Microchip Technology DV164139 Datenbogen
![Microchip Technology](https://files.manualsbrain.com/attachments/cf42c3c895ef469f06d2e47e97fd98d738fcf5cf/common/fit/150/50/7340124dc8aa983aaf764094e2f06faab86f306c03111c5817f7e4e53fb2/brand_logo.gif)
Low Pin Count USB Development Kit User’s Guide
DS41356B-page 26
© 2009 Microchip Technology Inc.
EXAMPLE 2-9:
KEYBOARD() STATE MACHINE CODE
//delay to allow the hold capacitor on the ADC to charge
case 0:
if(++delaycounter>9000)
{
delaycounter = 0;
state = 1;
}
break;
case 1:
ADCON0bits.GO_DONE = 1; //Start an ADC conversion
state = 2;
break;
case 2:
if(ADCON0bits.GO_DONE == 0) //Check if conversion is
//completed
{
state = 3;
}
break;
case 3:
HIDoutput = ADRESH>>3;//shift the result in ADRESH
//left by three
if(HIDoutput<=4) HIDoutput = 4;
if(HIDoutput>=29) HIDoutput = 29;
//Can the SIE transmit?
if((HIDTxHandleBusy(lastTransmission) == 0))
{
//Load the HID buffer
hid_report_in[0] = 0;
hid_report_in[1] = 0;
hid_report_in[2] = HIDoutput;
hid_report_in[3] = 0;
hid_report_in[4] = 0;
hid_report_in[5] = 0;
hid_report_in[6] = 0;
hid_report_in[7] = 0;
//Send the 8 byte packet over USB to the host.
lastTransmission = HIDTxPacket(HID_EP,
(BYTE*)hid_report_in, 0x08);
state = 0;
}
break;