📄 d12_command.lst
字号:
C51 COMPILER V7.20 D12_COMMAND 09/11/2008 22:15:07 PAGE 1
C51 COMPILER V7.20, COMPILATION OF MODULE D12_COMMAND
OBJECT MODULE PLACED IN d12_command.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE d12_command.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include"mytype.h"
2 #include "d12_command.h"
3 #include"d12_value.h"
4 #include"port.h"
5 #include"my_usb.h"
6 #include "uar.h"
7 extern USB_FLAGS usb_flags;
8 extern INT_REG Interrupt_Register;
9 extern CONTROL_DATA_BUFF Control_Data;
10 //缓冲
11
12
13 //交换数据时用的指针
14 uint8 idle; //空闲状态
15 uint8 protocol; //当前协议
16
17
18 /***************************断开USB连接****************************************/
19 void disconnect_usb(void)
20 {
21 1 write_command(Set_Mode);
22 1 write_data(0x0e);
23 1 write_data(0x47);
24 1 del(100);
25 1 }
26 /*******************************连接USB**************************************/
27 void connect_usb(void)
28 {
29 1 write_command(Set_Mode); //初始化USBD12
30 1 write_data(0x1e); //连接USB
31 1 write_data(0x47); //设置频率
32 1 }
33
34 /******************************************************************************/
35 /*************************端点使能******************************************/
36 void set_endpoint_enable(void)
37 {
38 1 write_command(Set_Endpoint_Enable);
39 1 write_data(0x01);
40 1 }
41 /******************************************************************************/
42 /****************************读端点最后状态**********************************/
43 uint8 read_last_status(uint8 endp)
44 {
45 1 write_command(Read_Last_Status+endp);
46 1 return read_data();
47 1 }
48 /******************************************************************************/
49 /************************读USB中断寄存器**************************************/
50 void read_interrupt_register(void)
51 {
52 1 write_command(Read_Interrupt_Register);
53 1 Interrupt_Register.value[0]=read_data();
54 1 Interrupt_Register.value[1]=read_data();
55 1 }
C51 COMPILER V7.20 D12_COMMAND 09/11/2008 22:15:07 PAGE 2
56 /******************************************************************************/
57
58 /****************************USB总线复位处理***********************************/
59 void usb_bus_reset(void)
60 {usb_flags.value=0;
61 1 set_endpoint_enable();
62 1 Prints("USB总线复位.\r\0");
63 1 }
64 /******************************************************************************/
65 /*****************************USB总线挂起处理**********************************/
66 void usb_bus_suspend(void)
67 { Prints("USB总线挂起.\r\0");
68 1 }
69 /******************************************************************************/
70 /************************设置USB地址*******************************************/
71 void set_addr_enable(uint8 addr)
72 {
73 1 write_command(Set_Address);
74 1 write_data(0x80|addr);
75 1 Prints("USB地址:\0");
76 1 PrintHex(addr);
77 1 Prints("\r\0");
78 1 }
79
80
81
82 /******************************************************************************/
83 /****************************选择终端点*************************************/
84 uint8 select_endpoint(uint8 endp)
85 {
86 1 write_command(Select_EndPoint+endp);
87 1 return read_data();
88 1 }
89 /******************************************************************************/
90 void error(uint8 number)
91 {
92 1 number=0;
93 1 }
94 /************************清缓冲,在读取缓冲数据后调用**************************/
95 void clear_buffer(void)
96 {
97 1 write_command(Clear_Buffer);
98 1 }
99 /******************************************************************************/
100 /***********************缓冲区数据有效,在写缓冲后调用**************************/
101 void validate_buffer(void)
102 {
103 1 write_command(Validate_Buffer);
104 1
105 1 }
106 /******************************************************************************/
107 /****************************设置端点状态**************************************/
108 void set_endpoint_status(uint8 endp,uint8 status)
109 {
110 1 write_command(0x40+endp);
111 1 write_data(!status);
112 1 }
113 /******************************************************************************/
114 /***************************应答建立包************************************/
115 void ack_setup(uint8 endp)
116 {
117 1 select_endpoint(endp);
C51 COMPILER V7.20 D12_COMMAND 09/11/2008 22:15:07 PAGE 3
118 1 write_command(Ack_Setup);
119 1 }
120 /******************************************************************************/
121
122 /*****************************读端点状态**************************************/
123 uint8 read_endpoint_status(uint8 endp)
124 {
125 1 write_command(0x80+endp);
126 1 return read_data();
127 1 }
128 /******************************************************************************/
129 /*************************读终端点缓冲****************************************/
130 uint8 read_endpoint_buff(uint8 endp,uint8 len,uint8 * buff)
131 {
132 1 uint8 i,j;
133 1 if(!(select_endpoint(endp)&0x01)){error(0); return 0;}
134 1 if((read_endpoint_status(endp)&0x60)!=0x60) //两个缓冲没有都满,才能清中断
135 1 {
136 2 read_last_status(endp); //清中断
137 2 }
138 1 write_command(Read_Buffer);
139 1 read_data();
140 1 j=read_data();
141 1 if(j>len)
142 1 j=len;
143 1 for(i=0;i<j;i++)
144 1 {
145 2 USB_RD=0;
146 2 *(buff+i)=USB_DATA;
147 2 USB_RD=1;
148 2
149 2 }
150 1 if(endp)
151 1 {
152 2 select_endpoint(endp);
153 2 clear_buffer();
154 2 }
155 1 return j;
156 1 }
157 /******************************************************************************/
158
159 /*************************写终端点缓冲*****************************************/
160 uint8 write_endpoint_buff(uint8 endp,uint8 len,uint8 * buff)
161 {
162 1 uint8 i;
163 1 read_last_status(endp);
164 1 select_endpoint(endp);
165 1 write_command(Write_Buffer);
166 1 write_data(0);
167 1 write_data(len);
168 1
169 1 for(i=0;i<len;i++)
170 1 {
171 2 USB_DATA=*(buff+i);
172 2 USB_WR=0;
173 2 USB_WR=1;
174 2 }
175 1 USB_DATA=0xFF;
176 1 validate_buffer();
177 1 return len;
178 1 }
179 /******************************************************************************/
C51 COMPILER V7.20 D12_COMMAND 09/11/2008 22:15:07 PAGE 4
180
181 //以下为第9章节协议
182 /***************************设置地址***************************************/
183 void set_usb_address(void)//???
184 {
185 1 Control_Data.wLength=0;
186 1 Control_Data.pData=0;
187 1 usb_flags.Status.set_addr=1;
188 1 set_addr_enable((uint8) Control_Data.DeviceRequest.wValue);
189 1 }
190 /******************************************************************************/
191
192 /**************************获取状态响应*****************************************/
193 void get_status(uint8 receiver)
194 {
195 1 uint8 status[2];
196 1 switch (receiver)
197 1 {
198 2 case 0: //获取设备状态
199 2 status[0]=0x00;
200 2 status[1]=0x00;
201 2 break;
202 2 case 1: //获取接口状态
203 2 status[0]=0x00;
204 2 status[0]=0x00;
205 2 break;
206 2 case 2: //获取端点状态
207 2 status[0]=0x00;
208 2 status[1]=0x00;
209 2 break;
210 2 }
211 1 Control_Data.wLength=2;
212 1 Control_Data.pData=&status;
213 1 }
214 /******************************************************************************/
215
216 /*********************清除特性*******************************************/
217 void clear_feature(uint8 receiver)
218 {
219 1 receiver=0;
220 1 Control_Data.wLength=0;
221 1 Control_Data.pData=0;
222 1 }
223 /******************************************************************************/
224
225 /*******************设置特性**************************************************/
226 void set_feature(uint8 receiver)
227 {
228 1 receiver=0;
229 1 Control_Data.wLength=0;
230 1 Control_Data.pData=0;
231 1
232 1 }
233 /******************************************************************************/
234
235 /*****************************设置描述*****************************************/
236 void set_descriptor(void)
237 {Control_Data.wLength=0;
238 1 Control_Data.pData=0;
239 1
240 1 }
241 /******************************************************************************/
C51 COMPILER V7.20 D12_COMMAND 09/11/2008 22:15:07 PAGE 5
242
243 /***************************设置配置*******************************************/
244 void set_configuration(void)
245 {
246 1 Control_Data.wLength=0;
247 1 Control_Data.pData=0;
248 1
249 1 }
250 /******************************************************************************/
251
252 /************************获取配置状态******************************************/
253 void get_configuration(void)
254 {
255 1 uint8 value=0x01;
256 1 Control_Data.wLength=1;
257 1 Control_Data.pData=&value;
258 1 }
259 /******************************************************************************/
260
261 /****************************设置接口************************************/
262 void set_interface(void)
263 {
264 1 Control_Data.wLength=0;
265 1 Control_Data.pData=0;
266 1 }
267 /******************************************************************************/
268
269 /***************************获取接口状态***************************************/
270 void get_interface(void)
271 {
272 1 uint8 value=0x01;
273 1 Control_Data.wLength=1;
274 1 Control_Data.pData=&value;
275 1
276 1 }
277 /******************************************************************************/
278 uint16 i;
279 /***********************获取描述符*********************************************/
280 void get_descriptor(void)
281 {
282 1 //if(!usb_flags.Status.not_end)//如果已经结束则再次重新写入要的内容,如果还没有结束则转到以后的语句再次
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -