Please note that, for programming, we will be using the 5V supply from the programmer. I’ve added some labels to the picture to make it clear which components go where. The following picture shows the circuit constructed on a hobbyist breadboard. You can use other crystal speeds, however I recommend you use 20 Mhz to begin with since otherwise you will need to alter the firmware. In these examples (and the associated firmware) a 20Mhz crystal is used (this allows the PIC to use PLL which ups the clock speed to the required 48Mhz necessary for USB communication). An external oscillator (crystal) is required for the PIC to be able to use the on-board USB module. The ICSP header allows you to connect a PIC programmer, I suggest using the inexpensive PICkit3 programmer, however other ICSP compatible programmers should work just fine. The 470nF capacitor (C3) is required so the PIC can operate the internal USB circuitry (it helps with regulating the USB voltages required by the on-board USB interface in the PIC) – Note that C3 can be any value between 220nF and 470nF (the datasheet recommends 220nF however I had 470nF available, it doesn’t make any odds to the functioning of the circuit. The PIC18F4550 will be ‘bus powered’ this means that the device will draw its power from the USB host (your PC) so no power regulation is required. The circuit is very straight forward (if you are not familiar with this level of microcontroller electronics I suggest you go ahead and build some of the many flashing LED and push button tutorials available on the web before attempting this).
In addition there is a single LED and a single push switch to represent the input and output devices.
The device includes an ICSP header (In Circuit Serial Programming) and a USB type B connection.
In the following circuit diagram you can see the minimum configuration for a usable USB device. To begin with we need to build a USB device to communicate with. Please note that all of the host screenshots are taken from a Windows 7 machine, if you need to find the same/similar thing on an older Windows box please head over to Google where you will find plenty of information about where the items are on your WindowsME machine. Also make sure you have MPLAB, Microchip C18 for the PIC18F and Microsoft Visual Studio 2010 express installed. If you want to follow along with this article I suggest you scroll down to the bottom and download the accompanying software.
To keep the cost and difficulty as low as possible I will concentrate on breadboard construction of the hardware using few components, the PIC18F firmware will be based on (the freely available) MPLAB and Microchip C18 compiler, the Windows software will be created using Microsoft Visual C# 2010 express (which is also free to download).Īlthough this article is based around the PIC18F4550 microcontroller you can easily substitute this for the smaller and cheaper PIC18F2550 which is code compatible with the larger 4550. Using this the basic principals of 2-way USB communication will be made clear allowing you to progress onto more complex projects. The device will allow you to control a LED from Windows and also see the status of a push-switch on the device.
As always I welcome your feedback and suggestions in the comments.įor this article we’re going to stick to a fairly basic USB device. This should provide a smoother path from this basic tutorial to more complex projects. Update: I have updated this article to use the Microchip C18 compiler and to be based around my latest USB framework libraries for both the PIC and Windows ().
Since the HID standard does not require custom drivers you will not need to get a certificate for your driver, also both Windows and Linux have built-in libraries to help you communicate. Using the built in drivers for generic HID devices provides a simple method of creating Windows and Linux compatible devices and also makes the creation of both firmware and software far simpler.
Since the advent of Windows 7 you need an expensive Microsoft validation certification to create custom USB drivers (without it most users cannot even install your software).
In this article I will show how to breadboard a simple USB generic HID device, creating the PIC18F firmware and finally creating the Windows interface for the device which will allow you to control a LED from the PC and read the state of a push-button from the device. After looking at projects such as my Atari Joystick USB Adaptor and C64 VICE Front-End there seems to be a demand for more information on how to ‘hack your own’. I get a number of emails every month asking about creating USB devices using the PIC18F microcontroller.