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

📄 usb.lst

📁 关于 at89c51snd1c 的海量存储mass storge的基于keil c的源代码
💻 LST
📖 第 1 页 / 共 4 页
字号:
C51 COMPILER V7.50   USB                                                                   03/19/2006 13:41:49 PAGE 1   


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

line level    source

   1          #include "REGSND1.H"
   2          #include "USBDEF.H"
   3          #include "UART.h"
   4          
   5          //时钟参数宏
   6          #define         Rdiv            11
   7          //USB寄存器设置相关的宏定义
   8          #define         PLLRES          (0x1<<3)        //PLLCON
   9          #define         PLLEN           (0x1<<1)
  10          #define         USBE            (0x1<<7)        //USBCON
  11          #define         EEOFINT         (0x1<<4)
  12          #define         FEN                     (0x1<<7)
  13          #define         FADDEN          (0x1)
  14          #define         CONFG           (0x1<<1)
  15          #define         DIR                     (0x1<<7)                //UEPSTAX
  16          #define         RXOUTB1         (0x1<<6)
  17          #define         STALLRQ         (0x1<<5)
  18          #define         TXRDY           (0x1<<4)
  19          #define         STLCRC          (0x1<<3)
  20          #define         RXSETUP         (0x1<<2)
  21          #define         RXOUTB0         (0x1<<1)
  22          #define         TXCMP           (0x1<<0)
  23          
  24          //USB 请求的bRequert的含意宏
  25          #define get_status                      0x00            //取得状态
  26          #define clear_feature           0x01            //清除特性
  27          #define reserved                        0x02            //保留
  28          #define set_feature                     0x03            //设置特性
  29          
  30          #define set_address                     0x05            //设置地址
  31          #define get_descriptor          0x06            //取得描述符
  32          
  33          #define get_configuration       0x08            //取得配置
  34          #define set_configuration       0x09            //设置配置
  35          #define get_interface           0x0a            //取得接口
  36          #define set_interface           0x0b            //设置接口
  37          
  38          /**---------------------------------------------------------------------------------
  39          
  40          ----------------------------------------------------------------------------------**/
  41          
  42          void AtmelUSBInit()             //用于USB的PLL时钟20M晶振时如下设置
  43          {
  44   1              int data i;     
  45   1              PLLNDIV =       0x04;                     //设置PLL时钟
  46   1              PLLCON |=       (0x3&Rdiv)<<6;
  47   1              PLLRDIV =       (0x3ff&Rdiv)>>2;
  48   1              USBCLK=0;
  49   1              PLLCON&=(~PLLRES);                    //使能PLL
  50   1              PLLCON|=PLLEN;               
  51   1              USBCON&=(~USBE);                      //关闭USB并复位USB
  52   1              for(i=0;i<3000;i++);                  //等待PLL工作稳定
  53   1              USBCON|=USBE;                         //开启USB控制器
  54   1      
  55   1      }       
C51 COMPILER V7.50   USB                                                                   03/19/2006 13:41:49 PAGE 2   

  56          
  57          void EpEnable(void)                                       //初始化USB端点
  58          {
  59   1              UEPNUM=0x00;    UEPCONX=0x80;
  60   1              UEPNUM=0x01;    UEPCONX=0x86;
  61   1              UEPNUM=0x02;    UEPCONX=0x82;
  62   1              UEPRST=0x07;    UEPRST= 0x00;
  63   1              UEPIEN=0x07;    USBIEN|=EEOFINT;
  64   1              USBADDR=FEN;
  65   1      }
  66          
  67          unsigned char ReadEp(unsigned char EpNum,unsigned char *Data)   //读取端口数据
  68          {
  69   1              unsigned char data i=0;
  70   1              UEPNUM=EpNum;                                     //指端口号
  71   1              while(i<UBYCTLX)                          //读数据到缓冲//UBYCTX得到数据长度
  72   1              {
  73   2                      Data[i++]=UEPDATX;
  74   2              }       
  75   1              UEPSTAX&=~(RXOUTB0|RXOUTB1|RXSETUP);                                        //清除相关位
  76   1              return(i);
  77   1      }
  78          
  79          void WriteEp(unsigned char EpNum,unsigned char nLength,unsigned char *Data)     //写端口数据
  80          {
  81   1              unsigned char data i=0;
  82   1              UEPNUM=EpNum;                                                                                        //选择端口
  83   1              UEPSTAX|=DIR;                                                                                        //控制方向
  84   1              while(nLength--) UEPDATX=Data[i++];                              //写入FIFO
  85   1              UEPSTAX|=TXRDY;                                                                                      //开始发送
  86   1              while(!(UEPSTAX&TXCMP)) ;
  87   1              UEPSTAX&=(~(TXCMP));                                                                     //清除TXCMP
  88   1      }
  89          
  90          //-------------以下用于对端点进行处理
  91          
  92          void Set_Address(unsigned char EpNum)                            //设置USB地址1-127
  93          {
  94   1              WriteEp(0,0,0);                                                                                      //在Status阶段过后才能改变设备地址
  95   1              USBADDR|=EpNum;
  96   1              USBADDR|=FEN;                                                                                        //设置地址
  97   1              USBCON|=FADDEN;                                                                                      //地址使能
  98   1      }
  99          
 100          //设备描述符
 101          code unsigned char Device_Descriptor[18] = {
 102                                                                                   0x12,                     //0x12
 103                                                                                           0x01,             //DEVICE descriptor
 104                                                                                           0x10, 0x01,       //spec rev level (BCD) 1.0
 105                                                                                           0x0,              //device class
 106                                                                                           0x0,              //device subclass
 107                                                                                           0x0,              //device protocol
 108                                                                                           0x20,             //max packet size
 109                                                                                           0x05, 0x82,       //National's vendor ID
 110                                                                                           0x00, 0x11,       //National's product ID  
 111                                                                                           0x00, 0x00,       //National's revision ID  
 112                                                                                           0,                //index of manuf. string   
 113                                                                                           0,                //index of prod.  string  
 114                                                                                           0,                //index of ser. # string   
 115                                                                                           0x01              //number of configs.         
 116                                                                                  };
 117          //配置描述符
C51 COMPILER V7.50   USB                                                                   03/19/2006 13:41:49 PAGE 3   

 118          code unsigned char Configuration_Descriptor_All[32] = {
 119          
 120                                                                                      9,                 //Size of Descriptor in Bytes
 121                                                                                      2,                 //Configuration Descriptor (0x02)
 122                                                                                      0x20,              //Total length in bytes of data returned  LSB
 123                                                                                          0x00,              //MSB
 124                                                                                          1,                 //Number of Interfaces
 125                                                                                          1,                 //Value to use as an argument to select this configuration
 126                                                                                      0,                 //Index of String Descriptor describing this configuration
 127                                                                                          0x80,
 128                                                                                          0xfa,              //Maximum Power Consumption in 2mA units //recerive 500ma
 129                                                                                  
 130                                                                                      9,
 131                                                                                      4,
 132                                                                                      0,                 //the index of the interface descriptor Number of Interface
 133                                                                                      0,                 //Value used to select alternative setting
 134                                                                                          2,                 //EndPoint Number Used in this Descriptor
 135                                                                                          8,                 //Class Code (Assigned by USB Org)
 136                                                                                          6,                     //interface subclass1=RBC,2=SFF,3=QIC,4=UFI,5=SFF,6=SCSI
 137                                                                                          0x50,              //bulk 0nly Transport
 138                                                                                          0,                 //Index of String Descriptor Describing this interface
 139          
 140                                                                                                             //Bulk-in Endpoint
 141                                                                                           0x07,             //length of this desc.   
 142                                                                                           0x05,             //ENDPOINT descriptor TYPE
 143                                                                                           0x81,             //address (IN) Endpoint 4 84
 144                                                                                           0x02,             //attributes  (BULK)    
 145                                                                                           0x40, 0x00,       //max packet size (64)  
 146                                                                                           0x0,              //Does not apply to Bulk endpoints
 147                                                                  
 148                                                                                                             //Bulk-out Endpoint
 149                                                                                           0x07,             //length of this desc.   
 150                                                                                           0x05,             //ENDPOINT descriptor TYPE
 151                                                                                           0x02,             //address (OUT) Endpoint 5 05
 152                                                                                           0x02,             //attributes  (BULK)
 153                                                                                           0x40, 0x00,       //max packet size (64)
 154                                                                                           0x0               //Does not apply to Bulk endpoints
 155                                                                                          };

⌨️ 快捷键说明

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