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

📄 usb_disk.lst

📁 基于at89c51单片机的mp3 U盘原理实验代码
💻 LST
📖 第 1 页 / 共 3 页
字号:
C51 COMPILER V7.50   USB_DISK                                                              01/15/2006 18:40:26 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE USB_DISK
OBJECT MODULE PLACED IN USB_DISK.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE USB_DISK.C LARGE ROM(COMPACT) BROWSE

line level    source

   1          
   2          #include "AT89C51SND1_REG.H"
   3          #include "UDISK_DEF.H"
   4          
   5          extern void ReadFlash();         //Defined in FLASH_RW.C
   6          extern void WriteFlash();
   7          
   8          code unsigned char Device_Descriptor[18] = {
   9                                                   0x12,                     //0x12
  10                                                           0x01,             //DEVICE descriptor
  11                                                           0x10, 0x01,       //spec rev level (BCD) 1.0
  12                                                           0x0,              //device class
  13                                                           0x0,              //device subclass
  14                                                           0x0,              //device protocol
  15                                                           0x20,             //max packet size
  16                                                           0x05, 0x82,       //National's vendor ID
  17                                                           0x00, 0x11,       //National's product ID  
  18                                                           0x00, 0x00,       //National's revision ID  
  19                                                           0,                //index of manuf. string   
  20                                                           0,                //index of prod.  string  
  21                                                           0,                //index of ser. # string   
  22                                                           0x01              //number of configs.         
  23                                                          };
  24          
  25          code unsigned char Configuration_Descriptor_All[32] = {
  26          
  27                                              9,                 //Size of Descriptor in Bytes
  28                                                      2,                 //Configuration Descriptor (0x02)
  29                                                      0x20,              //Total length in bytes of data returned  LSB
  30                                                          0x00,              //MSB
  31                                                          1,                 //Number of Interfaces
  32                                                          1,                 //Value to use as an argument to select this configuration
  33                                                      0,                 //Index of String Descriptor describing this configuration
  34                                                          0x80,
  35                                                          0xfa,              //Maximum Power Consumption in 2mA units 
  36                                                      9,
  37                                                      4,
  38                                                      0,                 //the index of the interface descriptor Number of Interface
  39                                                      0,                 //Value used to select alternative setting
  40                                                          2,                 //EndPoint Number Used in this Descriptor
  41                                                          8,                 //Class Code (Assigned by USB Org)
  42                                                          6,                     //interface subclass1=RBC,2=SFF,3=QIC,4=UFI,5=SFF,6=SCSI
  43                                                          0x50,              //bulk 0nly Transport
  44                                                          0,                 //Index of String Descriptor Describing this interface
  45                                                                             //Bulk-in Endpoint
  46                                                          0x07,             //length of this desc.   
  47                                                          0x05,             //ENDPOINT descriptor TYPE
  48                                                          0x81,             //address (IN) Endpoint 4 84
  49                                                          0x02,             //attributes  (BULK)    
  50                                                          0x40, 0x00,       //max packet size (64)  
  51                                                          0x0,              //Does not apply to Bulk endpoints
  52                                                                            //Bulk-out Endpoint
  53                                                          0x07,             //length of this desc.   
  54                                                          0x05,             //ENDPOINT descriptor TYPE
  55                                                          0x02,             //address (OUT) Endpoint 5 05
C51 COMPILER V7.50   USB_DISK                                                              01/15/2006 18:40:26 PAGE 2   

  56                                                          0x02,             //attributes  (BULK)
  57                                                          0x40, 0x00,       //max packet size (64)
  58                                                          0x0               //Does not apply to Bulk endpoints
  59                                                  };
  60          
  61          
  62          code unsigned char B_InquiryData[] = {
  63                                                                  0x00,                          //Direct Access Device
  64                                                                  0x80,                          //RMB
  65                                                                  0x00,                          //ISO/ECMA/ANSI
  66                                                                  0x01,                          //Response Data Format
  67                                                                  0x1f,                          //Additional Length
  68                                                                  0x00,                          //Reserved
  69                                                                  0x00,                          //Reserved
  70                                                                  0x00,                          //Reserved 
  71                                                                  'J', 'M', 'B', 'I', 'E', ' ', ' ', ' ',        //Vendor Information
  72                                                                  'U', 'S', 'B', '-', 'M', 'P', '3', ' ', 'V', '3', '.', '0', ' ', ' ', ' ', ' ',//Product Identifica
             -tion
  73                                                                  0, 0, 0, 0                                         //Product Revision Level n.nn
  74                                                                  };                     
  75          
  76          //SCSI-Read_Format_capacities命令的返回数据      
  77          code unsigned char B_Read_Format_capacities[] = {0x00, 0x00, 0x00, 0x10,                //capacity list header
  78                                                                                  0x00, 0x00, 0x07, 0xf5, 0x01, 0x00, 0x02, 0x00, //capacity descriptor
  79                                                                              //Number of Blocks =2037,unformatted media,blocklength = 512Bytes
  80                                                                                  0x00, 0x00, 0x07, 0xfd, 0x00, 0x00, 0x02, 0x00  //Formattable Capacity Descriptors
  81                                                                                  };
  82          //SCSI-Read_Capacity命令的返回数据
  83          code unsigned char B_Read_Capacity[] = {
  84                                                                          0x00, 0x00, 0xfe, 0xa0,    //Last  Logical Block Address for 32MB 
  85                                                                          0x00, 0x00, 0x02, 0x00     //block length in bytes
  86                                                                          };
  87          //SCSI-Mode_Sense命令的返回数据                         
  88          code unsigned char B_Mode_Sense_ALL[] = {0x0b, 0x00,       //Mode Data Length
  89                                                                  0x00, 0x08, 0x00, 0x00,
  90                                                                  0x7d, 0, 0, 0, 0x02, 0x00
  91                                                                  };
  92          //SCSI-Mode_Sense命令的返回数据                 
  93          code unsigned char B_Mode_Sense_TPP[] = {0xf0, 0x00,       //Mode Data Length
  94                                                                  05, 00, 00, 00, 00, 0x0b, 00, 00, 00, 00, 0x24, 00, 00, 00, 00, 00
  95                                                                  };
  96          //SCSI-Mode_Sense命令的返回数据                 
  97          code unsigned char B_Mode_Sense_ZERO[] = {0x00, 0x06,      //Mode Data Length
  98                                                                  0x00,                          //Medium Type Code
  99                                                                  0,                             //write enabled
 100                                                                  0, 0, 0, 0                     //reserved       
 101                                      };
 102          
 103          
 104          unsigned char data bulk_CSW[]={0x55,0x53,0x42,0x53,     //bytes 4 dCSWSignature
 105                                                        0x00,0x00,0x00,0x00,          //bytes 4 dCSWTag
 106                                                        0x00,0x00,0x00,0x00,              //bytes 4 dDataResiduce
 107                                                        0x00};                            //bCSWStatus  00=good state.
 108          
 109          
 110          
 111          struct_CBW data bulk_CBW;
 112          
 113          
 114          
 115          void AtmelUSBInit()
 116          {
C51 COMPILER V7.50   USB_DISK                                                              01/15/2006 18:40:26 PAGE 3   

 117   1              int data i;     
 118   1              PLLNDIV =       0x04;
 119   1              PLLCON |=       (0x3&Rdiv)<<6;
 120   1              PLLRDIV =       (0x3ff&Rdiv)>>2;
 121   1              USBCLK=0;
 122   1              PLLCON&=(~PLLRES);
 123   1              PLLCON|=PLLEN;
 124   1              USBCON&=(~USBE);
 125   1              for(i=0;i<3000;i++);
 126   1              USBCON|=USBE;
 127   1      
 128   1      }       
 129          
 130          void EpEnable(void)
 131          {
 132   1              UEPNUM=0x00;    UEPCONX=0x80;
 133   1              UEPNUM=0x01;    UEPCONX=0x86;
 134   1              UEPNUM=0x02;    UEPCONX=0x82;
 135   1              UEPRST=0x07;    UEPRST= 0x00;
 136   1              UEPIEN=0x07;    USBIEN|=EEOFINT;
 137   1              USBADDR=FEN;
 138   1      }
 139          
 140          unsigned char ReadEp(unsigned char EpNum,unsigned char *Data)
 141          {
 142   1              unsigned char data i=0;
 143   1              UEPNUM=EpNum;
 144   1              while(i<UBYCTLX)
 145   1              {
 146   2                      Data[i++]=UEPDATX;
 147   2              }       
 148   1              UEPSTAX&=~(RXOUTB0|RXOUTB1|RXSETUP);
 149   1              return(i);
 150   1      }
 151          
 152          void WriteEp(unsigned char EpNum,unsigned char nLength,unsigned char *Data)
 153          {
 154   1              unsigned char data i=0;
 155   1              UEPNUM=EpNum;
 156   1              UEPSTAX|=DIR;
 157   1              while(nLength--) UEPDATX=Data[i++];     
 158   1              UEPSTAX|=TXRDY;
 159   1              while(!(UEPSTAX&TXCMP)) ;
 160   1              UEPSTAX&=(~(TXCMP));
 161   1      }
 162          
 163          
 164          
 165          void Set_Address(unsigned char EpNum)
 166          {
 167   1              WriteEp(0,0,0);
 168   1              USBADDR|=EpNum;
 169   1              USBADDR|=FEN;
 170   1              USBCON|=FADDEN;
 171   1      }
 172          
 173          
 174          void Get_Descriptor(unsigned char DesType,unsigned char nLength)

⌨️ 快捷键说明

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