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

📄 dataflash.lst

📁 实现ucos任务调度时保存LCD上的显示信息
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.02   DATAFLASH                                                             05/08/2008 13:16:17 PAGE 1   


C51 COMPILER V8.02, COMPILATION OF MODULE DATAFLASH
OBJECT MODULE PLACED IN DataFlash.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE dataflash\DataFlash.c LARGE BROWSE INCDIR(.\dataflash;.\lcd;.\task;.\uart;.
                    -\ucos;.\key) DEBUG OBJECTEXTEND PRINT(.\DataFlash.lst) OBJECT(DataFlash.obj)

line level    source

   1          /*
   2          ********************************************************************************
   3          *                                               C8051F340 DataFlash modular
   4          *
   5          *                                 Ambition Comm Tech Ltd.Cop
   6          *                                                  Jason.D.Proakis
   7          *
   8          * File Name                : DataFlash.c
   9          * File Description : C file of DataFlash modular AT45DB161D.
  10          * Create Date      : 04-11-2008
  11          * Version              : V1.00
  12          * Modified History :
  13          *                                       None
  14          *
  15          * All rights reserved.
  16          *
  17          * NOTE: This process is for device which page size is 512 bytes.
  18          ********************************************************************************
  19          */
  20          
  21          /*
  22          ********************************************************************************
  23          *                                                       HEADER FILE INCLUDE
  24          ********************************************************************************
  25          */
  26          #include <C8051F340.h>
  27          #include "DataFlash.h"
  28          
  29          /*
  30          ********************************************************************************
  31          *                                               SPI OPERATION MACRO DEFINITION
  32          ********************************************************************************
  33          */
  34          /* assert CS to begin a operation, CS setup time 5ns */
  35          #define start_SPI()                                     AT45_CS = 0
  36          
  37          /* deassert CS to end a operation, CS hold time 5ns */
  38          #define stop_SPI()                                      AT45_CS = 1
  39          
  40          /*
  41          ********************************************************************************
  42          *                                               INTERNAL FUNCTION DECLARATION
  43          ********************************************************************************
  44          */
  45          /* read buffer1 */
  46          static void rd_buf1(unsigned int addr,unsigned char * buf,unsigned int len);
  47          
  48          /* write buffer1 */
  49          static void wr_buf1(unsigned int addr,unsigned char * buf,unsigned int len);
  50          
  51          /* buffer1 to main memory page program with built-in erase */
  52          static void prog_main_pg_buf1_erase(unsigned int pg_addr);
  53          
  54          /* page erase */
C51 COMPILER V8.02   DATAFLASH                                                             05/08/2008 13:16:17 PAGE 2   

  55          static void erase_pg(unsigned int pg_addr);
  56          
  57          /* main memory page to buffer 1 transfer */
  58          static void get_main_pg_buf1(unsigned int pg_addr);
  59          
  60          /* internal function, read a byte from SPI use SPI mode0 */
  61          static unsigned char rd_byte(void);     
  62          
  63          /* internal function, write a byte to SPI use SPI mode0 */              
  64          static void wr_byte(unsigned char ch);
  65          
  66          /* wait until device is ready */                
  67          static void wait_rdy(void);
  68          
  69          /*
  70          ********************************************************************************
  71          *                                                         STATIC VARIABLES      
  72          ********************************************************************************
  73          */
  74          static unsigned int buf1_pg_num;
  75          static unsigned int buf2_pg_num;
  76          static unsigned char buf_op_flag;
  77          
  78          /*
  79          ********************************************************************************
  80          *                                               EXTERNAL INTERFACE FUNCTION 
  81          ********************************************************************************
  82          */
  83          /*
  84          ********************************************************************************
  85          * Function Name : DF_init 
  86          * Description   : initial SPI port used by dataflash.
  87          * Parameter             : none.
  88          * Return                : none.
  89          ********************************************************************************
  90          */
  91          void DF_init(void)
  92          {
  93   1              P2MDOUT |= 0x70;                                /* set CS,SI,SCK push-pull ouput                */
  94   1              P2MDOUT &= ~0x80;                               /* set SO open-drain output                     */
  95   1              P2 |= 0x80;                                             /* set SO input                                                 */
  96   1              
  97   1              AT45_CS = 1;                                    /* diselect AT45DB161                                   */
  98   1              AT45_SI = 1;
  99   1              AT45_SCK = 0;           
 100   1      }
 101          
 102          /*
 103          ********************************************************************************
 104          * Function Name : DF_rd 
 105          * Description   : Read data from dataflash.
 106          * Parameter             : addr, unsigned long type, dataflash address begin to read.
 107          *                   Range from 0 to 2^21 - 1.
 108          *                                 buf, unsigned char * type, header pointer to store data.
 109          *                                 len, unsigned int type, length of data want to read. 
 110          *                   Range from 0 to 65535.
 111          * Return                : none
 112          ********************************************************************************
 113          */
 114          void DF_rd(unsigned long addr,unsigned char * buf,unsigned int len)
 115          {
 116   1              start_SPI();
C51 COMPILER V8.02   DATAFLASH                                                             05/08/2008 13:16:17 PAGE 3   

 117   1              wr_byte(OP_CODE_RD_ARRAY);
 118   1              wr_byte((unsigned char)(addr >> 16));
 119   1              wr_byte((unsigned char)(addr >> 8));
 120   1              wr_byte((unsigned char)addr);
 121   1              wr_byte(0x00);                                  /* 1 dummy bytes is need                                */
 122   1              
 123   1              while(len--) *buf++ = rd_byte();
 124   1              
 125   1              stop_SPI();
 126   1      }
 127          
 128          /*
 129          ********************************************************************************
 130          * Function Name : DF_wr 
 131          * Description   : Write data to dataflash.
 132          * Parameter             : addr, unsigned long type, dataflash address begin to write.
 133          *                   Range from 0 to 2^21 - 1.
 134          *                                 buf, unsigned char * type, header pointer of stored data.
 135          *                                 len, unsigned int type, length of data want to write. 
 136          *                   Range from 0 to 65535.
 137          * Return                : none
 138          ********************************************************************************
 139          */
 140          void DF_wr(unsigned long addr,unsigned char * buf,unsigned int len)
 141          {
 142   1              unsigned int ba,pg;
 143   1              
 144   1              ba = (unsigned int)(addr & 0x1FF);
 145   1              pg = addr >> 9;
 146   1      
 147   1              if(len <= (512 - ba))
 148   1              {
 149   2                      if(ba) get_main_pg_buf1(pg);
 150   2                      wr_buf1(ba,buf,len);
 151   2                      prog_main_pg_buf1_erase(pg);
 152   2                      len = 0;
 153   2              }
 154   1              else
 155   1              {
 156   2                      if(ba != 0)                                                             /* address not at page edge                             */
 157   2                      {
 158   3                              get_main_pg_buf1(pg);
 159   3                              wr_buf1(ba,buf,512 - ba);
 160   3                              prog_main_pg_buf1_erase(pg);
 161   3      
 162   3                              pg ++;
 163   3                              buf += (512 - ba);      
 164   3                              len -= (512 - ba);
 165   3                      }
 166   2      
 167   2                      while(len > 511)
 168   2                      {
 169   3                              wr_buf1(0,buf,512);
 170   3                              prog_main_pg_buf1_erase(pg);
 171   3                      
 172   3                              pg ++;
 173   3                              buf += 512;
 174   3                              len -= 512;     

⌨️ 快捷键说明

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