Simple PIC USB Interface

Program Download:

Archived Project File:
HID_Example.zip

The Software
           There are two main softwares for this project:
    -Windows Software
    -Embedded PIC Firmware


           The windows software acts as the interface on your laptop/desktop that lets you interact with the PIC. Similarly, the firmware on the PIC is what enables the back and forth communicatio with the laptop for giving input and showing output.
           Simply put, these are sophisticated programs that I cannot explain in a single, or even multiple web pages, so I will highlight a few of the important areas in the firmware. Please look through and compile the code yourself to see how things are really happening.

USB HID Device Descriptor

------------« Begin Code »------------
/* Device Descriptor */
ROM USB_DEVICE_DESCRIPTOR device_dsc=
{
  0x12, // Size of this descriptor in bytes
  USB_DESCRIPTOR_DEVICE, // DEVICE descriptor type
  0x0200, // USB Spec Release Number in BCD format
  0x00, // Class Code
  0x00, // Subclass code
  0x00, // Protocol code
  USB_EP0_BUFF_SIZE, // Max packet size for EP0
  MY_VID, // Vendor ID
  MY_PID, // Product ID: Mouse in a circle fw demo
  0x0002, // Device release number in BCD format
  0x01, // Manufacturer string index
  0x02, // Product string index
  0x00, // Device serial number string index
  0x01 // Number of possible configurations
};
------------« End Code »------------

           This is the device descriptor, similar to the way the PCI BUS on a motherboard tells windows what it is, USB tells windows the version of USB (2.0), and specifically the manufacturer (MY_VID) and product (MY_PID). These values show up in the device manager in windows when the USB is plugged in. Choose unique values for these variables as you must define your own ID, otherwise windows might think your device is something it is not and assign drivers to it.

USB HID Device Descriptor

------------« Begin Code »------------
/* Configuration 1 Descriptor */
ROM BYTE configDescriptor1[]={
..
..
USB_DESCRIPTOR_CONFIGURATION,
0x29,0x00, // Total length of data for this cfg
1, // Number of interfaces in this cfg
1, // Index value of this configuration
0, // Configuration string index
..
..
/* Endpoint Descriptor */
0x07,/*sizeof(USB_EP_DSC)*/
USB_DESCRIPTOR_ENDPOINT, //Endpoint Descriptor
HID_EP | _EP_IN, //EndpointAddress
_INTERRUPT, //Attributes
0x40,0x00, //size
0x01, //Interval
};
------------« End Code »------------

           The configDescriptor ROM BYTE holds the configuration of the actual USB device. The endpoint descriptor shows you how much information will be passed over this usb line, how fast and by what method. These can all be changed to the different values or methods depending on your need for the USB device. There's a lot more to this register, but this is a quick introduction I wanted to give.



;