The PicBasic Pro Compiler now supports the Microchip PIC16C745 and 765 low-
speed USB devices.

The USB subdirectory contains the Microchip USB libraries, modified for the
PicBasic Pro Compiler, as well as example programs and some documentation
files.  USB programs require several addtional files to operate (which are in
the USB subdirectory), some of which may require modification for your
particular application.  The files in this subdirectory are:

        HIDCLASS.ASM    Modified Microchip HID class assembler file
        JADESC.ASM      Descriptor file for Jan Axelson demo
        MOUSDESC.ASM    Descriptor file for mouse demo
        README.1ST      Microchip read me file
        USB.TXT         This file
        USB_CH9.ASM     Modified Microchip USB chapter 9 assembler file
        USB_DEFS.INC    Modified Microchip USB definitions file
        USBDESCR.ASM    Include file for descriptor file
        USBJADEM.BAS    Jan Axelson demo BASIC program file
        USBMOUSE.BAS    Mouse demo BASIC program file
        USB-UGV1.DOC    Microchip USB Word doc file


HIDCLASS.ASM, USB_DEFS.INC and USB_CH9.ASM are files provided by Microchip
to access the USB hardware on the PICmicro MCU.  These files have been
modified so that they may be used with the compiler.  The modifications
included removing any linker-specific ops as the compiler does not support a
linker.  Includes to header files and ENDs have also been removed.  #IFDEFs
and #ENDIFs have had the # sign removed.  Labels that were the same except
for the case have been changed to make them unique.  Any decimal constants
that used . were changed to hex.  Finally, the label DEVICE was commented out
as this is a keyword in the assembler PM and is not being used in any case.

README.1ST and USB-UGV1.DOC are the Microchip USB documentation files.  Keep
in mind that we have slightly modified the Microchip USB code as described
above.  However, these documentation files are still extremely valuable.

USB communications is much more complicated than synchronous (Shiftin and
Shiftout) and asynchronous (Serin, Serout and so forth) communications.
There is much more to know about USB operation that can possibly be described
here.  The USB information on the Microchip web site needs to be studied.
Also, the book "USB Complete" by Jan Axelson may be helpful.



BASIC USB Programs

A USB program consists of the BASIC source code along with the proper USB
files, including HIDCLASS.ASM, USB_CH9.ASM, USB_DEFS.INC and a USB descriptor
file.  The BASIC source program must include an assembler interrupt handler
as most USB operations are handled in the background by interrupts.  There
are interrupt handlers in the sample BASIC programs included that can be used
as is in your project.

When the compiler sees that you are using a PIC16C745 or 765, it will
automatically include the required Microchip files into the project.  It will
also include the file USBDESCR.ASM.  This is a user modified file that
contains an include to the descriptor used for the current project.  Only one
descriptor file must be selected in this file.

The files HIDCLASS.ASM, USB_CH9.ASM, USB_DEFS.INC and USBDESCR.ASM, as well
as any desired sample programs, should be copied to the PBP subdirectory
before being used.



Sample Programs

USBMOUSE.BAS is the Microchip mouse demo written in BASIC instead of
assembler.  It makes the mouse move in a small circle when connected to a PC.
MOUSDESC.ASM contains the descriptors required by the demo program to
operate.  This file is compiled into the program automatically by PBP.  The
descriptor files are named in the file USBDESC.ASM.  This file can be edited
to name another descriptor file.


USBJADEM.BAS is the Jan Axelson demo program written in BASIC instead of
assembler.  It communicates with a program running on the PC, USBHIDIO, that
can be found on Jan Axelson's web site at www.lvr.com.  This demo takes 2
numbers from the PC program, increments them and sends them back.  It shows
how to send data to and from the PC.  JADESC.ASM contains the descriptors
required by the demo program to operate.  This file is compiled into the
program automatically by PBP.  The descriptor files are named in the file
USBDESC.ASM.  This file must be edited to name this descriptor file.



New USB Commands

Three new PBP commands have been added, as well as the modifications made to
the Microchip USB libraries, to support the PIC16C745 and 765 low-speed USB
devices.  The new commands are shown below:

	USBInit

USBInit needs to be one of the first statements in the program.  It will
initialize the USB portion of the PICmicro MCU and wait until the USB bus is
configured and enabled.

	USBIn enpoint, buffer, countvar, label

USBIn gets any available USB data for the endpoint and places it in the
buffer.  Buffer must be a byte array of suitable length to contain the data.
Countvar will contain the number of bytes transferred to the buffer.  Label
will be jumped to if no data is available.

	USBOut endpoint, buffer, count, label

USBOut takes count number of bytes from the buffer and sends them to the USB
endpoint.  If the USB buffer does not have room for the data because of a
pending transmission, no data will be transferred and program execution will
continue at label.

See the included USB sample programs for examples of each of these commands.
