📄 usb_hid_led.c
字号:
// ============================================================// ETOMS USB Demo // Designer: Brooklin// 2004/09/22// MCU: ET44M210// MCU setting value//============================================================#include <interrupt.h>#include "usb_hid_led.h" void main() { PRIE = 0; INTF = 0; INTE = 0; // set porta as output IOCA=0x00; // call for Led Initial LedInitial(); UsbInitial(); M_ENI; // wait for USB configure Ok do { M_NOP; M_NOP; } while(M_ISBC(RegState,ConfigOk)); // start Led LedStart();}void LedInitial(){ byLedData = 0; byData1 = 0; byData2 = 0; PORTA = 0; PORTB = 0; PORTC = 0; PUCB = 0; // disable ep1 RX/TX M_BC(EP1CSR,RXTXEN); }void LedStart() using 1{ // put the button data to the ep1 fifo. AddUsbEp1Sub(); while(1) { M_NOP; byData1 =0; byData2 = 0; ScanButton(); // enable ep1 RX/TX M_BS(EP1CSR,RXTXEN); DelayMs(4); // enable ep2 RX/TX M_BS(EP2CSR,RXTXEN); M_NOP; // if ep2 interrupt occur set the led status. if(M_ISBS(RegState,LedGet)) { M_BC(RegState,LedGet); PORTLED = byLedData; } DelayMs(5); }}/////////////////////////////////////////////// There are 16 (4*4)buttons on the damo board// Set the Col(portc) be input and pull high the port// scan the bit Column1~Column4 if the bit is clear,// one button is set, scan the row if the row is still// clear we get the col and row, // only one button can be seted for each column.// byData1 and byData2 are the registers for saving the button data,// byData1 // Bit0 | Bit1 | Bit2 | Bit3 | Bit4 | Bit5 | Bit6 | Bit7 // S1 | S2 | S3 | S4 | S5 | S6 | S7 | S8// byData2 // Bit0 | Bit1 | Bit2 | Bit3 | Bit4 | Bit5 | Bit6 | Bit7 // S9 | S10 | S11 | S12 | S13 | S14 | S15 | S16//// S16 S15 S14 S13 Column4// S12 S11 S10 S9 Column3// S8 S7 S6 S5 Column2// S4 S3 S2 S1 Column1// R4 R3 R2 R1// /////////////////////////////////////////////////void ScanButton() { IOCC = 0x0F; PUCC = 0x0F; // col IOCB = 0; BtnRow =0; for(byi=0;byi<4;byi++) { IOCB = 0; BtnRow =0; if(M_ISBC(BtnCol,byi)) { for(byj=0;byj<4;byj++) { BtnRow = 15-(0x01<<byj); if(M_ISBC(BtnCol,byi)) { byOffset = byi*4 + byj; byOffset &= 0x0f; if(byOffset < 8) { M_BS(byData1,byOffset); } else { byOffset -= 8; M_BS(byData2,byOffset); } } } } }}void DelayMs(unsigned char nMs){ while(nMs) { DelayNs(250); DelayNs(250); DelayNs(250); DelayNs(250); nMs--; }}void DelayNs(unsigned char nNs){ while(nNs) { NOP1; nNs--; }}// replace macro _ADD_USB_SET_REPORT_SUBvoid AddUsbSetReportSub() using USBBANK{}void AddUsbInitialWorkSub() using USBBANK{}void AddUsbRt0x01Request() using USBBANK{}void AddUsbRt0x02Request() using USBBANK{}//. call macro _ADD_USB_RT0X00_Requestvoid AddUsbRt0x00Request() using USBBANK{}// macro _ADD_USB_RT0X80_Requestvoid AddUsbRt0x80Request() using USBBANK{}// macro _ADD_USB_RT0X82_Requestvoid AddUsbRt0x82Request() using USBBANK{}// macro _ADD_USB_RT0X20_Requestvoid AddUsbRt0x20Request() using USBBANK{}// macro _ADD_USB_RT0X21_Requestvoid AddUsbRt0x21Request() using USBBANK{}// macro _ADD_USB_RT0X23_Requestvoid AddUsbRt0x23Request() using USBBANK{}// macro _ADD_USB_RT0XA0_Requestvoid AddUsbRt0xA0Request() using USBBANK{}// macro _ADD_USB_RT0XA1_Requestvoid AddUsbRt0xA1Request() using USBBANK{}// macro _ADD_USB_RT0XA3_Requestvoid AddUsbRt0xA3Request() using USBBANK{}// macro _ADD_USB_GET_REPORT_SUBvoid AddUsbGetReportSub() using USBBANK{}// macro _ADD_USB_bmRequestTypevoid AddUsbBmRequestType() using USBBANK{}//. macro _ADD_USB_GET_REPORT_EXP_SUBvoid AddUsbGetReportExpSub() using USBBANK{}//. macro _ADD_USB_EP1_SUB// 2 bytes sent// byte1: button data hi byte// byte2: button data low bytevoid AddUsbEp1Sub() using USBBANK{ if(M_ISBS(EP1CSR,RXTXEN)|| M_ISBS(EP1CSR,SESTALL)) return; // set endpoint count to 2 EP1CTR=2; // put the first byte to endpoint1 fifo, EP1DAR EP1DAR = byData1; M_NOP; // put the second byte to endpoint1 fifo, EP1DAR EP1DAR = byData2; M_NOP; M_BC(EP1CSR,SESTALL); M_NOP; M_BS(EP1CSR,RXTXEN); M_NOP;}//. macro _ADD_USB_EP2_SUBvoid AddUsbEp2Sub() using USBBANK{ if(M_ISBS(EP2CSR,RXTXEN)|| M_ISBS(EP2CSR,SESTALL)) return; // get the data size byCount = EP2CTR; // get endpoint2 data to byLedData byLedData = EP2DAR; // set flag for change led status. M_BS(RegState,LedGet); M_BC(EP2CSR,SESTALL); M_NOP; M_BS(EP2CSR,RXTXEN); M_NOP; }//. macro _ADD_USB_EP3_SUBvoid AddUsbEp3Sub() using USBBANK{}//. macro _ADD_USB_BUS_RESET_SUBvoid AddUsbBusResetSub() using USBBANK{}//. macro _ADD_USB_IDLE_INT_SUBvoid AddUsbIdleIntSub() using USBBANK{}//. macro _ADD_USB_WAKEUP_INT_SUBvoid AddUsbWakeup() using USBBANK{}//. macro _ADD_USB_SOF_INT_SUBvoid AddUsbSof() using USBBANK{}//. macro _ADD_USB_DEVICE_CONFIG_OKvoid AddUsbDeviceConfigOk() using USBBANK{ // set flag for usb config OK M_BS(RegState,ConfigOk);}//;============================================================//;Copyright c 2004 by ETOMS Electronics Corp. All right reserved.//;No part of this computer program may be reproduced, stored in a retrieval system, or //;transmitted in any form or by any means, electronic, mechanical, photocopying, //;recording, scanning or otherwise, except as permitted under ETOMS authorization. //;セ筿福祘Αぇ帝
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -