[mw_shl_code=c,true]void Joystick_Send(u8 buf0)
{
u8 KeyBoard_Buffer[8] = {0, 0, 0, 0, 0, 0, 0, 0};
/* prepare buffer to send */
KeyBoard_Buffer[2]=buf0;
/*copy mouse position info in ENDP1 Tx Packet Memory Area*/
UserToPMABufferCopy(KeyBoard_Buffer, GetEPTxAddr(ENDP1), 8);
/* enable endpoint for transmission */
SetEPTxValid(ENDP1);
}[/mw_shl_code]
[mw_shl_code=c,true]int main(void)
{
u8 key;
delay_init(); //延时函数初始化
NVIC_Configuration(); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
uart_init(9600); //串口初始化为9600
LED_Init(); //LED端口初始化
KEY_Init(); //按键初始化
usb_port_set(0); //USB先断开
delay_ms(300);
usb_port_set(1); //USB再次连接
//USB配置
USB_Interrupts_Config();
Set_USBClock();
USB_Init();
while(1)
{
key=KEY_Scan(0);//支持连按
if(key)
{
if(key==KEY_UP){
Joystick_Send(0x1c);
LED0 = !LED0;
}
}
if(bDeviceState==CONFIGURED)LED1=0;//当USB配置成功了,LED1亮,否则,灭
else LED1=1;
}
}
[/mw_shl_code]
|