📄 usb_main.lst
字号:
C51 COMPILER V6.23a USB_MAIN 12/24/2005 14:35:50 PAGE 1
C51 COMPILER V6.23a, COMPILATION OF MODULE USB_MAIN
OBJECT MODULE PLACED IN D:\PRJ\SMARTOK\USB_MAIN.OBJ
COMPILER INVOKED BY: C:\keil623\C51\BIN\C51.EXE D:\PRJ\SMARTOK\USB_MAIN.C DB SB OE SMALL
stmt level source
1
2
3 #include "usb_inc.h"
4
5 //=====================================
6
7 /*
8 //*************************************************************************
9 // USB protocol function pointer arrays
10 //*************************************************************************
11 */
12 code void (*StandardDeviceRequest[])(void) =
13 {
14 get_status,
15 clear_feature,
16 reserved,
17 set_feature,
18 reserved,
19 set_address,
20 get_descriptor,
21 reserved,
22 get_configuration,
23 set_configuration,
24 get_interface,
25 set_interface,
26 reserved,
27 reserved,
28 reserved,
29 reserved
30 };
31
32 code void (*VendorDeviceRequest[])(void) =
33 {
34 reserved,
35 reserved,
36 reserved,
37 reserved,
38 reserved,
39 reserved,
40 reserved,
41 reserved,
42 reserved,
43 reserved,
44 reserved,
45 reserved,
46 read_write_register,
47 reserved,
48 reserved,
49 reserved
50 };
51
52
53
54
55
C51 COMPILER V6.23a USB_MAIN 12/24/2005 14:35:50 PAGE 2
56
57
58 timer_isr() interrupt 1
59 {
60 1 DISABLE;
61 1 ClockTicks++;
62 1 bEPPflags.bits.timer = 1;
63 1 ENABLE;
64 1 }
65
66
67 usb_isr() interrupt 2
68 {
69 1 unsigned char x;
70 1 DISABLE;
71 1 //fn_usb_isr();
72 1 //unsigned int st;
73 1 //unsigned char x,st;
74 1 bEPPflags.bits.in_isr = 1;
75 1 x = D12_ReadInterruptRegister();
76 1 //st=x;
77 1 //i=st;
78 1 if(x != 0) {
79 2 //if(i_st & D12_INT_BUSRESET) {
80 2 if(x & 0x40) {
81 3 bus_reset();
82 3 bEPPflags.bits.bus_reset = 1;
83 3 }
84 2
85 2 //if(x & D12_INT_EOT)
86 2 //dma_eot();
87 2
88 2 if(x & D12_INT_SUSPENDCHANGE)
89 2 bEPPflags.bits.suspend = 1;
90 2
91 2
92 2 if(x & D12_INT_ENDP0IN)
93 2 ep0_txdone();
94 2 if(x & D12_INT_ENDP0OUT)
95 2 ep0_rxdone();
96 2 if(x & D12_INT_ENDP1IN)
97 2 ep1_txdone();
98 2 if(x & D12_INT_ENDP1OUT)
99 2 ep1_rxdone();
100 2 if(x & D12_INT_ENDP2IN)
101 2 main_txdone();
102 2 if(x & D12_INT_ENDP2OUT)
103 2 main_rxdone();
104 2
105 2 }
106 1
107 1 bEPPflags.bits.in_isr = 0;
108 1
109 1
110 1
111 1 ENABLE;
112 1 }
113
114 //==================================================
115 /*
116 PCON: SMOD | - | - | - | GF1|GF0|PD |IDL|
117 TCON: TF1 | - |TF0| - |IE1 |IT1|IE0|IT0|
C51 COMPILER V6.23a USB_MAIN 12/24/2005 14:35:50 PAGE 3
118
119 */
120 /* Configure Timer 0
121 - Mode = 1
122 - Interrupt = ENABLED
123 - Clock Source = INTERNAL
124 - Enable Gating Control = DISABLED
125 */
126
127
128 void init_timer0(void)
129 {
130 1 TMOD &= 0XF0; /* clear Timer 0 */
131 1 TMOD |= 0X1;
132 1 TL0 = 0X0; /* value set by user */
133 1 TH0 = 0X0; /* value set by user */
134 1 ET0 = 1; /* IE.1*/
135 1 TR0 = 1; /* TCON.4 start timer */
136 1 PT0 = 1;
137 1
138 1 //EA = 1;
139 1 }
140
141
142 void init_port()
143 {
144 1 P0 = 0xFF;
145 1 P1 = 0xFF;
146 1 P2 = 0xFF;
147 1 P3 = 0xFF;
148 1 D12SUSPD = 0; //D12 not in Suspend
149 1 }
150
151
152
153 //=================================================================
154 void disconnect_USB(void)
155 {
156 1 // Initialize D12 configuration
157 1 D12_SetMode(D12_NOLAZYCLOCK|D12_CLOCKRUNNING, D12_SETTOONE | D12_CLOCK_12M);
158 1 }
159
160 void connect_USB(void)
161 {
162 1 // reset event flags
163 1
164 1 DISABLE;
165 1 bEPPflags.value = 0;
166 1 ENABLE;
167 1
168 1 // ENABLE_INTERRUPTS;
169 1
170 1 D12_SetEndpointStatus(4, 0);
171 1 D12_SetEndpointStatus(5, 0);
172 1 // V2.1 enable normal+sof interrupt
173 1 D12_SetDMA(D12_ENDP4INTENABLE | D12_ENDP5INTENABLE);
174 1
175 1 // Initialize D12 configuration
176 1
177 1 //D12_SetMode(D12_NOLAZYCLOCK ,D12_SETTOONE | D12_CLOCK_12M );
178 1 D12_SetMode(D12_NOLAZYCLOCK |D12_CLOCKRUNNING|D12_SOFTCONNECT,D12_SETTOONE | D12_CLOCK_12M );
179 1
C51 COMPILER V6.23a USB_MAIN 12/24/2005 14:35:50 PAGE 4
180 1 }
181
182
183 void reconnect_USB(void)
184 {
185 1 unsigned long clk_cnt;
186 1
187 1
188 1
189 1 // Pull-down D12's SUSPEND pin
190 1 // Disable 74HCT123 pulse generation before disconnect
191 1 // Release D12's SUSPEND pin after receiving bus reset from host
192 1 D12SUSPD = 0;
193 1 disconnect_USB();
194 1 ENABLE;
195 1 //printf("Wait for 1 second ...\n");
196 1 for (clk_cnt=0;clk_cnt<50000;clk_cnt++);
197 1
198 1 DISABLE;
199 1
200 1 connect_USB();
201 1
202 1
203 1 }
204 //------------------------------
205 void stall_ep0(void)
206 {
207 1 D12_SetEndpointStatus(0, 1);
208 1 D12_SetEndpointStatus(1, 1);
209 1 }
210
211 //---------------
212
213 //----------------------------------
214 void check_key_LED(void)
215 {
216 1 static unsigned char c, last_key = 0xf;
217 1
218 1 c = MCU_SWM0 & MCU_SWM1;
219 1 c &= 0x0f;
220 1 if (c != last_key) {
221 2 D12_WriteEndpoint(3, 1, &c);
222 2 }
223 1
224 1 last_key = c;
225 1
226 1 if(bEPPflags.bits.ep1_rxdone) {
227 2 DISABLE;
228 2 bEPPflags.bits.ep1_rxdone = 0;
229 2 ENABLE;
230 2 MCU_LED0 = !(GenEpBuf[3] & 0x1);
231 2 MCU_LED1 = !(GenEpBuf[3] & 0x2);
232 2 }
233 1 }
234 //--------------------------
235 void init_unconfig(void)
236 {
237 1 //unsigned char i;
238 1
239 1 D12_SetEndpointEnable(0); /* Disable all endpoints but EPP0. */
240 1 }
241
C51 COMPILER V6.23a USB_MAIN 12/24/2005 14:35:50 PAGE 5
242 void init_config(void)
243 {
244 1 D12_SetEndpointEnable(1); /* Enable generic/iso endpoints. */
245 1 }
246 //--------------------------
247
248 void single_transmit(unsigned char * buf, unsigned char len)
249 {
250 1 if( len <= EP0_PACKET_SIZE) {
251 2 D12_WriteEndpoint(1, len, buf);
252 2 }
253 1 }
254
255 void code_transmit(unsigned char code * pRomData, unsigned short len)
256 {
257 1 ControlData.wCount = 0;
258 1 if(ControlData.wLength > len)
259 1 ControlData.wLength = len;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -