void main(void)
{
int temp1,temp2;
BYTE readout;
LED_1_Start();
LED_2_Start();
LED_3_Start();
LED_1_Switch(0); // Turn on LED_1
LED_2_Switch(0); // Turn on LED_2
LED_3_Switch(0); // Turn on LED_3
M8C_EnableGInt; //Enable Global Interrupts
USBFS_Start(0, USB_5V_OPERATION); //Start USBFS Operation using device 0 and with 5V operation
while(!USBFS_bGetConfiguration()); //Wait for Device to enumerate
//Enumeration is completed load endpoint 1. Do not toggle the first time
USBFS_LoadInEP(1, keycode, 8, USB_NO_TOGGLE);
USBFS_EnableOutEP(2);
while(1)
{
temp1=KEY_input();
if(temp1==0x41)
{
keycode[0]|=0x02;
}
else
{
keycode[0]&=(~0x02);
}
if(temp1==0x43)
{
keycode[0]|=0x02;
temp1=0x11;
}
if(USBFS_bGetEPAckState(1))
{
//ACK has occurred, load the endpoint and toggle the data bit
USBFS_LoadInEP(1, keycode, 8, USB_TOGGLE);
//converting read from Keyboard scan code to PC format
keycode[2]=MakeConversionTable(temp1);
}
}
if(USBFS_bGetEPAckState(2))
{
USBFS_bReadOutEP(2, Buf, 1);
if(Buf[0]&0x02)
{
LED_1_Switch(1);
}
else
{
LED_1_Switch(0);
}
USBFS_EnableOutEP(2);
}
Delay(1000);
}
} |