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