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

📄 main.lst

📁 用89C51SND1C实现的USB存储器的代码,包括USB通信和FLASH的读写操作.
💻 LST
📖 第 1 页 / 共 2 页
字号:
 137          {
 138   1      
 139   1      //      printu("Set_Configuration\n");
 140   1              if(wValue == 0) {
 141   2              /* put device in unconfigured state */
 142   2                       /* Disable all endpoints but EPP0. *///init_unconfig
 143   2      
 144   2                      UEPNUM=0x00;//Ep0 as control Endpoint
 145   2                      UEPCONX=0x80;
 146   2              
 147   2                      UEPNUM=0x01;//Ep1 as Bulk-in Endpoint
 148   2                      UEPCONX=0x86;
 149   2              
 150   2                      UEPNUM=0x02;//Ep2 as Bulk-out Endpoint
 151   2                      UEPCONX=0x82;
 152   2      
 153   2      //              WriteEp(0,&Device_Descriptor[4],2);
 154   2                      USBCON&=(~CONFG);
 155   2                      WriteEp(0,0,0);//状态传送阶段之前完成指定操作
 156   2      
 157   2              }
 158   1              else if(wValue == 1) {
 159   2              /* Configure device */
 160   2                      /* Enable generic/iso endpoints. init_config*/
 161   2      
 162   2                      UEPNUM=0x00;//Ep0 as control Endpoint
 163   2                      UEPCONX=0x80;
 164   2              
 165   2                      UEPNUM=0x01;//Ep1 as Bulk-in Endpoint
 166   2                      UEPCONX=0x86;
 167   2              
 168   2                      UEPNUM=0x02;//Ep2 as Bulk-out Endpoint
 169   2                      UEPCONX=0x82;
 170   2      
 171   2      
 172   2      //              WriteEp(0,&Device_Descriptor[4],2);
 173   2                      USBCON|=CONFG;
 174   2                      WriteEp(0,0,0);//状态传送阶段之前完成指定操作
 175   2      //              printuf("After Config,USBADDR:%x  ",USBADDR);
 176   2      //              printuf("USBCON:%x \n",USBCON);
 177   2      
 178   2              }
C51 COMPILER V6.23a  MAIN                                                                  06/02/2003 09:51:30 PAGE 4   

 179   1      //      printu("Set_Configuration ");
 180   1      }
 181          void Get_Interface()
 182          {
 183   1              printu("Get_Interface\n");
 184   1      }
 185          void Set_Interface()
 186          {
 187   1              WriteEp(0,0,0);
 188   1              printu("Set_Interface\n");
 189   1      }
 190          void Reserved()
 191          {}
 192          
 193          void Ep0Int()
 194          {
 195   1              unsigned char i,j;
 196   1              unsigned char ControlData[32]={0,};
 197   1      //      printu("\nEp0 Interrrupted!");
 198   1              i=ReadEp(0,ControlData);//读端点0数据
 199   1      //    for(j=0;j<i;j++) printuf("%x ",ControlData[j]);
 200   1              j=ControlData[0]&0x60;  //判断是否是USB标准请求
 201   1              if((j==0)&&i){                  //如果端点0数据长度非零且为标准请求
 202   2                      switch(ControlData[1]){ //分支处理
 203   3                                      case get_status                 :       Get_Status();break;
 204   3                                      case clear_feature              :       Clear_Feature();break;
 205   3              
 206   3                                      case set_feature                :       Set_Feature();break;
 207   3              
 208   3                                      case set_address                :       Set_Address(ControlData[2]);break;
 209   3                                      case get_descriptor             :       Get_Descriptor(ControlData[3],ControlData[6]);break;
 210   3              
 211   3                                      case get_configuration  :       Get_Configuration();break;
 212   3                                      case set_configuration  :       Set_Configuration(ControlData[2]);break;
 213   3                                      case get_interface              :       Get_Interface();break;
 214   3                                      case set_interface              :       Set_Interface();break;
 215   3                                      default                                 :       Reserved();break;
 216   3                              }
 217   2              }
 218   1              else if(ControlData[0]==0xa1){//非标准USB请求
 219   2                              WriteEp(0,0,0);
 220   2                      }
 221   1      }
 222          
 223          void main_txdone()
 224          {
 225   1      //      printu("Bulk_In Ep Intterupt\n");
 226   1              UEPSTAX&=(~(TXCMP));//clear TXCMP
 227   1              switch(bulk_state){
 228   2                      case BULK_DATA_TRANS:
 229   2                              TransDataGoOn();
 230   2                              break;
 231   2                      case BULK_DATA_END:
 232   2                              TransmitCSW();
 233   2                              break;
 234   2                      case BULK_REQEST_TRANS:
 235   2                              TransRequestGoOn();
 236   2                              break;
 237   2                      case BULK_CSW_END:
 238   2                              break;
 239   2                      default:        return;
 240   2                      }
C51 COMPILER V6.23a  MAIN                                                                  06/02/2003 09:51:30 PAGE 5   

 241   1      }
 242          void main_rxdone()
 243          {
 244   1              unsigned char i,j;
 245   1      //      printu("Bulk_Out Ep Intterupt\n");
 246   1              i=ReadEp(2,Bulk_Out_Buf);
 247   1      //    for(j=0;j<i;j++) printuf("%x ",Bulk_Out_Buf[j]);
 248   1              if((bulk_state != BULK_DATA_RECIEVE) &&(Bulk_Out_Buf[0] == 0x55)) InterpretCBW();
 249   1              else RecieveData();     
 250   1      }
*** WARNING C280 IN LINE 244 OF MAIN.C: 'j': unreferenced local variable
 251          void main()
 252          {
 253   1      //      printu("Test Ep0 Intterupt\n");
 254   1      //      需要格式化时使用以下两行,格式化完成后再将以下两行注释掉
 255   1      //  Format_Fat16Media();
 256   1      //      while(1);
 257   1              AtmelUSBInit(0,2,0);
 258   1              EpEnable();
 259   1              while(1){
 260   2                      if(UEPINT&EP0INT) Ep0Int();
 261   2                      if(UEPINT&EP1INT) main_txdone();
 262   2                      if(UEPINT&EP2INT) main_rxdone();
 263   2                      UEPINT=0;
 264   2              }
 265   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    664    ----
   CONSTANT SIZE    =    171    ----
   XDATA SIZE       =   ----      44
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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