Saturday 13 April 2013

MikroC Project - USB HID


What is USB HID?

HID is a USB device class that describes human interface devices such as keyboards, mice, game controllers and alphanumeric display devices. The USB HID class describes devices used with nearly every modern computer. Great set of existing predefined functions allow hardware manufacturers to design a product to USB HID class specifications and expect it to work with any software that also meets these specifications. In other words, no drivers are needed for USB device to work on any computer and on any operating system.


    




Let us show you how easily mikroC PRO for PIC handles with rather complex programs using the power of integrated libraries.
The following PIC C compiler code sample is a simple loop that demonstrates the operation of USB HID library. It constantly checks for HID packets, and as soon as the HID message arrives, it is transmitted back with the same content.
Examine these lines to see how the HID library deals with a highly complicated task of HID USB communication. mikroC PRO for PIC spares you the research of how USB communication works, and encapsulates everything in a simple and easy-to-understand functions.
HID Library Example


unsigned char readbuff[64] absolute 0x500;  // Buffers should be in USB RAM
unsigned char writebuff[64] absolute 0x540;
char cnt;
char kk;

void main(void){
  ADCON1 |= 0x0F;                         // Configure all ports with analog function as digital
  CMCON  |= 7;                            // Disable comparators

  HID_Enable(&readbuff,&writebuff);       // Enable HID communication

  while(1){                               // USB servicing is done inside the while loop
         USB_Polling_Proc();               // Call this routine periodically
         kk = HID_Read();
         if(kk != 0){
           for(cnt=0;cnt<64;cnt++)
                 writebuff[cnt]=readbuff[cnt];
           HID_Write(&writebuff,64);
         }
  }
}



courtesy : Mikroe.com

No comments:

Post a Comment