⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sl811.lst

📁 采用811芯片实现单片机读写U盘的源代码
💻 LST
📖 第 1 页 / 共 4 页
字号:
 576   1      
 577   1              //------------------------------------------------
 578   1              // Get USB Device Descriptors on EP0 & Addr X
 579   1              //------------------------------------------------
 580   1              pDev =(pDevDesc)DBUF;
 581   1              usbstack.usbaddr=uAddr;
 582   1              
 583   1              usbstack.setup.wLength=pDev->bLength;
 584   1              usbstack.setup.wValue=DEVICE;
 585   1              usbstack.setup.wIndex=0;
 586   1              
 587   1              //usbstack.setup.wLength=0x12;//(unsigned short)DBUF[0];//pDev->bLength;
 588   1              usbstack.buffer=DBUF;
 589   1              
 590   1              if (!GetDesc())         
 591   1                      return FALSE;                                                           // For this current device:
 592   1              uDev.wVID  = pDev->idVendor;                    // save VID
 593   1              uDev.wPID  = pDev->idProduct;                   // save PID
 594   1              uDev.iMfg  = pDev->iManufacturer;               // save Mfg Index
 595   1              uDev.iPdt  = pDev->iProduct;                    // save Product Index
 596   1      
 597   1              //------------------------------------------------
 598   1              // Get String Descriptors
 599   1              //------------------------------------------------
 600   1              //------------------------------------------------
 601   1              // Get Slave USB Configuration Descriptors
 602   1              //------------------------------------------------
 603   1              
 604   1              pCfg = (pCfgDesc)DBUF;  
 605   1              
 606   1              usbstack.usbaddr=uAddr;
 607   1              usbstack.setup.wValue=CONFIGURATION;
 608   1              usbstack.setup.wIndex=0;
 609   1              usbstack.setup.wLength=64;
 610   1              usbstack.buffer=DBUF;   
 611   1              if (!GetDesc())                 
 612   1                      return FALSE;   
C51 COMPILER V7.00  SL811                                                                  09/22/2005 17:57:50 PAGE 11  

 613   1              
 614   1              pIfc = (pIntfDesc)(DBUF + 9);                                   // point to Interface Descp
 615   1              uDev.bClass     = pIfc->iClass;                 // update to class type
 616   1              uDev.bNumOfEPs = (pIfc->bEndPoints <= MAX_EP) ? pIfc->bEndPoints : MAX_EP;
 617   1              
 618   1              if(uDev.bClass==8) //mass storage device
 619   1                      bXXGFlags.bits.bMassDevice=TRUE;
 620   1              //------------------------------------------------
 621   1              // Set configuration (except for HUB device)
 622   1              //------------------------------------------------
 623   1              usbstack.usbaddr=uAddr;
 624   1              usbstack.setup.wValue=DEVICE;
 625   1              //if (uDev[usbaddr].bClass!=HUBCLASS)                           // enumerating a FS/LS non-hub device
 626   1                      if (!Set_Configuration())               // connected directly to SL811HS
 627   1                                      return FALSE;
 628   1      
 629   1              //------------------------------------------------
 630   1              // For each slave endpoints, get its attributes
 631   1              // Excluding endpoint0, only data endpoints
 632   1              //------------------------------------------------
 633   1              
 634   1              epLen = 0;
 635   1              for (i=1; i<=uDev.bNumOfEPs; i++)                               // For each data endpoint
 636   1              {
 637   2                      pEnp = (pEPDesc)(DBUF + 9 + 9 + epLen);                         // point to Endpoint Descp(non-HID)
 638   2                      //if(pIfc->iClass == HIDCLASS)  
 639   2                      //      pEnp = (pEPDesc)(DBUF + 9 + 9 + 9 + epLen);             // update pointer to Endpoint(HID)
 640   2                      uDev.bEPAddr[i]         = pEnp->bEPAdd;                 // Ep address and direction
 641   2                      uDev.bAttr[i]           = pEnp->bAttr;                  // Attribute of Endpoint
 642   2                      uDev.wPayLoad[i]        = WordSwap(pEnp->wPayLoad);             // Payload of Endpoint
 643   2                      uDev.bInterval[i]       = pEnp->bInterval;              // Polling interval
 644   2                      uDev.bData1[i] = 0;                                 // init data toggle
 645   2                      epLen += 7;
 646   2                      //////////////////////////////
 647   2                      if(uDev.bAttr[i]==0x2)
 648   2                      {
 649   3                          if(uDev.bEPAddr[i]&0x80)
 650   3                              usbstack.epbulkin=uDev.bEPAddr[i];
 651   3                          else
 652   3                              usbstack.epbulkout=uDev.bEPAddr[i];
 653   3                      }
 654   2                      //////////////////////////////
 655   2              }
 656   1              
 657   1              return TRUE;
 658   1      }
 659          
 660          
 661          void SL811_Init(void)
 662          {       
 663   1              bXXGFlags.nValue=0;
 664   1              
 665   1              SL811Write(cDATASet,0xe0);
 666   1              SL811Write(cSOFcnt,0xae);
 667   1              SL811Write(CtrlReg,0x5);
 668   1                              
 669   1              SL811Write(EP0Status,0x50);
 670   1              SL811Write(EP0Counter,0);
 671   1              SL811Write(EP0Control,0x01);
 672   1                              
 673   1              
 674   1              SL811Write(IntEna,0x20);                // USB-A, Insert/Remove, USB_Resume.
C51 COMPILER V7.00  SL811                                                                  09/22/2005 17:57:50 PAGE 12  

 675   1              SL811Write(IntStatus,INT_CLEAR);        // Clear Interrupt enable status
 676   1      }
 677          
 678          void check_key_LED(void)
 679          {
 680   1      //      static unsigned char last_key=0x7;
 681   1      //      unsigned char *pBuf;//=(unsigned char *)&UartCmdBlock;
 682   1      //      unsigned int *wpBuf;
 683   1              unsigned char intr;
 684   1      //      unsigned int i,len;
 685   1              //SL811Write(IntStatus,INSERT_REMOVE);
 686   1              intr=SL811Read(IntStatus);
 687   1              #ifdef ZLH_DEBUG
 688   1              disp_data(2,"A1");
 689   1              disp_data(1,&intr);
 690   1              while(!getkey());
 691   1              disp_data(2, "A5");
 692   1              #endif
 693   1              if(intr & USB_RESET)
 694   1                         {
 695   2                         MCU_LED0=1;
 696   2                                      //bXXGFlags.bits.SLAVE_IS_ATTACHED = FALSE;     // Set USB device found flag
 697   2                         if(bXXGFlags.bits.SLAVE_ONLINE ==TRUE)
 698   2                              {bXXGFlags.bits.SLAVE_REMOVED=TRUE;
 699   3                              bXXGFlags.bits.SLAVE_ONLINE =FALSE;}
 700   2                         }
 701   1              else    {
 702   2                      MCU_LED0=0;
 703   2                                      //bXXGFlags.bits.SLAVE_IS_ATTACHED = TRUE;
 704   2                         if(bXXGFlags.bits.SLAVE_ONLINE == FALSE)
 705   2                              {bXXGFlags.bits.SLAVE_FOUND=TRUE;
 706   3                              bXXGFlags.bits.SLAVE_ONLINE =TRUE;}
 707   2                         }
 708   1              //bXXGFlags.bits.SLAVE_FOUND;
 709   1              
 710   1              //bXXGFlags.bits.SLAVE_REMOVED=0;
 711   1              SL811Write(IntStatus,INT_CLEAR);
 712   1              SL811Write(IntStatus,INSERT_REMOVE);
 713   1              
 714   1              /////// for test only /////////////////////
 715   1      //      intr=SWM0;
 716   1      //      intr&=0x1;
 717   1      //      if(intr!=last_key)
 718   1      //              {
 719   1      //              if(intr==0)
 720   1      //                      {
 721   1      //                      pBuf=(unsigned char *)&UartCmdBlock;
 722   1      //                      for(i=0;i<64;i++)
 723   1      //                              *(pBuf+i)=*(cmd_test_createfile+i);
 724   1      //                      bXXGFlags.bits.bUartInDone=1;
 725   1      //                      last_key=0;
 726   1      //                      }
 727   1      //              else
 728   1      //                      last_key=1;
 729   1      //              }
 730   1              ////////////////////////////////////////////
 731   1      //      intr=SWM1;
 732   1      //      intr&=0x1;
 733   1      //      if(intr!=last_key)
 734   1      //              {
 735   1      //              if(intr==0)
 736   1      //                      {
C51 COMPILER V7.00  SL811                                                                  09/22/2005 17:57:50 PAGE 13  

 737   1      //                      pBuf=(unsigned char *)&UartCmdBlock;
 738   1      //                      for(i=0;i<64;i++)
 739   1      //                              *(pBuf+i)=*(cmd_test_writefile+i);
 740   1      //                      wpBuf=(unsigned int *)UARTBUF;
 741   1      //                      len=SwapINT16(UartCmdBlock.CmdBlock.Cmd_WriteFile.writeLength)/2;
 742   1      //                      for(i=0;i<len;i++)
 743   1      //                              *(wpBuf+i)=i;
 744   1      //                      bXXGFlags.bits.bUartInDone=1;
 745   1      //                      last_key=0;
 746   1      //                      }
 747   1      //              else
 748   1      //                      last_key=1;
 749   1      //              }
 750   1              
 751   1              /////////////////////////////////////////////           
 752   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   2264    ----
   CONSTANT SIZE    =     18    ----
   XDATA SIZE       =   2068      26
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =     45    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -