PIC18 basic compiler USB support
PIC18 Simulator IDE can be used for development of USB generic HID devices. With optional USB support add-on for its integrated basic compiler, you will get an easy and elegant way for high-speed USB firmware development that will enable your hardware projects to communicate with PC host using USB bus.
USB support add-on consists of the USB command set for the PIC18 basic compiler and HidTerm ActiveX control (DLL library is also available) for the development of the PC application that will communicate with your device. Microsoft Visual Basic and PureBasic examples are also included. This solution can be used with the following models from Microchip PIC18F product line: 18F2455, 18F2550, 18F4455 and 18F4550.
Data exchange is implemented with USB Feature, Input and Output reports with 8 bytes of data. With HidTerm control PC application will be able to send Feature report, to request Feature report, to send Output report and to request Input report from your hardware. Basic compiler set of USB language elements will enable the hardware to easily respond to these four events.
Please take a look at the following easy example of USB firmware developed with PIC18 Simulator IDE integrated basic compiler. It actually uses all available USB basic language elements. Output report data sent from the PC will be automatically stored in the system UsbIoBuffer(0-7) array and the firmware will return increased values when it is requested to send Input report to the PC. Data received with Feature report sent from the PC application will be stored in the UsbFtBuffer(0-7) array and will be returned decreased when Feature report is requested back.
UsbService statement should be executed as often as possible, because several calls to UsbService routine are necessary to process each of the USB events. I have however tested the same example with WaitMs 500 statement after the UsbService and there were no problems experienced. The device was only slow with its responses to the PC.
The hardware necessary to connect PIC18F chip to USB bus is really minimal. Here is the schematics and the photo of the prototype I used for my tests. You can use a 20MHz 3-pin ceramic resonator to further reduce the number of components.
You can download here the stand-alone application for PC that can be used for getting information about the connected generic HID devices and also for reports exchange. The archive also contain the Microsoft Visual Basic source file with all the code that would be necessary for the development of such an application with the help of HidTerm ActiveX control.