📄 usbkeyboard.lst
字号:
C51 COMPILER V8.02 USBKEYBOARD 12/12/2007 21:37:17 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE USBKEYBOARD
OBJECT MODULE PLACED IN UsbKeyBoard.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE UsbKeyBoard.c BROWSE DEBUG OBJECTEXTEND
line level source
1 /******************************************************************
2 本程序只供学习使用,未经作者许可,不得用于其它任何用途
3
4 欢迎访问我的USB专区:http://group.ednchina.com/93/
5 欢迎访问我的blog: http://www.ednchina.com/blog/computer00
6 http://computer00.21ic.org
7
8 感谢wang1jin为本PCB的检查以及元件的采购,欢迎大家访问wang1jin的博客:
9 http://www.ednchina.com/blog/wang1jin/
10
11 USBKeyBoard.C file
12
13 作者:Computer-lov
14 建立日期: 2007.03.20
15 修改日期: 2007.03.23
16 版本:V1.1
17 版权所有,盗版必究。
18 Copyright(C) Computer-lov 2007-2017
19 All rights reserved
20 *******************************************************************/
21
22 #include "AT89x52.H"
23 #include "USB.H"
24 #include "PDIUSBD12.H"
25 #include "My_type.h"
26 #include "UART.H"
27 #include "key.h"
28 #include "keyboard.h"
29 #include "led.h"
30
31 #define DispLineInf() \
32 { \
33 Prints(" in file \""); \
34 Prints(__FILE__); \
35 Prints(", @ line "); \
36 PrintLongInt(__LINE__-1); \
37 Prints("\r\n"); \
38 }
39
40 //#define debug
41
42 #define USB_COMMAND_ADD 1
43 #define USB_DATA_ADD 0
44
45 //USB芯片连接引脚
46 #define USB_DATA P0
47 #define USB_A0 P3_5
48 #define USB_WR P3_6
49 #define USB_RD P3_7
50 #define USB_INT P3_2
51
52
53 #define ENDPOINT_NUMBER 2
54 #define MAX_CONTROL_DATA_SIZE 16
55
C51 COMPILER V8.02 USBKEYBOARD 12/12/2007 21:37:17 PAGE 2
56
57 //控制传输时保存数据
58 CONTROL_DATA_BUFF Control_Data;
59
60 //缓冲
61 uint8 idata buffer[64];
62
63 //交换数据时用的指针
64 uint8 *pData;
65
66 uint8 idle; //空闲状态
67 uint8 protocol; //当前协议
68
69 //高低字节交换
70
71 #define SWAP16(x) ((((uint16)(x))<<8)|(((uint16)(x))>>8))
72
73 //取一个整数的低字节
74 #define LSB(x) ((uint8)(x))
75
76 //取一个整数的高字节
77 #define MSB(x) ((uint8)(((uint16)(x))>>8))
78
79 //字符串描述符所用的语言种类
80 code uint8 LANGUAGE_ID[4]={0x04,0x03,0x09,0x04};
81
82 //设备序列号
83 code uint8 device_serial_number[]=
84 {22,STRING_DESCRIPTOR,'2',0,'0',0,'0',0,'7',0,'-',0,'1',0,'1',0,'-',0,'2',0,'9',0};
85
86 //厂商字符串 电脑圈圈的USB专区 http://group.ednchina.com/93
87 //汉字Unicode编码,使用http://computer00.21ic.org/user1/2198/archives/2007/42769.html转换
88 code uint8 ManufacturerString[80]=
89 {80,STRING_DESCRIPTOR,0x35,0x75,0x11,0x81,0x08,0x57,0x08,0x57,0x84,0x76,'U',0x00,
90 'S',0x00,'B',0x00,0x13,0x4E,0x3A,0x53,0x20,0x00,'H',0,'t',0,'t',0,
91 'p',0,':',0,'/',0,'/',0,'g',0,'r',0,'o',0,'u',0,'p',0,'.',0,'e',0,'d',0,'n',0,
92 'c',0,'h',0,'i',0,'n',0,'a',0,'.',0,'c',0,'o',0,'m',0,'/',0,'9',0,'3',0};
93
94 //产品字符串 电脑圈圈的USB专区活动之USB键盘 http://group.ednchina.com/93
95 //汉字Unicode编码,使用http://computer00.21ic.org/user1/2198/archives/2007/42769.html转换
96 code uint8 ProducterString[96]=
97 {96,STRING_DESCRIPTOR,0x35,0x75,0x11,0x81,0x08,0x57,0x08,0x57,0x84,0x76,'U',0x00,
98 'S',0x00,'B',0x00,0x13,0x4E,0x3A,0x53,0x3B,0x6D,0xA8,0x52,0x4B,0x4E,'U',0x00,
99 'S',0x00,'B',0x00,0x2E,0x95,0xD8,0x76,0x20,0x00,'H',0,'t',0,'t',0,
100 'p',0,':',0,'/',0,'/',0,'g',0,'r',0,'o',0,'u',0,'p',0,'.',0,'e',0,'d',0,'n',0,
101 'c',0,'h',0,'i',0,'n',0,'a',0,'.',0,'c',0,'o',0,'m',0,'/',0,'9',0,'3',0};
102
103 code DEVICE_DESCRIPTOR_STRUCT device_descriptor= //设备描述符
104 {
105 sizeof(DEVICE_DESCRIPTOR_STRUCT), //设备描述符的字节数大小
106 DEVICE_DESCRIPTOR, //设备描述符类型编号
107 SWAP16(0x0110), //USB版本号,USB1.1
108 0x00, //USB分配的设备类代码
109 0x00, //USB分配的子类代码
110 0x00, //USB分配的设备协议代码
111 0x10, //端点0的最大包大小
112 SWAP16(0x8888), //厂商编号VID,这里只是作为测试用,请使用自己的VID
113 SWAP16(0x0001), //产品编号PID,这里只是作为测试用,请使用自己的PID
114 SWAP16(0x0001), //设备出厂编号
115 0x01, //设备厂商字符串的索引
116 0x02, //描述产品字符串的索引
117 0x03, //描述设备序列号字符串的索引
C51 COMPILER V8.02 USBKEYBOARD 12/12/2007 21:37:17 PAGE 3
118 0x01 //可能的配置数量
119 };
120
121 //定义配置,接口,端点等描述符结构体,因为它们是随配置描述符一起返回的
122 typedef struct _CON_INT_ENDP_DESCRIPTOR_STRUCT
123 {
124 CONFIGURATION_DESCRIPTOR_STRUCT configuration_descriptor;
125 INTERFACE_DESCRIPTOR_STRUCT interface_descriptor;
126 HID_DESCRIPTOR_STRUCT hid_descriptor;
127 ENDPOINT_DESCRIPTOR_STRUCT endpoint_descriptor[ENDPOINT_NUMBER];
128 }CON_INT_ENDP_DESCRIPTOR_STRUCT;
129
130 code CON_INT_ENDP_DESCRIPTOR_STRUCT con_int_endp_descriptor=
131 {
132 //configuration_descriptor //配置描述符
133 {
134 sizeof(CONFIGURATION_DESCRIPTOR_STRUCT), //配置描述符的字节数大小
135 CONFIGURATION_DESCRIPTOR, //配置描述符类型编号
136 SWAP16(sizeof(CON_INT_ENDP_DESCRIPTOR_STRUCT)),
137 0x01, //只包含一个接口
138 0x01, //该配置的编号
139 0x00, //iConfiguration字段
140 0xA0, //采用总线供电,支持远程唤醒
141 0xC8 //从总线获取最大电流400mA
142 },
143 //interface_descritor //接口描述符
144 {
145 sizeof(INTERFACE_DESCRIPTOR_STRUCT), //接口描述符的字节数大小
146 INTERFACE_DESCRIPTOR, //接口描述符类型编号
147 0x00, //接口编号为0
148 0x00, //该接口描述符的编号
149 ENDPOINT_NUMBER, //非0端点数量为2,只使用端点主端点输入和
-输出
150 0x03, //人机接口设备(HID)类
151 0x01, //使用的子类:支持BIOS根启动Boot的子类
152 0x01, //使用的协议:键盘
153 0x00 //接口描述符字符串索引
154 },
155 //hid_descriptor
156 {
157 sizeof(HID_DESCRIPTOR_STRUCT), //HID描述符的字节数大小
158 HID_DESCRIPTOR, //HID描述符类型编号
159 SWAP16(0x0110), //HID类协议版本号,为1.1
160 0x21, //固件的国家地区代号,0x21为美国
161 NUM_SUB_DESCRIPTORS, //下级描述符的数量
162 {
163 {
164 REPORT_DESCRIPTOR, //下级描述符为报告描述符
165 SWAP16(sizeof(KeyBoardReportDescriptor)) //下级描述符的长度
166 }
167 },
168 },
169 //endpoint_descriptor[]
170 {
171 { //主端点输入描述
172 sizeof(ENDPOINT_DESCRIPTOR_STRUCT), //端点描述符的字节数大小
173 ENDPOINT_DESCRIPTOR, //端点描述符类型编号
174 MAIN_POINT_IN, //端点号,主输入端点
175 ENDPOINT_TYPE_INTERRUPT, //使用的传输类型:中断传输
176 SWAP16(0x0040), //该端点支持的最大包尺寸,64字节
177 0x0A //中断扫描时间:设置为10ms
178 },
C51 COMPILER V8.02 USBKEYBOARD 12/12/2007 21:37:17 PAGE 4
179
180 { //主端点输出描述
181 sizeof(ENDPOINT_DESCRIPTOR_STRUCT), //端点描述符的字节数大小
182 ENDPOINT_DESCRIPTOR, //端点描述符类型编号
183 MAIN_POINT_OUT, //端点号,主输出端点
184 ENDPOINT_TYPE_INTERRUPT, //使用的传输类型:中断传输
185 SWAP16(0x0040), //该端点支持的最大包尺寸,64字节
186 0x0A //中断扫描时间:设置为10ms
187 }
188 }
189 };
190
191 union //程序标志位
192 {
193 uint16 Register;
194 struct
195 {
196 uint8 bus_reset :1;
197 uint8 suspend :1;
198 uint8 remote_wakeup :1;
199 uint8 int_isr :1;
200 uint8 not_end :1;
201 uint8 usb_idle :1;
202 uint8 usb_busy :1;
203 uint8 setup_packet_in :1;
204 uint8 setup_packet_out :1;
205 uint8 set_addr :1;
206 uint8 usb_endp0_in :1;
207 uint8 usb_endp2_in :1;
208 uint8 usb_endp2_out :1;
209 }flags;
210 }usb_flags;
211
212 union //中断寄存器
213 {
214 uint8 Register[2];
215 struct
216 {
217 uint8 control_out_port :1;
218 uint8 control_in_port :1;
219 uint8 port_out_1 :1;
220 uint8 port_in_1 :1;
221 uint8 main_out_port :1;
222 uint8 main_in_port :1;
223 uint8 bus_reset :1;
224 uint8 suspend_change :1;
225 uint8 DMA_EOT :1;
226 uint8 not_use :7;
227 }Interrupt;
228 }Interrupt_Register;
229
230
231 union //端点最后处理状态
232 {
233 uint8 Register;
234 struct
235 {
236 uint8 successful :1;
237 uint8 error_code :4;
238 uint8 setup_packet :1;
239 uint8 data_1 :1;
240 uint8 prestatus_not_read :1;
C51 COMPILER V8.02 USBKEYBOARD 12/12/2007 21:37:17 PAGE 5
241 }Status;
242 }Last_Status;
243
244
245 /***************** 延时x毫秒函数 ***********/
246 void delay(uint16 x)
247 {
248 1 uint16 i;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -