📄 usb2uart.lst
字号:
C51 COMPILER V7.06 USB2UART 12/11/2007 01:02:42 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE USB2UART
OBJECT MODULE PLACED IN USB2UART.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE USB2UART.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 USB2UART.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 "led.h"
28
29 #define DispLineInf() \
30 { \
31 Prints(" in file \""); \
32 Prints(__FILE__); \
33 Prints(", @ line "); \
34 PrintLongInt(__LINE__-1); \
35 Prints("\r\n"); \
36 }
37
38 //#define debug
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 #define DTR P2_0
51 #define RTS P2_1
52
53 #define TXD P3_1
54
55
C51 COMPILER V7.06 USB2UART 12/11/2007 01:02:42 PAGE 2
56 #define ENDPOINT_NUMBER 2
57 #define MAX_CONTROL_DATA_SIZE 16
58
59
60 //控制传输时保存数据
61 CONTROL_DATA_BUFF Control_Data;
62
63 //缓冲
64 uint8 idata OutBuffer[64],InBuffer[64];
65 //数据计数器
66 uint8 idata InCount;
67 //数据位置
68 uint8 idata pIn;
69 //溢出标志
70 uint8 idata Overflow;
71
72 //交换数据时用的指针
73 uint8 *pData;
74
75 uint8 idle; //空闲状态
76 uint8 protocol; //当前协议
77
78 //当前串口设置
79 LINE_CODING LineCoding;
80
81 //高低字节交换
82
83 #define SWAP16(x) ((((uint16)(x))<<8)|(((uint16)(x))>>8))
84
85 #define SWAP32(x) ((((uint32)SWAP16(x))<<16)|SWAP16((x)>>16))
86
87 //取一个整数的低字节
88 #define LSB(x) ((uint8)(x))
89
90 //取一个整数的高字节
91 #define MSB(x) ((uint8)(((uint16)(x))>>8))
92
93 //字符串描述符所用的语言种类
94 code uint8 LANGUAGE_ID[4]={0x04,0x03,0x09,0x04};
95
96 //设备序列号
97 code uint8 device_serial_number[]=
98 {22,STRING_DESCRIPTOR,'2',0,'0',0,'0',0,'7',0,'-',0,'1',0,'1',0,'-',0,'2',0,'9',0};
99
100 //厂商字符串 电脑圈圈的USB专区 http://group.ednchina.com/93
101 //汉字Unicode编码,使用http://computer00.21ic.org/user1/2198/archives/2007/42769.html转换
102 code uint8 ManufacturerString[80]=
103 {80,STRING_DESCRIPTOR,0x35,0x75,0x11,0x81,0x08,0x57,0x08,0x57,0x84,0x76,'U',0x00,
104 'S',0x00,'B',0x00,0x13,0x4E,0x3A,0x53,0x20,0x00,'H',0,'t',0,'t',0,
105 'p',0,':',0,'/',0,'/',0,'g',0,'r',0,'o',0,'u',0,'p',0,'.',0,'e',0,'d',0,'n',0,
106 'c',0,'h',0,'i',0,'n',0,'a',0,'.',0,'c',0,'o',0,'m',0,'/',0,'9',0,'3',0};
107
108 //产品字符串 电脑圈圈的USB专区活动之USB转串口 http://group.ednchina.com/93
109 //汉字Unicode编码,使用http://computer00.21ic.org/user1/2198/archives/2007/42769.html转换
110 code uint8 ProducterString[98]=
111 {98,STRING_DESCRIPTOR,0x35,0x75,0x11,0x81,0x08,0x57,0x08,0x57,0x84,0x76,'U',0x00,
112 'S',0x00,'B',0x00,0x13,0x4E,0x3A,0x53,0x3B,0x6D,0xA8,0x52,0x4B,0x4E,'U',0x00,
113 'S',0x00,'B',0x00,0x6C,0x8F,0x32,0x4E,0xE3,0x53,0x20,0x00,'H',0,'t',0,'t',0,
114 'p',0,':',0,'/',0,'/',0,'g',0,'r',0,'o',0,'u',0,'p',0,'.',0,'e',0,'d',0,'n',0,
115 'c',0,'h',0,'i',0,'n',0,'a',0,'.',0,'c',0,'o',0,'m',0,'/',0,'9',0,'3',0};
116
117 code DEVICE_DESCRIPTOR_STRUCT device_descriptor= //设备描述符
C51 COMPILER V7.06 USB2UART 12/11/2007 01:02:42 PAGE 3
118 {
119 sizeof(DEVICE_DESCRIPTOR_STRUCT), //设备描述符的字节数大小
120 DEVICE_DESCRIPTOR, //设备描述符类型编号
121 SWAP16(0x0110), //USB版本号,USB1.1
122 0x02, //USB分配的设备类代码,通信设备类(CDC)
123 0x00, //USB分配的子类代码
124 0x00, //USB分配的设备协议代码
125 0x10, //端点0的最大包大小
126 SWAP16(0x8888), //厂商编号VID,这里只是作为测试用,请使用自己的VID
127 SWAP16(0x0006), //产品编号PID,这里只是作为测试用,请使用自己的PID
128 SWAP16(0x0001), //设备出厂编号
129 0x01, //设备厂商字符串的索引
130 0x02, //描述产品字符串的索引
131 0x03, //描述设备序列号字符串的索引
132 0x01 //可能的配置数量
133 };
134
135 //定义配置,接口,端点等描述符结构体,因为它们是随配置描述符一起返回的
136 typedef struct _CON_INT_ENDP_DESCRIPTOR_STRUCT
137 {
138 CONFIGURATION_DESCRIPTOR_STRUCT configuration_descriptor;
139 INTERFACE_DESCRIPTOR_STRUCT interface0_descriptor;
140 HEADER_FUNCTIONAL_DESCRIPTOR header_functional_descriptor;
141 CALL_MANAGEMENT_FUNCTIONAL_DESCRIPTOR call_management_functional_descriptor;
142 ABSTRACT_CONTROL_MANAGEMENT_FUNCTIONAL_DESCRIPTOR abstract_ontrol_anagement_unctional_escriptor;
143 UNION_FUNCTIONAL_DESCRIPTOR union_functional_descriptor;
144 ENDPOINT_DESCRIPTOR_STRUCT endpoint1in_descriptor;
145 INTERFACE_DESCRIPTOR_STRUCT interface1_descriptor;
146 ENDPOINT_DESCRIPTOR_STRUCT endpoint2in_descriptor;
147 ENDPOINT_DESCRIPTOR_STRUCT endpoint2out_descriptor;
148 }CON_INT_ENDP_DESCRIPTOR_STRUCT;
149
150 code CON_INT_ENDP_DESCRIPTOR_STRUCT con_int_endp_descriptor=
151 {
152 //configuration_descriptor //配置描述符
153 {
154 sizeof(CONFIGURATION_DESCRIPTOR_STRUCT), //配置描述符的字节数大小
155 CONFIGURATION_DESCRIPTOR, //配置描述符类型编号
156 SWAP16(sizeof(CON_INT_ENDP_DESCRIPTOR_STRUCT)),
157 0x02, //只包含一个接口
158 0x01, //该配置的编号
159 0x00, //iConfiguration字段
160 0xA0, //采用总线供电,支持远程唤醒
161 0xC8 //从总线获取最大电流400mA
162 },
163 //CDC interface_descritor //CDC类接口描述符
164 {
165 sizeof(INTERFACE_DESCRIPTOR_STRUCT), //接口描述符的字节数大小
166 INTERFACE_DESCRIPTOR, //接口描述符类型编号
167 0x00, //接口编号为0
168 0x00, //该接口描述符的备用编号
169 0x01, //非0端点数量为1,端点1中断
170 0x02, //所使用的类,Communication Interface Cl
-ass
171 0x02, //使用的子类,Abstract Control Model
172 0x01, //使用的协议,Common AT commands
173 0x00 //接口描述符字符串索引
174 },
175
176 //header_functional_descriptor
177 {
178 sizeof(HEADER_FUNCTIONAL_DESCRIPTOR), //Size of this descriptor in bytes
C51 COMPILER V7.06 USB2UART 12/11/2007 01:02:42 PAGE 4
179 CS_INTERFACE_DESCRIPTOR, //CS_INTERFACE descriptor type
180 0x00, //Header functional descriptor subtype
181 SWAP16(0x0110) //CDC版本号
182 },
183
184 //call_management_functional_descriptor
185 {
186 sizeof(CALL_MANAGEMENT_FUNCTIONAL_DESCRIPTOR), //Size of this descriptor in bytes
187 CS_INTERFACE_DESCRIPTOR, //CS_INTERFACE descriptor type
188 0x01, //Call Management functional descriptor subtype
189 0x00, //D1=0: Device sends receives call management
190 //information only over the Communication Class interface.
191 //D0=0: Device does not handle call management itself
192 0x00 //Interface number of Data Class interface optionally used for call management(here not use).
193 },
194
195 //abstract_ontrol_anagement_unctional_escriptor
196 {
197 sizeof(ABSTRACT_CONTROL_MANAGEMENT_FUNCTIONAL_DESCRIPTOR), //Size of this descriptor in bytes
198 CS_INTERFACE_DESCRIPTOR, //CS_INTERFACE descriptor type
199 0x02, //Abstract Control Management functional descriptor subtype
200 0x02, //D3=0: Device DO NOT supports the notification Network_Connection.
201 //D2=0: Device DO NOT supports the request Send_Break
202 //D1=0: Device supports the request combination of
203 // Set_Line_Coding,Set_Control_Line_State,
204 // Get_Line_Coding, and the notification Serial_State.
205 },
206
207 //union_functional_descriptor
208 {
209 sizeof(UNION_FUNCTIONAL_DESCRIPTOR), //Size of this descriptor in bytes
210 CS_INTERFACE_DESCRIPTOR, //CS_INTERFACE descriptor type
211 0x06, //Union functional descriptor SubType
212 0x00, //MasterInterface,CDC接口
213 0x01 //SlaveInterface,数据接口
214 },
215
216 //endpoint1in_descriptor
217 { //中断输入端点描述
218 sizeof(ENDPOINT_DESCRIPTOR_STRUCT), //端点描述符的字节数大小
219 ENDPOINT_DESCRIPTOR, //端点描述符类型编号
220 POINT_1_IN, //端点号,输入端点1
221 ENDPOINT_TYPE_INTERRUPT, //使用的传输类型:中断传输
222 SWAP16(0x0010), //该端点支持的最大包尺寸,16字节
223 0x01 //中断扫描时间:设置为1ms
224 },
225
226 //interface_descritor //数据接口描述符
227 {
228 sizeof(INTERFACE_DESCRIPTOR_STRUCT), //接口描述符的字节数大小
229 INTERFACE_DESCRIPTOR, //接口描述符类型编号
230 0x01, //接口编号为1
231 0x00, //该接口描述符的备用编号
232 0x02, //端点数量为2,使用主端点输入和输出
233 0x0A, //所使用的类,Data Interface Class
234 0x00, //使用的子类
235 0x00, //使用的协议,Common AT commands
236 0x00 //接口描述符字符串索引
237 },
238 //endpoint2in_descriptor
239 { //主端点输入描述
240 sizeof(ENDPOINT_DESCRIPTOR_STRUCT), //端点描述符的字节数大小
C51 COMPILER V7.06 USB2UART 12/11/2007 01:02:42 PAGE 5
241 ENDPOINT_DESCRIPTOR, //端点描述符类型编号
242 MAIN_POINT_IN, //端点号,主输入端点
243 ENDPOINT_TYPE_BULK, //使用的传输类型:批量传输
244 SWAP16(0x0040), //该端点支持的最大包尺寸,64字节
245 0x0A //中断扫描时间:批量端点无效
246 },
247
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -