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

📄 main.lst

📁 用89C51SND1C实现的USB存储器的代码,包括USB通信和FLASH的读写操作.
💻 LST
📖 第 1 页 / 共 2 页
字号:
 128   1              if((DesType==0x02)&&(nLength==0x20)) {WriteEp(0,32,Configuration_Descriptor_All);}
 129   1      
 130   1      //              printu("Get_Descriptor\n");
 131   1      }
 132          void Get_Configuration()
 133          {
 134   1              printu("Get_Configuration\n");
 135   1      }
 136          void Set_Configuration(unsigned char wValue)
 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                                                                  11/27/2003 16:42:27 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      
 227   1      }
 228          void main_rxdone()
 229          {
 230   1              unsigned char i,j;
 231   1              printu("Bulk_Out Ep Intterupt\n");
 232   1              i=ReadEp(2,Bulk_Out_Buf);
 233   1          for(j=0;j<i;j++) printuf("%x ",Bulk_Out_Buf[j]);
 234   1              if((bulk_state != BULK_DATA_RECIEVE) &&(Bulk_Out_Buf[0] == 0x55)) InterpretCBW();
 235   1              else RecieveData();     
 236   1      }
 237          void main()
 238          {
 239   1              printu("Test Ep0 Intterupt\n");
 240   1              AtmelUSBInit(0,2,0);
C51 COMPILER V6.23a  MAIN                                                                  11/27/2003 16:42:27 PAGE 5   

 241   1              EpEnable();
 242   1              while(1){
 243   2                      if(UEPINT&EP0INT) Ep0Int();
 244   2                      if(UEPINT&EP1INT) main_txdone();
 245   2                      if(UEPINT&EP2INT) main_rxdone();
 246   2                      UEPINT=0;
 247   2              }
 248   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    763    ----
   CONSTANT SIZE    =    288    ----
   XDATA SIZE       =   ----      46
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   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 + -