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

📄 usb.lst

📁 ATMEL AT89C51SND1 IDE TO USB READER
💻 LST
📖 第 1 页 / 共 4 页
字号:
 236   1              {
C51 COMPILER V7.50   USB                                                                   11/03/2008 13:09:02 PAGE 5   

 237   2      
 238   2                      Usb_sel_ep(0);                
 239   2                      if (Usb_setup_packet_receive())
 240   2                      {
 241   3      
 242   3                              usb_do_enumeration();
 243   3                      }
 244   2              }
 245   1      }
 246          
 247          /**************************************************************************
 248          *                                                                                                         
             -                        
 249          *  Function Name:usb_do_enumeration                                                                       
             -        
 250          *                                                                                                         
             -                 
 251          *  Descriptions:                                                       
 252          *                                                                        
 253          *  Arguments:                                                           
 254          *                                                                       
 255          *  Returns: None                                                         
 256          *                                          
 257          **************************************************************************/
 258          void usb_do_enumeration (void)
 259          { 
 260   1      
 261   1              Usb_sel_ep(0x00);
 262   1              UsbCtrlCmd.bmRequestType = UEPDATX;
 263   1              UsbCtrlCmd.bRequest =  UEPDATX;
 264   1              UsbCtrlCmd.wValue = UEPDATX;
 265   1              UsbCtrlCmd.wValue |= UEPDATX<<8;
 266   1              UsbCtrlCmd.wIndex  =UEPDATX;
 267   1              UsbCtrlCmd.wIndex |=UEPDATX<<8;
 268   1              UsbCtrlCmd.wLength = UEPDATX;
 269   1              UsbCtrlCmd.wLength |= UEPDATX<<8;
 270   1      
 271   1      #if 0
                      printf("UsbCtrlCmd.bmRequestType = %x\n",UsbCtrlCmd.bmRequestType);
                      printf("UsbCtrlCmd.bRequest=%x\n",UsbCtrlCmd.bRequest);
                      printf("UsbCtrlCmd.wValue=%x\n",UsbCtrlCmd.wValue);
                      printf("UsbCtrlCmd.wIndex=%x\n",UsbCtrlCmd.wIndex);
                      printf("UsbCtrlCmd.wLength=%x\n",UsbCtrlCmd.wLength);
              #endif
 278   1      
 279   1              if((UsbCtrlCmd.bmRequestType&0x20) == 0x00){
 280   2      
 281   2                      usb_standard_request();
 282   2      
 283   2              }
 284   1              else if((UsbCtrlCmd.bmRequestType&0x20) == 0x20){ 
 285   2                      usb_class_request();
 286   2      
 287   2              }
 288   1      }
 289          
 290          
 291          
 292          /**************************************************************************
 293          *                                                                                                         
             -                        
 294          *  Function Name:usb_standard_request                                                                     
C51 COMPILER V7.50   USB                                                                   11/03/2008 13:09:02 PAGE 6   

             -          
 295          *                                                                                                         
             -                 
 296          *  Descriptions:                                                       
 297          *                                                                        
 298          *  Arguments:                                                           
 299          *                                                                       
 300          *  Returns: None                                                         
 301          *                                          
 302          **************************************************************************/
 303          void usb_standard_request(void)
 304          { 
 305   1      
 306   1              switch (UsbCtrlCmd.bRequest)                 
 307   1              {
 308   2      
 309   2              case USB_GET_DESCRIPTOR:
 310   2      
 311   2                      usb_GetDescriptor();
 312   2                      break;
 313   2      
 314   2              case USB_GET_CONFIGURATION:
 315   2      
 316   2                      usb_get_configuration();
 317   2                      break;
 318   2      
 319   2              case USB_SET_ADDRESS:
 320   2                      usb_set_address();
 321   2                      break;
 322   2      
 323   2              case USB_SET_CONFIGURATION:
 324   2                      usb_set_configuration();
 325   2                      break;
 326   2      
 327   2              case USB_CLEAR_FEATURE:
 328   2                      usb_clear_feature();
 329   2                      break;
 330   2      
 331   2              case USB_SET_FEATURE:
 332   2                      usb_set_feature();
 333   2                      break;
 334   2      
 335   2              case USB_GET_STATUS:
 336   2                      usb_get_status();
 337   2                      break;
 338   2      
 339   2      
 340   2              default:          
 341   2                      break;
 342   2              }
 343   1      
 344   1      }
 345          
 346          /**************************************************************************
 347          *                                                                                                         
             -                        
 348          *  Function Name:usb_class_request                                                                        
             -       
 349          *                                                                                                         
             -                 
 350          *  Descriptions:                                                       
 351          *                                                                        
C51 COMPILER V7.50   USB                                                                   11/03/2008 13:09:02 PAGE 7   

 352          *  Arguments:                                                           
 353          *                                                                       
 354          *  Returns: None                                                         
 355          *                                          
 356          **************************************************************************/
 357          void usb_class_request(void)
 358          { 
 359   1      
 360   1      
 361   1              switch (UsbCtrlCmd.bRequest)                 
 362   1              {
 363   2      
 364   2              case HID_SET_IDLE:
 365   2                      hid_set_idle();
 366   2                      break;
 367   2              case USB_GET_MAX_LUN:
 368   2                      printf("USB_GET_MAX_LUN\n");
 369   2                      usb_get_max_lun();
 370   2                      break;
 371   2              default:
 372   2                      break;
 373   2              }
 374   1      
 375   1      
 376   1      }
 377          /**************************************************************************
 378          *                                                                                                         
             -                        
 379          *  Function Name:usb_GetDescriptor                                                                        
             -       
 380          *                                                                                                         
             -                 
 381          *  Descriptions:                                                       
 382          *                                                                        
 383          *  Arguments:                                                           
 384          *                                                                       
 385          *  Returns: None                                                         
 386          *                                          
 387          **************************************************************************/
 388          void   usb_GetDescriptor(void){
 389   1      
 390   1              UINT8 data_to_send;
 391   1              UINT8 des_type,i;
 392   1              UINT8 desc_ptr = 0; 
 393   1              UINT8 zeroflag = 0;
 394   1              UINT8 ret;
 395   1              Usb_set_DIR_bit();                           
 396   1      
 397   1              des_type = UsbCtrlCmd.wValue>>8;/*read  wValue msb*/
 398   1              switch (des_type)
 399   1              {
 400   2              case USB_DEVICE_DESC:
 401   2                      {
 402   3      
 403   3      
 404   3                              G_pucCtrlDataPointer = (UINT8 *)USB_DeviceDescriptor;
 405   3                              data_to_send = sizeof(USB_DeviceDescriptor);
 406   3                              break;
 407   3                      }
 408   2      
 409   2              case USB_CONFIGURATION_DESC:
 410   2                      {
C51 COMPILER V7.50   USB                                                                   11/03/2008 13:09:02 PAGE 8   

 411   3      
 412   3                              G_pucCtrlDataPointer = (UINT8 *)USB_ConfigurationDescriptor;
 413   3                              data_to_send = sizeof(USB_ConfigurationDescriptor);
 414   3                              break;
 415   3                      }
 416   2      
 417   2              case USB_STRING_DESC:
 418   2                      {
 419   3      
 420   3      
 421   3                              des_type = UsbCtrlCmd.wValue & 0xff;
 422   3                              switch (des_type)
 423   3                              {
 424   4                              case USB_LANG_ID:
 425   4                                      {
 426   5      
 427   5                                              G_pucCtrlDataPointer = (UINT8 *)USB_LanguageIdString;
 428   5                                              data_to_send = sizeof(USB_LanguageIdString);     
 429   5                                              break;
 430   5                                      }
 431   4      
 432   4                              case USB_MAN_INDEX:
 433   4                                      {
 434   5      
 435   5                                              G_pucCtrlDataPointer = (UINT8 *)USB_ManufacturerString;
 436   5                                              data_to_send = sizeof(USB_ManufacturerString);            
 437   5                                              break;
 438   5                                      }
 439   4                              case USB_PROD_INDEX:
 440   4                                      {
 441   5      
 442   5                                              G_pucCtrlDataPointer = (UINT8 *)USB_ProductString;
 443   5                                              data_to_send = sizeof(USB_ProductString);                 
 444   5                                              break;
 445   5                                      }
 446   4                              case USB_SN_INDEX:
 447   4                                      {
 448   5                                              G_pucCtrlDataPointer = (UINT8 *)USB_SerialNumberString;
 449   5                                              data_to_send = sizeof(USB_SerialNumberString);
 450   5                                              break;
 451   5                                      }
 452   4                              default:
 453   4                                      {
 454   5                                              return;
 455   5                                      }
 456   4                              }
 457   3                              break;
 458   3                      }
 459   2              default:
 460   2                      {
 461   3                              return;
 462   3                      }
 463   2              }
 464   1      
 465   1      
 466   1              if (UsbCtrlCmd.wLength > data_to_send)
 467   1              {
 468   2                      if ((data_to_send % 8) == 0)
 469   2                      {
 470   3                              zeroflag = TRUE;                          

⌨️ 快捷键说明

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