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

📄 minhost.lst

📁 完整的usb_host_device源代码直接在keil下编译
💻 LST
字号:
C51 COMPILER V7.50   MINHOST                                                               10/27/2005 20:38:40 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE MINHOST
OBJECT MODULE PLACED IN minhost.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE minhost.c MODDP2 DEBUG OBJECTEXTEND

line level    source

   1          // minhost.c
   2          #define BYTE    unsigned char
   3          // SL811 Registers
   4          #define CTL                     0x00    // write this register to kick off a transfer
   5          #define BUFADR          0x01    // start of internal data buffer
   6          #define BUFLEN          0x02    // length of internal buffer
   7          #define PID_EP          0x03    // name when written--PID and Endpoint for next xfr
   8          #define PKTSTAT         0x03    // name when read--status of last transfer
   9          #define FNADDR          0x04    // name when written--USB function address
  10          #define CTL1            0x05    // more control stuff
  11          #define INTSTATUS       0x0D    // Interrupt request status bits. We use DONE and SOF.
  12          #define SOFCT_L         0x0E    // SOF (EOP) time constant low byte
  13          #define SOFCT_H         0x0F    // name when written--EOP time constant high byte
  14          
  15          #define IN_PID          0x90    // PID (Packet ID) constants
  16          #define SETUP_PID       0xD0    // for the 'set address' request
  17          #define SOF_PID         0x05
  18          // constants for 811 CTL1 register
  19          #define USB_RESET       0x08    // SIERES=1
  20          #define USB_OPERATE     0x21    // Low Speed=1(b5),SOF(EOP)EN=1(b0)
  21          // use an 8051 port bit to sync transfers on oscilloscope
  22          #define SCOPE_LO        OUTA=0x00;
  23          #define SCOPE_HI        OUTA=0x01;
  24          // EZ-USB registers
  25          xdata   BYTE    SL811_ADDR      _at_    0x4000;
  26          xdata   BYTE    SL811_DATA      _at_    0x4001;
  27          xdata   BYTE    PORTACFG        _at_    0x7F93;
  28          xdata   BYTE    OUTB            _at_    0x7F97;         
  29          xdata   BYTE    OEB                     _at_    0x7F9D;
  30          xdata   BYTE    PORTCCFG        _at_    0x7F95;
  31          xdata   BYTE    OEA                     _at_    0x7F9C;
  32          xdata   BYTE    OUTA            _at_    0x7F96;
  33          xdata   BYTE    I2CS            _at_    0x7FA5;
  34          xdata   BYTE    I2DAT           _at_    0x7FA6;
  35          // lookup table for EZ-USB Dev Board 7-segment readout
  36          char digit[]={0x7f,0xad,0x9c,0xbf,0xa3,0x86,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x98,0xc0,0xa1};
  37          
  38          // function prototypes
  39          void wr811(BYTE address, BYTE value);
  40          BYTE rd811(BYTE address);
  41          void delay(tc);
  42          BYTE go(BYTE cmd);                              // arm an 811 transfer, wait for completion, return status
  43          void waitframes(BYTE num);              // wait this many 1 msec frames
  44          void display_hex (char val);
  45          
  46          //***************************************************************************   
  47          void main(void)
  48          {
  49   1      BYTE            result;
  50   1      // set up the EZ-USB chip to talk to the 811 chip and provide scope trigger
  51   1      PORTCCFG        = 0xC0;                         // enable RD, WR pins
  52   1      OEB                     = 0x03;                         // PB0 is SL811 RESET, PB1 is Host/Slave pin)
  53   1      OEA                     = 0x01;                         // PA0 is scope trigger
  54   1      SCOPE_LO;                                               // initialize scope trigger
  55   1      // Reset the SL811H chip
C51 COMPILER V7.50   MINHOST                                                               10/27/2005 20:38:40 PAGE 2   

  56   1      OUTB            = 0x00;                         // PB1=0 means we're the host
  57   1      delay(1000);
  58   1      OUTB            = 0x01;                         // remove reset, keep PB1 LOW for SLAVE         
  59   1      
  60   1      // SL811 initialization
  61   1      wr811(BUFADR,0x10);                     // start of SETUP/IN internal data buffer
  62   1      wr811(BUFLEN,0x08);                     // reserve 8 bytes
  63   1      
  64   1      // (1) Reset the USB device. This makes it listen to address 0.
  65   1      wr811(CTL1,USB_RESET);                  // Speed=1(L), JKFORCE=1, SOFEN=1
  66   1      delay(10000);                                   // about 18 milliseconds
  67   1      wr811(CTL1,USB_OPERATE);
  68   1      
  69   1      // Enable sending 1 msec EOP's (the low-speed version of SOF's)
  70   1      wr811(SOFCT_L, 0xE0);                   // Set the SOF generator time constant
  71   1      wr811(SOFCT_H, 0x2E | 0xC0);    // 1 msec SOF rate, b7=HOST, b6=POLSWAP
  72   1      
  73   1      // (2) Issue a SET_ADDRESS USB request, setting the peripheral address to 1
  74   1      // From the USB spec, Chapter 9, here is the data for a "SET_ADDRESS" request:
  75   1      // Note: every SL811_DATA load increments an internal SL811 address pointer
  76   1      SL811_ADDR      =       0x10;   // next SL811_DATA byte goes here
  77   1      SL811_DATA      =       0x00;   // bmRequestType (h->d,std request,device is recipient)
  78   1      SL811_DATA      =       0x05;   // bRequest (SET_ADDRESS)
  79   1      SL811_DATA      =       0x01;   // wValueL  (device address)--we're setting it to ONE
  80   1      SL811_DATA      =       0x00;   // wValueH  (zero)
  81   1      SL811_DATA      =       0x00;   // wIndexL  (zero)
  82   1      SL811_DATA      =       0x00;   // wIndexH  (zero)
  83   1      SL811_DATA      =       0x00;   // wLengthL (zero)
  84   1      SL811_DATA      =       0x00;   // wLengthH (zero)
  85   1      
  86   1      wr811(FNADDR,0x00);                                     // USB address zero
  87   1      wr811(PID_EP,SETUP_PID | 0x00);         // SETUP PID, EP0
  88   1      result=go(0x07);                                        // DIREC=1(out), ENAB=1, ARM=1
  89   1      
  90   1      // STATUS stage is a no-data IN to EP0
  91   1      wr811(PID_EP,IN_PID | 0x00);            // IN PID, EP0
  92   1      result=go(0x03);                                        // Don't sync to SOF, DIREC=0(in), ENAB, ARM
  93   1      
  94   1      // (3) Send a CONTROL transfer to select configuration #1. Until we do this
  95   1      //         the device is in an "unconfigured" state and probably won't send data.
  96   1      // Again, from USB spec Chapter 9:
  97   1      SL811_ADDR      =       0x10;   // reset pointer to beginning of internal buffer.
  98   1      SL811_DATA      =       0x00;   // bmRequestType (h->d,std request,device is recipient)
  99   1      SL811_DATA      =       0x09;   // bRequest (SET_CONFIGURATION)
 100   1      SL811_DATA      =       0x01;   // wValueL  (configuration = 1)
 101   1      SL811_DATA      =       0x00;   // wValueH  (zero)
 102   1      SL811_DATA      =       0x00;   // wIndexL  (zero)
 103   1      SL811_DATA      =       0x00;   // wIndexH  (zero)
 104   1      SL811_DATA      =       0x00;   // wLengthL (zero)
 105   1      SL811_DATA      =       0x00;   // wLengthH (zero)
 106   1      
 107   1      wr811(FNADDR,0x01);                                             // now talking to USB device at address 1
 108   1      wr811(PID_EP,SETUP_PID | 0x00);                 // OR in the endpoint (zero)
 109   1      result=go(0x07);                                                // DIREC=1(out), ENAB=1, ARM=1
 110   1      
 111   1      // STATUS stage is a no-data IN to EP0
 112   1      
 113   1      wr811(PID_EP,IN_PID | 0x00);                    // IN PID, EP0
 114   1      result=go(0x03);                                                // DIREC=0(in), ENAB=1, ARM=1
 115   1      
 116   1      // (4) Send constant IN requests to Addr 1, EP1
 117   1      
C51 COMPILER V7.50   MINHOST                                                               10/27/2005 20:38:40 PAGE 3   

 118   1      wr811(PID_EP,IN_PID | 0x01);    // set up for IN PIDS to endpoint 1
 119   1      while(1)
 120   1              {
 121   2              SL811_ADDR      =       0x10;           // reset pointer to beginning of internal bufferf
 122   2              waitframes(4);                          // send the IN requests every n milliseconds            
 123   2              result=go(0x03);                        // DIREC=0(in), ENAB=1, ARM=1
 124   2                      if (result & 0x01)              // look only for ACK
 125   2                              display_hex(rd811(0x12));       // KB value is in third byte of 3-byte packet                   
 126   2              } 
 127   1      } // end main
 128          
 129          // *************************************************************************************
 130          BYTE go(BYTE cmd)                       // Launch an 811 operation. 
 131          {
 132   1              SCOPE_HI;
 133   1              wr811(INTSTATUS,0x01);  // clear the DONE bit
 134   1              wr811(CTL,cmd);                 // start the operation
 135   1              delay(100);     
 136   1              while(rd811(INTSTATUS) & 0x01 == 0){}   // spin while "done" bit is low
 137   1              SCOPE_LO;
 138   1              return rd811(PKTSTAT);  // return the status of this transfer
 139   1      }
 140          
 141          void waitframes(BYTE num)
 142          {
 143   1      int j;
 144   1      BYTE result;
 145   1      j=0;
 146   1              while (j < num)
 147   1              {
 148   2                      wr811(INTSTATUS,0xFF);                  // clear the int request flags
 149   2                      while (1)
 150   2                      {
 151   3                      result = (rd811(INTSTATUS));    // hang while SOF flag low
 152   3                      result &= 0x10;                                 // SOF flag is bit 4
 153   3                      if (result == 0x10) break;
 154   3                      }
 155   2              j++;
 156   2              }
 157   1      delay(100);
 158   1      }
 159          
 160          void wr811(BYTE address, BYTE value)
 161          {
 162   1              SL811_ADDR = address;
 163   1              SL811_DATA = value;
 164   1      }
 165          BYTE rd811(BYTE address)
 166          {
 167   1              SL811_ADDR = address;
 168   1              return SL811_DATA;
 169   1      }
 170          void delay(tc)
 171          {
 172   1      int     timer;
 173   1      timer = tc;
 174   1      while(timer--){}
 175   1      }
 176          
 177          void display_hex (char val)             // display one hex digit (over i2c bus)
 178          {
 179   1              if (val==00) val=0xFF;          // blank display for key-up code (00)
C51 COMPILER V7.50   MINHOST                                                               10/27/2005 20:38:40 PAGE 4   

 180   1              else if (val==0x2A) val=0x7F;   // backspace key is 0x2A (show decimal point)
 181   1              else val = digit[val-0x53];     // all other keycodes fit into table values 0x53-0x63
 182   1              while (I2CS & 0x40);            // wait for STOP bit LOW--last operation complete
 183   1              I2CS = 0x80;                            // set the START bit
 184   1              I2DAT = 0x42;                           // IO expander address=42, LSB=0 for write
 185   1              while ((I2CS & 0x01)!=0x01);// wait for DONE=1 (i2c transmit complete)
 186   1              I2DAT = val;                            // send the data byte
 187   1              while ((I2CS & 0x01)!=0x01);// wait for DONE=1
 188   1              I2CS = 0x40;                            // set the STOP bit
 189   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    417    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     17       5
   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 + -