📄 main.lst
字号:
C51 COMPILER V7.07 MAIN 06/04/2004 18:36:52 PAGE 1
C51 COMPILER V7.07, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN MAIN.OBJ
COMPILER INVOKED BY: D:\Keil\C51\BIN\C51.EXE MAIN.c DB OE SMALL ROM(LARGE)
stmt level source
1 //**********************************************************************************************//
2 /* */
3 /* USB to Serial V1.0版 */
4 /* */
5 /* FirmWare Files */
6 /* COPYRIGHT (c) 2004 BY GARY 应用物理学 物理实验中心 */
7 /* */
8 /* Files Name: MAIN.C */
9 /* Author: Gary Zou LuDing */
10 /* Created: March 2004 */
11 /* Modified: */
12 /* Revision: 1.0 */
13 /* Other Details: */
14 /* */
15 /* */
16 /* */
17 //**********************************************************************************************//
18
19
20 #include <stdio.h>
21 #include <string.h>
22
23 #include "usb100.h"
24 #include "reg52.h"
25 #include "hal.h"
26 #include "d12ci.h"
27 #include "isr.h"
28 #include "chap_9.h"
29 #include "vendor.h"
30 #include "main.h"
31
32
33 /****************************************/
34 //定义全局静态数据成员
35 /****************************************/
36
37 FLAG flag; //中断事务标志存储区
38 CTRL_BUF ctrl_buf; //控制端点设置包数据存储区
39 unsigned char idata enp1_buf[16];
40 unsigned char idata enp1_len;
41 unsigned char idata enp2_buf[64];
42 unsigned char idata enp2_len;
43
44 unsigned char idata serial_buf[16];
45 unsigned char idata s2u_len=0;
46
47 unsigned char idata time[4]={0,0,0,0};
48 unsigned char idata chartime[14]={'T','I','M','E',':',0,0,':',0,0,':',0,0,'\n'};
49
50
51 /****************************************/
52 //主函数定义
53 /****************************************/
54
55 void main(void)
C51 COMPILER V7.07 MAIN 06/04/2004 18:36:52 PAGE 2
56 {
57 1 unsigned char i;
58 1 unsigned char temp;
59 1 init();
60 1 //d12_set_dma(0x00); //不使用DMA
61 1 //printf("ready to reconnect\n");
62 1 d12_reconnect_usb();
63 1 //printf("already been reconnect\n");
64 1 while(TRUE)
65 1 {
66 2 if(flag.bits.timer==1)
67 2 {
68 3 DISABLE_ALL_INTERRUPT;
69 3 flag.bits.timer=0;
70 3 ENABLE_ALL_INTERRUPT;
71 3 if(time[3]<19)time[3]++;
72 3 else {
73 4 time[3]=0;
74 4 if(time[2]<59)time[2]++;
75 4 else{
76 5 time[2]=0;
77 5 if(time[1]<59)time[1]++;
78 5 else{
79 6 time[1]=0;
80 6 if(time[0]<23)time[0]++;
81 6 else time[0]=0;
82 6 }
83 5 }
84 4 }
85 3
86 3 }
87 2 if(flag.bits.showtime==1)
88 2 {
89 3 DISABLE_ALL_INTERRUPT;
90 3 flag.bits.showtime=0;
91 3 ENABLE_ALL_INTERRUPT;
92 3 temp=time[0]/10;
93 3 chartime[5]=temp+0x30;
94 3 chartime[6]=time[0]-temp*10+0x30;
95 3 temp=time[1]/10;
96 3 chartime[8]=temp+0x30;
97 3 chartime[9]=time[1]-temp*10+0x30;
98 3 temp=time[2]/10;
99 3 chartime[11]=temp+0x30;
100 3 chartime[12]=time[2]-temp*10+0x30;
101 3 d12_write_endpoint(3,chartime,14);
102 3 printf("time:%bu:%bu:%bu\n",time[0],time[1],time[2]);
103 3 }
104 2 if(flag.bits.bus_reset)
105 2 {
106 3 DISABLE_ALL_INTERRUPT;
107 3 flag.bits.bus_reset=0;
108 3 ENABLE_ALL_INTERRUPT;
109 3 D12_SUSPD = 1;
110 3 }
111 2 if(flag.bits.suspend)
112 2 {
113 3 DISABLE_ALL_INTERRUPT;
114 3 flag.bits.suspend=0;
115 3 ENABLE_ALL_INTERRUPT;
116 3 if(D12_SUSPD == 1)
117 3 {
C51 COMPILER V7.07 MAIN 06/04/2004 18:36:52 PAGE 3
118 4 D12_SUSPD = 0;
119 4 P0 = 0xFF;
120 4 P1 = 0xFF;
121 4 P2 = 0xFF;
122 4 P3 = 0xFF;
123 4 D12_SUSPD = 1;
124 4 }
125 3 }
126 2 if(flag.bits.setup_packet)
127 2 {
128 3 DISABLE_ALL_INTERRUPT;
129 3 flag.bits.setup_packet=0;
130 3 //printf("receive packet\n");
131 3 control_handler();
132 3 ENABLE_ALL_INTERRUPT;
133 3 D12_SUSPD=1;
134 3 }
135 2 if(flag.bits.enp1_rxdone==1)
136 2 {
137 3 DISABLE_ALL_INTERRUPT;
138 3 flag.bits.enp1_rxdone=0;
139 3 ENABLE_ALL_INTERRUPT;
140 3 if(enp1_buf[0]=='T'& enp1_buf[1]==' '& enp1_buf[2]=='W'& enp1_len==12){
141 4 time[0]=(enp1_buf[4]-0x30)*10+(enp1_buf[5]-0x30);
142 4 time[1]=(enp1_buf[7]-0x30)*10+(enp1_buf[8]-0x30);;
143 4 time[2]=(enp1_buf[10]-0x30)*10+(enp1_buf[11]-0x30);
144 4 printf("USB set time command OK!\n");
145 4 }
146 3 else if(enp1_buf[0]=='T'& enp1_buf[1]==' '& enp1_buf[2]=='R'&enp1_len==3){
147 4 //d12_write_endpoint(3,time,3);
148 4 //printf("time:%bu:%bu:%bu\n",time[0],time[1],time[2]);
149 4 flag.bits.showtime=1;
150 4 }
151 3 else for(i=0;i<enp1_len;i++)
152 3 printf("%c",enp1_buf[i]);
153 3 //printf("\n");
154 3 //if(enp1_len>0)
155 3 //d12_write_endpoint(3,enp1_buf,enp1_len);
156 3 enp1_len=0;
157 3
158 3
159 3 }
160 2 if(flag.bits.enp2_rxdone==1)
161 2 {
162 3 DISABLE_ALL_INTERRUPT;
163 3 flag.bits.enp2_rxdone=0;
164 3 ENABLE_ALL_INTERRUPT;
165 3 if(flag.bits.enp2buf_full==1)
166 3 {
167 4 DISABLE_ALL_INTERRUPT;
168 4 flag.bits.enp2buf_full=0;
169 4 ENABLE_ALL_INTERRUPT;
170 4 printf("enp2 double_buf been full\n");
171 4
172 4 }
173 3 for(i=0;i<enp2_len;i++)
174 3 printf("%c",enp2_buf[i]);
175 3 //printf("\n")
176 3 //if(enp2_len>0)
177 3 //d12_write_endpoint(5,enp2_buf,enp2_len);
178 3 enp2_len=0;
179 3 }
C51 COMPILER V7.07 MAIN 06/04/2004 18:36:52 PAGE 4
180 2 if(RI)
181 2 {
182 3 DISABLE_ALL_INTERRUPT;
183 3 serial_send_to_endp1();
184 3 ENABLE_ALL_INTERRUPT;
185 3 }
186 2 }
187 1 }
188
189
190
191 /**************************************
192 USB标准设备请求函数入口指针数组
193 **************************************/
194 code void (*StandardDeviceRequest[])(void)=
195 {
196 get_status, /*0x00*/
197 clear_feature, /*0x01*/
198 reserved,
199 set_feature, /*0x03*/
200 reserved,
201 set_address, /*0x05*/
202 get_descriptor, /*0x06*/
203 reserved,
204 get_configuration, /*0x08*/
205 set_configuration, /*0x09*/
206 get_interface, /*0x0A*/
207 set_interface, /*0x0B*/
208 reserved,
209 reserved,
210 reserved,
211 reserved
212 };
213 /***************************************
214 //厂商请求函数入口指针数组
215 ***************************************/
216 code void (*VendorDeviceRequest[])(void)=
217 {
218 reserved,
219 reserved,
220 reserved,
221 reserved,
222 reserved,
223 reserved,
224 reserved,
225 reserved,
226 reserved,
227 reserved,
228 reserved,
229 reserved,
230 reserved,
231 reserved,
232 reserved,
233 reserved
234 };
235
236
237 void control_handler()
238 {
239 1
240 1 unsigned char type,req;
241 1 //printf("call control handler\n");
C51 COMPILER V7.07 MAIN 06/04/2004 18:36:52 PAGE 5
242 1 type=ctrl_buf.dev_req.req_type&0x60;
243 1 req=ctrl_buf.dev_req.req&0x0F;
244 1 if(type==0x00){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -