📄 mainloop.lst
字号:
217 1 disconnect and reconnect Soft-Connect */
218 1 reconnect_USB();
219 1
220 1 /* Main program loop */
221 1 while( in_loop ) {
222 2
223 2 /* timer 0 overflow */
224 2 if (bEPPflags.bits.timer) {
225 3 DISABLE;
226 3 bEPPflags.bits.timer = 0;
227 3 ENABLE;
228 3 if(bEPPflags.bits.configuration)
229 3 check_key_LED();
230 3 }
231 2
232 2 if (bEPPflags.bits.bus_reset) {
233 3 DISABLE;
234 3 bEPPflags.bits.bus_reset = 0;
235 3 ENABLE;
236 3 //D12SUSPD = 1; /* release D12 suspend control */
237 3 } // if bus reset
238 2
239 2 if (bEPPflags.bits.suspend) {
240 3 DISABLE;
241 3 bEPPflags.bits.suspend= 0;
C51 COMPILER V7.50 MAINLOOP 03/23/2005 21:15:55 PAGE 5
242 3 ENABLE;
243 3 //suspend_change();
244 3 } // if suspend change
245 2
246 2 if (bEPPflags.bits.setup_packet){
247 3 DISABLE;
248 3 bEPPflags.bits.setup_packet = 0;
249 3 ENABLE;
250 3 control_handler();
251 3 } // if setup_packet
252 2
253 2 } // Main Loop
254 1
255 1 }
*** WARNING C280 IN LINE 206 OF MAINLOOP.C: 'key': unreferenced local variable
*** WARNING C280 IN LINE 206 OF MAINLOOP.C: 'i': unreferenced local variable
256
257 /* wakeup D12, make MCU into low power mode, then suspend D12 again */
258 void suspend_change(void)
259 {
260 1 if (D12SUSPD == 1)
261 1 D12SUSPD = 0;
262 1
263 1 P0 = 0xFF;
264 1 P1 = 0xFF;
265 1 P2 = 0xFF;
266 1 P3 = 0xFF;
267 1 D12SUSPD = 1; /* suspend D12 */
268 1 PCON |= 0x02; /* into low power mode */
269 1 while (1) ; /* hangup, only reset could wake up MCU */
270 1 }
271
272 /* Stall Enpoints */
273 void stall_ep0(void)
274 {
275 1 D12_SetEndpointStatus(0, 1);
276 1 D12_SetEndpointStatus(1, 1);
277 1 }
278
279 void disconnect_USB(void)
280 {
281 1 //D12_SetMode(D12_NOLAZYCLOCK|D12_CLOCKRUNNING, D12_SETTOONE | D12_CLOCK_12M);
282 1 /* Clear Soft_Connect bit, disconnect pull-up resistor */
283 1 D12_SetMode(0x00, 0x00);
284 1 }
285
286 void connect_USB(void)
287 {
288 1 unsigned int i;
289 1 // reset event flags
290 1 DISABLE;
291 1 bEPPflags.value = 0; //for (i=0; i<11; i++) bEPPflags.c_value[i] = 0;
292 1 ENABLE;
293 1
294 1 // disable normal+sof interrupt
295 1 D12_SetDMA(0x00);
296 1
297 1 // Initialize D12 working mode
298 1 D12_SetMode(D12_NOLAZYCLOCK|D12_CLOCKRUNNING|D12_SOFTCONNECT, D12_SETTOONE | D12_CLOCK_12M);
299 1 //D12_SetMode(D12_SOFTCONNECT, 0x00); /* Enable softconnect */
300 1 }
*** WARNING C280 IN LINE 288 OF MAINLOOP.C: 'i': unreferenced local variable
C51 COMPILER V7.50 MAINLOOP 03/23/2005 21:15:55 PAGE 6
301
302
303 void reconnect_USB(void)
304 {
305 1 unsigned long clk_cnt;
306 1
307 1 //Turn on LEDs
308 1 MCU_LED0 = 0;
309 1 MCU_LED1 = 0;
310 1
311 1 //D12SUSPD = 0; /* wakeup D12 */
312 1 disconnect_USB();
313 1
314 1 clk_cnt = ClockTicks;
315 1 while(ClockTicks < clk_cnt + 20)
316 1 ;
317 1
318 1 connect_USB();
319 1
320 1 //Trun off LEDs
321 1 MCU_LED0 = 1;
322 1 MCU_LED1 = 1;
323 1
324 1 }
325
326 void init_unconfig(void)
327 {
328 1 unsigned char i;
329 1
330 1 D12_SetEndpointEnable(0); /* Disable all endpoints but EPP0. */
331 1 }
*** WARNING C280 IN LINE 328 OF MAINLOOP.C: 'i': unreferenced local variable
332
333 void init_config(void)
334 {
335 1 D12_SetEndpointEnable(1); /* Enable generic/iso endpoints. */
336 1 }
337
338 void single_transmit(unsigned char * buf, unsigned char len)
339 {
340 1 if( len <= EP0_PACKET_SIZE) {
341 2 D12_WriteEndpoint(1, buf, len);
342 2 }
343 1 }
344
345 void code_transmit(unsigned char code * pRomData, unsigned short len)
346 {
347 1 ControlData.wCount = 0;
348 1 if(ControlData.wLength > len)
349 1 ControlData.wLength = len;
350 1
351 1 ControlData.pData = pRomData;
352 1 if( ControlData.wLength >= EP0_PACKET_SIZE) {
353 2 D12_WriteEndpoint(1, ControlData.pData, EP0_PACKET_SIZE);
354 2 ControlData.wCount += EP0_PACKET_SIZE;
355 2
356 2 DISABLE;
357 2 bEPPflags.bits.control_state = USB_TRANSMIT;
358 2 ENABLE;
359 2 }
360 1 else {
361 2 D12_WriteEndpoint(1, pRomData, ControlData.wLength);
C51 COMPILER V7.50 MAINLOOP 03/23/2005 21:15:55 PAGE 7
362 2 ControlData.wCount += ControlData.wLength;
363 2 DISABLE;
364 2 bEPPflags.bits.control_state = USB_IDLE;
365 2 ENABLE;
366 2 }
367 1 }
368
369 /* LED and Key Processing subroutine */
370 void check_key_LED(void)
371 {
372 1 static unsigned char c, last_key = 0xf;
373 1
374 1 // Key processing (infor current key status to host)
375 1 c = MCU_SWM0 & MCU_SWM1; /* get two keys status */
376 1 c &= 0x0f;
377 1 if (c != last_key & bEPPflags.bits.ep1_sxdone) { /* Keys status have been changed */
378 2 bEPPflags.bits.ep1_sxdone = 0;
379 2 D12_WriteEndpoint(3, &c, 1); /* send key information to host */
380 2 }
381 1 last_key = c; /* store current key status */
382 1
383 1 // LED processing (get LED info, and set LED
384 1 if(bEPPflags.bits.ep1_rxdone) { /* Get LED control command */
385 2 DISABLE;
386 2 bEPPflags.bits.ep1_rxdone = 0; /* Clear the endpoint receiving flag */
387 2 ENABLE;
388 2
389 2 MCU_LED0 = !(GenEpBuf[3] & 0x1); /* Cnage LED status */
390 2 MCU_LED1 = !(GenEpBuf[3] & 0x2);
391 2 }
392 1 }
393
394
395 void control_handler()
396 {
397 1 unsigned char type, req;
398 1
399 1 type = ControlData.DeviceRequest.bmRequestType & USB_REQUEST_TYPE_MASK; /*0x60*/
400 1 req = ControlData.DeviceRequest.bRequest & USB_REQUEST_MASK; /*0x0F*/
401 1
402 1 if (type == USB_STANDARD_REQUEST)
403 1 (*StandardDeviceRequest[req])();
404 1 // if (type == USB_CLASS_REQUEST) {
405 1 //blinkLED(0);
406 1 // (*ClassRequest[req])();
407 1 // }
408 1 else if (type == USB_VENDOR_REQUEST)
409 1 (*VendorDeviceRequest[req])();
410 1 else
411 1 stall_ep0();
412 1 }
413
414 void loop_delay(const unsigned int nDelay)
415 {
416 1 unsigned int x, y;
417 1 for (x=0; x<=nDelay;x++) {
418 2 for (y=0;y<=110;y++) ;
419 2 }
420 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
C51 COMPILER V7.50 MAINLOOP 03/23/2005 21:15:55 PAGE 8
CODE SIZE = 670 ----
CONSTANT SIZE = 472 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 27 17
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 4 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -