📄 mass_stg.lst
字号:
412 1 System_Config();
413 1 CLR_Flags();
414 1 Read_ID();
415 1 //page_read(0,0, 0);
416 1 fill_DBR();
417 1 //block_buffer(0);
418 1 //check_invalid();
419 1 //test_flash();
420 1 USB_Config();
421 1
422 1
423 1 while(1)
424 1 {
425 2 if(flags.epin1 | flags.epout1)
426 2 Analysis_UFI();
427 2
C51 COMPILER V7.06 MASS_STG 10/19/2007 15:26:26 PAGE 8
-
-
-
-
428 2 }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
429 1
430 1 }
431
432 /****************************************************************************************
433 name: USB_ISR
434 function: USB Interrupt Service Routine
435 pars: no
436 returns: no
437 ******************************************************************************************/
438 void USB_ISR(void) interrupt 8
439 {
440 1 uchar CMINT_FLAG,IN_FLAG, OUT_FLAG; //Interrupt flags,IN,OUT and Common
441 1 xdata uchar RevBuf[8]; //Save the host Requst Command
442 1 Requst *pReq;
443 1 uchar cmd, number, i;
444 1
445 1
446 1 //read interrupt status
447 1 CMINT_FLAG = SFR_RD(CMINT); //save the Interrupt flags for
448 1 //Subroutine Entry
449 1 IN_FLAG = SFR_RD(IN1INT);
450 1 OUT_FLAG = SFR_RD(OUT1INT);
451 1
452 1
453 1 //interrupt subroutine process
454 1 if(CMINT_FLAG & BIT2) //Reset procedure
455 1 {
456 2 while(SFR_RD(POWER) & 0x08);
457 2 USB_Config();
458 2
459 2 }
460 1 else if(IN_FLAG & BIT0) //Endpoint 0 affairs procedure
461 1 {
462 2 SFR_WR(INDEX, 0x00);
463 2 cmd = SFR_RD(E0CSR);
464 2 if(cmd & BIT0)
465 2 {
466 3 number = SFR_RD(E0CNT);
467 3 for(i=0;i<number;i++) //Receive the host Requst
468 3 RevBuf[i] = SFR_RD(FIFO0);
C51 COMPILER V7.06 MASS_STG 10/19/2007 15:26:26 PAGE 9
469 3 cmd |= 0x48; //Clear the Receive Interrupt Flag
470 3 //and indicate Receive Data is END
471 3 SFR_WR(E0CSR, cmd);
472 3 pReq = (pRequst)RevBuf;
473 3 Analysis_Requst(pReq);
474 3
475 3
476 3 }
477 2
478 2 else if(cmd & BIT2) //Stall procedure
479 2 {
480 3 cmd &= ~BIT2;
481 3 SFR_WR(E0CSR, cmd);
482 3 //LED = 1;
483 3 }
484 2
485 2
486 2 }
487 1 if(IN_FLAG & BIT1)
488 1 flags.epin1 = 1;
489 1 if(OUT_FLAG & BIT1)
490 1 flags.epout1 = 1;
491 1
492 1 }
493 /*****************************************************************************************
494 Delay 1mS Subroutine
495 ******************************************************************************************/
496 void Delay_mS(uchar t)
497 {
498 1 uint i;
499 1 uchar j;
500 1 for(j=0;j<t;j++)
501 1 for(i=0;i<20000;i++);
502 1
503 1 }
504
505 void Delay_uS(uint t)
506 {
507 1 do
508 1 {
509 2 _nop_();_nop_();
510 2 _nop_();_nop_();
511 2 _nop_();_nop_();
512 2 _nop_();_nop_();
513 2 }while(t--);
514 1
515 1
516 1 }
517
518 /*****************************************************************************************
519 name: Oscillator_Init
520 function: initial the system clock and 48MHz USB clock
521 pars: no
522 returns: no
523 ******************************************************************************************/
524 void Oscillator_Init(void)
525 {
526 1 int i = 0;
527 1 CLKMUL = 0x80;
528 1 for (i = 0; i < 20; i++); // Wait 5us for initialization
529 1 CLKMUL |= 0xC0;
530 1 while ((CLKMUL & 0x20) == 0);
C51 COMPILER V7.06 MASS_STG 10/19/2007 15:26:26 PAGE 10
531 1 CLKSEL = 0x02;
532 1 OSCICN = 0x83;
533 1 }
534
535 /******************************************************************************************
536 name: System_Config
537 function: Config the IO Port and Interrupt source
538 pars: no
539 renturns: no
540 *******************************************************************************************/
541 void System_Config(void)
542 {
543 1 PCA0MD &= ~0x40; //Disable WDT
544 1 //PCA0MD = 0x00;
545 1 P0MDOUT = 0x02;
546 1 P1MDOUT = 0x00; //Open Drain mode
547 1 P2MDOUT = 0xBF; //Push-pull output
548 1 XBR1 = 0x40; //Enable Weak Pull-up
549 1 REG0CN = 0x10; //Enable internal LDO, Low Power mode
550 1 GND = 1;
551 1 WP = 1;
552 1 RE = 1;
553 1 WE = 1;
554 1 CE = 1;
555 1 ALE = 0;
556 1 CLE = 0;
557 1
558 1
559 1 }
560
561 /******************************************************************************************
562 name: USB_Config
563 function: USB SIE function Config
564 pars: no
565 returns: no
566 ********************************************************************************************/
567 void USB_Config(void)
568 {
569 1 RSTSRC &= ~0x80; //Disable USB VBUS Reset
570 1 IE = 0x80;
571 1 EIE1 = 0x02; //Enable USB interrupt
572 1 USB0XCN = 0xE0; //Enable Tranceiver, Full Speed Mode
573 1 SFR_WR(CLKREC, 0x89); //Enable USB clock Recovery Ciruit
574 1 SFR_WR(CMIE, 0x04); //Enable Reset Interrupt
575 1 SFR_WR(INIE, 0x0F); //Enable EndPoint0-3 input Interrupt
576 1 SFR_WR(OUTIE, 0x0F); //Enable EndPoint0-3 output Interrupt
577 1 SFR_WR(INDEX, 0x01); //Split the FIFO into two halfs for input
578 1 SFR_WR(EINCSRH, 0x4); //Endpoint and output Endpoint
579 1 SFR_WR(EOUTCSRH,0x0); //Endpoint 1, 2, 3 are configured Double Buffer
580 1 SFR_WR(INDEX, 0x02);
581 1 SFR_WR(EINCSRH, 0x4);
582 1 SFR_WR(EOUTCSRH,0x0);
583 1 SFR_WR(INDEX, 0x03);
584 1 SFR_WR(EINCSRH, 0x4);
585 1 SFR_WR(EOUTCSRH,0x0);
586 1 SFR_WR(INDEX, 0x00);
587 1 SFR_WR(POWER, 0x00); //Enable USB0
588 1
589 1
590 1
591 1 }
592 /*******************************************************************************************
C51 COMPILER V7.06 MASS_STG 10/19/2007 15:26:26 PAGE 11
593 name: SFR_WR
594 function: wirte the cmd or data to the desired USB FSR by USB0ADDR and USB0DAT
595 pars: addr(SFR's address), dat(cmd or data)
596 returns: no
597 ********************************************************************************************/
598 void SFR_WR(uchar addr, uchar dat)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -