circuitcellar.com
Magazine Support   Digital Library   Products & Services   Suppliers Directory 
 
 





 

March 2006, Issue 188

Remedy for USB-to-MCU Pain|
Embedded USB with HIDmaker FS


by Fred Eady


Start USB Medicine Show Good USB Medicine Popping USB Pills Relief How Do You Feel? Sources and PDF

RELIEF

All I really wanted to accomplish was the simple movement of data between the host and the USB peripheral (the USB Widget). So, I added just two more lines of BASIC code to complete the mission.

Take a look at that LAB-XUSB schematic I referred to earlier. The lower nibble of the PIC18F4550’s port D drives four LEDs. The upper nibble of port D is used as the data lines for the 2 × 20 LCD. I needed to make the port D pins driving the LEDs output I/O pins. Ignore the LCD data lines for now. A simple TRISD = 0 was all I had to code to make it happen. 

I knew that the Visual Basic 6 test program would send 0x55 (85 decimal) when I clicked the Send All Reports button in the test GUI. I also knew that my widget_outputdata variable would ultimately hold the test value received from the host. (All data direction is referenced to the host. Out is from the host. In is to the host.) So, all I had to code was PORTD = widget_outputdata to write the received value of 0x55 to the bank of LAB-XUSB LEDs.

As you can see in Listing 3, I added the two lines of code and then recompiled and reprogrammed the PIC18F4550. I left the Visual Basic 6 test program running during the PIC18F4550 reprogramming operation. It disconnected and reconnected the USB link to the newly programmed USB Widget automatically (just as a good USB device should). After I punched the Send All Reports button, the LEDs representing bits 0 and 2 (LED 1 and LED 3, respectively) illuminated to indicate the lower nibble value of 5. The cycle of USB pain was broken!