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

📄 main.lst

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

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

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


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    673    ----
   CONSTANT SIZE    =    190    ----
   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 + -