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