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

📄 main.lst

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

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

 241   2                              TransmitCSW();
 242   2                              break;
 243   2                      case BULK_REQEST_TRANS:
 244   2                              TransRequestGoOn();
 245   2                              break;
 246   2                      case BULK_CSW_END:
 247   2                              break;
 248   2                      default:        return;
 249   2                      }
 250   1      }
 251          void main_rxdone()
 252          {
 253   1              unsigned char i,j;
 254   1      //      printu("Bulk_Out Ep Intterupt\n");
 255   1              i=ReadEp(2,Bulk_Out_Buf);
 256   1      //    for(j=0;j<i;j++) printuf("%x ",Bulk_Out_Buf[j]);
 257   1              if((bulk_state != BULK_DATA_RECIEVE) &&(Bulk_Out_Buf[0] == 0x55)) InterpretCBW();
 258   1              else RecieveData();     
 259   1      }
*** WARNING C280 IN LINE 253 OF MAIN.C: 'j': unreferenced local variable
 260          void main()
 261          {
 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        =    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 + -