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

📄 eeprom.lst

📁 c8051f310xmodembootloader.rar
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.16   EEPROM                                                                12/10/2009 11:17:10 PAGE 1   


C51 COMPILER V8.16, COMPILATION OF MODULE EEPROM
OBJECT MODULE PLACED IN eeprom.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE eeprom.c LARGE BROWSE INTVECTOR(0X1000) DEBUG OBJECTEXTEND

line level    source

   1          #include "global.h"
   2          
   3          #define WREN    6       //      0000 x110,write enable
   4          #define WRDI    4       //      0000 x100,write disable
   5          #define RDSR    5       //      0000 x101,read status register
   6          #define WRSR    1       //      0000 x001,write status register
   7          #define READ    3       //      0000 x011,read sequence
   8          #define WRITE   2       //      0000 x010,write sequence
   9          
  10          
  11          
  12          //extern unsigned char xdata combuf[32];
  13          unsigned char code defdata[32]={0xaa,
  14                                          0x55,                                                                             
  15                                                                          0x20,                                             //基站号
  16                                                                          0x00,                         //cmd
  17                                                                          0x00,0x00,0x02,0x01,              //id
  18                                                                          0x00,0x00,0x00,0x03,0x02,0x01,//tag
  19                                                                          0x00,0x03,0x03,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//选型    
  20                                                                          0x00,0x00,0x00,0x00,0x00, //none
  21                                                                          0xdb,0x6b                                     //crc
  22                                                                     }; //默认参数表
  23          
  24          /***************************************************************************************
  25          **函数功能:AT25128
  26          **入参:        无
  27          **返回值:      无
  28          **作者:        jerkoh
  29          **日期:        2009-07-02
  30          **说明:        SPI eeprom
  31          
  32          ***************************************************************************************/
  33            
  34          /*-------------------------------------------------------
  35                       SPI_WriteByte()
  36          
  37          Function:  Send a byte of data to the device using
  38                     SPI interface. 
  39          Input:     the data(one byte) want to send.
  40          Output:    None.
  41          NOTE:      Using SPI Mode 3/0
  42          --------------------------------------------------------*/
  43          void SPI_WriteByte(uchar spi_write_data)
  44          {
  45   1          uchar temp=0;
  46   1              uchar i=0;
  47   1          temp=spi_write_data;   
  48   1      
  49   1          for(i=0;i<8;i++)  //send 8 bits
  50   1          {
  51   2                      X_SCK=0;  
  52   2          
  53   2                  if(temp & 0x80)//MSB first          
  54   2                              X_SI=1;
  55   2                      else
C51 COMPILER V8.16   EEPROM                                                                12/10/2009 11:17:10 PAGE 2   

  56   2                              X_SI=0;
  57   2                       
  58   2                      temp=temp<<1;    
  59   2      
  60   2                  X_SCK=1;                            
  61   2          }
  62   1              
  63   1      
  64   1      }  
  65             
  66          
  67          
  68          /*-------------------------------------------------------
  69                       SPI_ReadByte()
  70          
  71          Function:  Read a byte of data from the device using
  72                     SPI interface. 
  73          Input:     None.
  74          Output:    The data(one byte) been read,as a return value.
  75          NOTE:      Using SPI Mode 3/0
  76          --------------------------------------------------------*/
  77          uchar SPI_ReadByte(void)
  78          {
  79   1              uchar temp=0;
  80   1              uchar i=0;
  81   1          bit bit_in;
  82   1      
  83   1          temp=0x00;//initialize the data output
  84   1         
  85   1          for(i=0;i<8;i++) 
  86   1              {
  87   2                      X_SCK=1;//Data is output on the SO line by the falling edge of SCK.  
  88   2                      temp=temp << 1;                         
  89   2              X_SCK=0;
  90   2              bit_in=X_SO;            
  91   2              if(bit_in) temp=temp | 0x01;            
  92   2              }
  93   1              return (temp);
  94   1      }
  95          
  96          
  97          
  98          /*---------------------------------------------------------
  99                       AT25_GetStatusReg()
 100          
 101          Function:  Read the Status Register of the AT25XXXA
 102          Input:     None.
 103          Output:    Content of the status register,as a return value.
 104          -----------------------------------------------------------*/
 105          uchar AT25_GetStatusReg(void)
 106          {
 107   1              uchar temp;
 108   1          
 109   1              X_CS=0;
 110   1      
 111   1              SPI_WriteByte(RDSR);
 112   1              temp=SPI_ReadByte();
 113   1      
 114   1              X_CS=1; 
 115   1              return temp;
 116   1      }
 117          
C51 COMPILER V8.16   EEPROM                                                                12/10/2009 11:17:10 PAGE 3   

 118          
 119          /*---------------------------------------------------------
 120                       AT25_IsReady()
 121          
 122          Function:  Return 0 if AT25XXXA is busy and 1 if ready.
 123          -----------------------------------------------------------*/
 124          bit AT25_IsReady(void)
 125          {
 126   1              
 127   1              if(0x01 & AT25_GetStatusReg()) return 0;
 128   1              else return 1;
 129   1      }
 130          
 131          
 132          
 133          /*---------------------------------------------------------
 134                       AT25_SetStatusReg()
 135          
 136          Function:  Set the Status Register of the AT25XXXA
 137          Input:     The Byte of the status register. NOTE: Only 
 138                             bit7(WPEN),bit3(BP1) and bit2(BP0) can be changed,
 139                             so this byte should in the form of: x000 xx00                
 140          Output:    None. 
 141          -----------------------------------------------------------*/
 142          void AT25_SetStatusReg(uchar status_data)
 143          {       
 144   1           uint j;
 145   1              /* wait when device is busy */
 146   1              //while(!AT25_IsReady());       //jerkoh
 147   1      
 148   1               for(j=0;j<60000;j++)
 149   1               {
 150   2                  if(AT25_IsReady()==1)
 151   2                      {
 152   3                        break;
 153   3                      }
 154   2               }
 155   1               if(j==60000)
 156   1               {
 157   2                  return;
 158   2               }
 159   1      
 160   1              /* make sure that the device is write enabled */
 161   1              X_CS=0;
 162   1              _nop_();
 163   1              SPI_WriteByte(WREN);
 164   1              X_CS=1;
 165   1              _nop_();
 166   1              _nop_();
 167   1      
 168   1              X_CS=0;
 169   1              _nop_();        
 170   1              SPI_WriteByte(WRSR);
 171   1              SPI_WriteByte(status_data & 0x8C);      
 172   1              X_CS=1; 
 173   1      }
 174          
 175          
 176          
 177          
 178          /*---------------------------------------------------------
 179                       AT25_ReadArray()
C51 COMPILER V8.16   EEPROM                                                                12/10/2009 11:17:10 PAGE 4   

 180          
 181          Function:  Read  data streams from AT25XXXA.
 182          Input:     address,num_of_byte,destination
 183          Output:    No return value.
 184          NOTE:      The function do not report error if the parameters
 185                             are wrong(eg.address>0x3000),it modify the parameters.
 186                             So be careful.       
 187          -----------------------------------------------------------*/
 188          void AT25_ReadArray(uint address,               //from this address;
 189                                                  uint num_of_byte,       //the number of bytes to read;
 190                                                  uchar* destination      //store the result.
 191                                                  )
 192          {       
 193   1              uint i=0;
 194   1              uint j=0;
 195   1      
 196   1              /* Filter the parameters */
 197   1              if(num_of_byte>32) num_of_byte=1;
 198   1              if(address>0x3fff) address=0;
 199   1              
 200   1              /* wait when device is busy */
 201   1              //while(!AT25_IsReady());       //jerkoh
 202   1      
 203   1               for(j=0;j<60000;j++)
 204   1               {
 205   2                  if(AT25_IsReady()==1)
 206   2                      {
 207   3                        break;
 208   3                      }
 209   2               }
 210   1               if(j==60000)
 211   1               {
 212   2                  return;
 213   2               }
 214   1      
 215   1              X_CS=0;//Enable the AT25XXXA.
 216   1              _nop_();
 217   1              
 218   1              SPI_WriteByte(READ);//op_code
 219   1              SPI_WriteByte((uchar)((address & 0x0F00)>>8));  //write address A11~A0
 220   1              SPI_WriteByte((uchar)(address & 0x00FF));               
 221   1              
 222   1      
 223   1              for(i=0;i<num_of_byte;i++)
 224   1              {
 225   2                      *destination=SPI_ReadByte();
 226   2                      destination++;
 227   2              }
 228   1      
 229   1              X_CS=1;//Disable the AT25XXXA.
 230   1              
 231   1      }       
 232          
 233          
 234          
 235          /*---------------------------------------------------------
 236                       AT25_ReadByte()
 237          
 238          Function:  Read only one byte from the AT25XXXA,as a return 
 239                             value.
 240          -----------------------------------------------------------*/
 241          /*
C51 COMPILER V8.16   EEPROM                                                                12/10/2009 11:17:10 PAGE 5   

 242          uchar AT25_ReadByte(uint address)
 243          {
 244                  uchar temp[1];
 245          
 246                  AT25_ReadArray(address,1,&temp);
 247                  return temp[0]; 
 248          }
 249          */
 250          
 251          
 252          /*---------------------------------------------------------
 253                       AT25_WritePage()
 254          
 255          Function:  Write data(<=32 bytes) to the AT25XXXA.
 256          Input:     address,num_of_byte,source
 257          Output:    No return value.
 258          NOTE:      The function do not report error if the parameters
 259                             are wrong(eg.address>0x3fff),it modify the parameters.
 260                             So be careful.       
 261          -----------------------------------------------------------*/
 262          void AT25_WritePage(uint address,               //from this address;
 263                                                  uchar num_of_byte,      //the number(<32) of bytes to write;
 264                                                  uchar* source           //data to write.

⌨️ 快捷键说明

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