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

📄 at45db041b.lst

📁 C语言写的关于AT45DB041B存储芯片的51驱动程序,压缩包内还有AT45DB041B存储芯片的说明书,以及芯片和51单片机的连接方式.
💻 LST
字号:
C51 COMPILER V7.06   AT45DB041B                                                            08/28/2008 17:06:38 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE AT45DB041B
OBJECT MODULE PLACED IN AT45DB041b.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE AT45DB041b.c OMF2 BROWSE DEBUG

stmt level    source

   1          /****************************************************************************** 
   2          at45db041b特性:
   3                  正常操作电压为2.7~3.6V,实验中发现当电压超过4.25V后读出的状态字节为9A(正常  
   4                  的状态字节值为9D),并且读写数据均不准确,所以应当保证卡片的供电电压不超过  
   5                  4.25V。                                               
   6          SPI规范:
   7                  Data is always clocked into the device on the rising edge of SCK a- 
   8                  nd clocked out of the device on the falling edge of SCK.All instruction-
   9                  s,addresses and data are transferred with the most significant bit(MSB)  
  10                  first.                                              
  11                                                                                                  2005-06-02 
  12          /******************************************************************************/ 
  13          #include "reg51.h"
  14          #include "at45db041b.h"
  15          
  16          sbit SPI_CS  =  P2^0; 
  17          sbit SPI_SCK =  P2^2; 
  18          sbit SPI_SO  =  P2^3; 
  19          sbit SPI_SI  =  P2^4; 
  20          
  21          unsigned char SPI_HostReadByte(void) { 
  22   1              unsigned char i, rByte = 0; 
  23   1              for(i = 0; i < 8; i++){ 
  24   2              SPI_SCK = 0; 
  25   2              SPI_SCK = 1; 
  26   2              rByte <<= 1; 
  27   2              rByte |= SPI_SO; 
  28   2              } 
  29   1              return rByte;   
  30   1      } 
  31          
  32          void SPI_HostWriteByte(unsigned char wByte) { 
  33   1              unsigned char i; 
  34   1              for(i = 0; i < 8; i++) { 
  35   2              if((wByte << i) & 0x80) {
  36   3                              SPI_SI = 1;
  37   3                      } 
  38   2              else { 
  39   3                              SPI_SI = 0;
  40   3                      } 
  41   2              SPI_SCK = 0; 
  42   2              SPI_SCK = 1; 
  43   2              }   
  44   1      } 
  45          
  46          /******************************************************************************
  47          描述:                                                
  48                  When the end of a buffer is reached.the device will continue reading back at
  49              the beginning of the buffer.
  50          参数:                                               
  51                  buffer  - 指定buffer ID-1、2                                  
  52                  BFA     - 指定BUFFER中的起始写入地址                          
  53                  pHeader - 指定存储数据的首地址                               
  54                  len     - 指定数据的长度                                  
  55          /******************************************************************************/ 
C51 COMPILER V7.06   AT45DB041B                                                            08/28/2008 17:06:38 PAGE 2   

  56          void AT45DB041B_BufferRead(UCHAR buffer, UINT BFA, UCHAR *pHeader, UINT len) {
  57   1              unsigned int i = 0; 
  58   1              while(i++ < 255) {
  59   2                      if(AT45DB041B_StatusRegisterRead() & 0x80) { 
  60   3                              break;
  61   3                      }
  62   2              } 
  63   1              SPI_CS = 0;   
  64   1              switch(buffer) { 
  65   2              case 1 : SPI_HostWriteByte(Read_Buffer1);//#define Write_Buffer1 0x84
  66   2                              break; 
  67   2              case 2 : SPI_HostWriteByte(Read_Buffer2);////#define Write_Buffer2 0x87
  68   2                              break; 
  69   2              }
  70   1              SPI_HostWriteByte(0x00);//the don't care 15bits of high eight bits
  71   1              SPI_HostWriteByte((unsigned char)(BFA >> 8));//the don't care 15bits of low seven bits and the BFA of hig
             -h one bit
  72   1              SPI_HostWriteByte((unsigned char)BFA);//the BFA of low eight bits
  73   1              SPI_HostWriteByte(0x00);//the eight don't care bits
  74   1              for(i = 0; i < len; i++) {
  75   2                      pHeader[i] = SPI_HostReadByte();
  76   2              } 
  77   1              SPI_CS = 1;
  78   1      }
  79          
  80          /******************************************************************************/ 
  81          /*Status Register Format:                                   */ 
  82          /*   ----------------------------------------------------------------------- */ 
  83          /* | bit7 | bit6 | bit5 | bit4 | bit3 | bit2 | bit1 | bit0 | */ 
  84          /* |--------|--------|--------|--------|--------|--------|--------|--------| */ 
  85          /* |RDY/BUSY| COMP |   0   |   1   |   1   |   1   |   X   |   X   | */ 
  86          /*   ----------------------------------------------------------------------- */ 
  87          /* bit7 - 忙标记,0为忙1为不忙。                               */ 
  88          /*       当Status Register的位0移出之后,接下来的时钟脉冲序列将使SPI器件继续*/ 
  89          /*       将最新的状态字节送出。                               */ 
  90          /* bit6 - 标记最近一次Main Memory Page和Buffer的比较结果,0相同,1不同。   */ 
  91          /* bit5                                               */ 
  92          /* bit4                                               */ 
  93          /* bit3                                               */ 
  94          /* bit2 - 这4位用来标记器件密度,对于AT45DB041B,这4位应该是0111,一共能标记 */ 
  95          /*       16种不同密度的器件。                               */ 
  96          /* bit1                                               */ 
  97          /* bit0 - 这2位暂时无效                                     */ 
  98          /******************************************************************************/ 
  99          unsigned char AT45DB041B_StatusRegisterRead(void) { 
 100   1              unsigned char status; 
 101   1              SPI_CS = 0;   
 102   1              SPI_HostWriteByte(Status_Register_Read);//#define Status_Register_Read 0xd7//写入读取AT45DB041B状态寄存
             -器命令'0xd7' 
 103   1              status = SPI_HostReadByte(); 
 104   1              SPI_CS = 1; 
 105   1              return status;   
 106   1      }
 107           
 108          /******************************************************************************
 109          描述:                                                
 110                  When the last bit in the main memory array has been read,the device will 
 111                  continue reading back at the beginning of the first page of memory.As w- 
 112                  ith crossing over page boundaries,no delays will be incurred when wrapp- 
 113                  ing around from the end of the array to the beginning of the array.    
 114          参数:                                               
 115                  PA     - 页地址,0~2047                                  
C51 COMPILER V7.06   AT45DB041B                                                            08/28/2008 17:06:38 PAGE 3   

 116                  BFA   - 指定BUFFER中的起始写入地址                          
 117                  pHeader - 指定数据的首地址                               
 118                  len   - 指定数据的长度                                  
 119          /******************************************************************************/ 
 120          void AT45DB041B_ContinuousArrayRead(UINT PA, UINT BFA, unsigned char *pHeader, UINT len) {     
 121   1              unsigned int i = 0;     
 122   1              while(i++ < 255) {//i++ < 255用来延时等待AT...空闲
 123   2                      if(AT45DB041B_StatusRegisterRead() & 0x80) {//读取状态寄存器最高位,判断是否为忙
 124   3                              break;//为1表示空闲则跳出
 125   3                      }
 126   2              } 
 127   1              SPI_CS = 0;   
 128   1              SPI_HostWriteByte(Continuous_Array_Read);//#define Continuous_Array_Read 0xe8//连续的数组读取   
 129   1              SPI_HostWriteByte((unsigned char)(PA >> 7));//此处代码很妙啊,PA >> 7则是发送PA的高4位以及最开始的4位无

⌨️ 快捷键说明

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