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

📄 usb_disk.lst

📁 mp3c程序源码
💻 LST
📖 第 1 页 / 共 3 页
字号:
C51 COMPILER V7.50   USB_DISK                                                              11/18/2005 21:31:23 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 BROWSE

line level    source

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

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

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

 179          
 180          void Get_Descriptor(unsigned char DesType,unsigned char nLength)
 181          {
 182   1              if(DesType==0x01)
 183   1                      WriteEp(0,18,Device_Descriptor);
 184   1      
 185   1              if((DesType==0x02)&&(nLength==0x09))
 186   1                      WriteEp(0,9,Configuration_Descriptor_All);
 187   1      
 188   1              if((DesType==0x02)&&(nLength==0xff))
 189   1              {
 190   2                  WriteEp(0,32,Configuration_Descriptor_All);
 191   2                  WriteEp(0,2,&Device_Descriptor[4]);
 192   2              }
 193   1      
 194   1              if((DesType==0x02)&&(nLength==0x20)) 
 195   1                      WriteEp(0,32,Configuration_Descriptor_All);
 196   1      }
 197          
 198          void Set_Configuration(unsigned char wValue)
 199          {
 200   1        if(wValue == 0)
 201   1        {
 202   2                      UEPNUM=0x00;    UEPCONX=0x80;
 203   2                      UEPNUM=0x01;    UEPCONX=0x86;
 204   2                      UEPNUM=0x02;    UEPCONX=0x82;
 205   2                      USBCON&=(~CONFG);
 206   2                      WriteEp(0,0,0); 
 207   2        }
 208   1        else if(wValue == 1) 
 209   1        {

⌨️ 快捷键说明

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