Licenses Contact


20th Anniversary

20th Anniversary of the
(2001 - 2021)

PIC18 basic compiler USB support

PIC18 Simulator IDE can be used for development of USB generic HID devices. Optional USB support add-on for its integrated basic compiler provides an easy and elegant way for development of the high-speed firmware for USB generic HID devices, 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 PIC 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 currently with the following MCUs from the Microchip 8-bit PIC18 architecture 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.

Here is a simple and easy example of the USB firmware written for PIC18 Simulator IDE integrated basic compiler with USB support add-on enabled, that uses all the available USB basic language elements.

PIC18 basic compiler USB support example basic program:

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.

PIC chip integrated USB module is enabled with UsbStart statement. After its execution the hardware will be recognized by Windows as a generic HID device. No driver is necessary. Hardware can be disconnected from the PC with UsbStop statement. UsbService statement should be executed as often as possible, because several calls to UsbService routine are necessary to process each of the USB events. The firmware will work correctly even if you execute UsbService only once per second. The device will only be slow with its responses to the PC. So, there is still a lot of time for other activities in the firmware.

Minimal number of external components is necessary to connect the PIC chip to the USB bus:


You can download here the stand-alone application for the PC that can be used for getting information about the connected generic HID devices, and also for reports exchange. The archive also contains 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 the HidTerm ActiveX control, that is a part of the PIC18 basic compiler USB support add-on solution.

PIC18 basic compiler USB support example schematics: