wl007.lst

来自「周立功的51单片机试验例程,我当年就是靠这个学会单片机的」· LST 代码 · 共 213 行

LST
213
字号
C51 COMPILER V7.08   WL007                                                                 02/23/2006 16:50:30 PAGE 1   


C51 COMPILER V7.08, COMPILATION OF MODULE WL007
OBJECT MODULE PLACED IN wl007.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE wl007.C BROWSE DEBUG OBJECTEXTEND

line level    source

   1          /*******************************************************************************
   2          *                                                                              *
   3          *    File       : wl007.c                                                      *
   4          *    Date       : 2004-1-5                                                     *
   5          *    Version    : 1.0                                                          *
   6          *                                                                              *
   7          *    Author     : Freeman          freeman@willar.com                          *
   8          *    Company    : Willar           www.willar.com                              *
   9          *                                                                              *
  10          ********************************************************************************
  11          *    Descriptoon:                                                              *
  12          *                读写AT24C01演示程序                                           *
  13          *                                                                              *
  14          *                                                                              *
  15          *                                                                              *
  16          *******************************************************************************/
  17          #include <reg51.h>
  18          #include <intrins.h>
  19          
  20          #define OP_READ 0xa1            // 器件地址以及读取操作
  21          #define OP_WRITE 0xa0           // 器件地址以及写入操作
  22          #define MAX_ADDR 0x7f           // AT24C01最大地址
  23          
  24          unsigned char code dis_code[] = {0x7e,0xbd,0xdb,0xe7,0xdb,0xbd,0x7e,0xff};
  25                                          // 写入到AT24C01的数据串
  26          
  27          sbit SDA = P1^1;
  28          sbit SCL = P1^0;
  29          
  30          
  31          void start();
  32          void stop();
  33          unsigned char shin();
  34          bit shout(unsigned char write_data);
  35          unsigned char read_random(unsigned char random_addr);
  36          void write_byte( unsigned char addr, unsigned char write_data);
  37          void fill_byte(unsigned char fill_data);
  38          void delayms(unsigned char ms);
  39          
  40          main(void)
  41          {
  42   1              unsigned char i;
  43   1              SDA = 1;
  44   1              SCL = 1;
  45   1              fill_byte(0xff);                // 全部填充0xff
  46   1      
  47   1              for(i = 0 ; i < 8; i++)         //写入显示代码到AT24Cxx
  48   1              {
  49   2                      write_byte(i, dis_code[i]);
  50   2              }
  51   1      
  52   1              i = 0;
  53   1              while(1)
  54   1              {
  55   2      
C51 COMPILER V7.08   WL007                                                                 02/23/2006 16:50:30 PAGE 2   

  56   2                      P0 = read_random(i);    // 循环读取24Cxx内容,并输出到P0口
  57   2                      i++;
  58   2                      i &= 0x07;              // 循环读取范围为0x00~0x07
  59   2                      delayms(250);
  60   2              }
  61   1      }
  62          
  63          void start()
  64          // 开始位
  65          {
  66   1              SDA = 1;
  67   1              SCL = 1;
  68   1              _nop_();
  69   1              _nop_();
  70   1              SDA = 0;
  71   1              _nop_();
  72   1              _nop_();
  73   1              _nop_();
  74   1              _nop_();
  75   1              SCL = 0;
  76   1      }
  77          
  78          void stop()
  79          // 停止位
  80          {
  81   1              SDA = 0;
  82   1              _nop_();
  83   1              _nop_();
  84   1              SCL = 1;
  85   1              _nop_();
  86   1              _nop_();
  87   1              _nop_();
  88   1              _nop_();
  89   1              SDA = 1;
  90   1      }
  91          
  92          unsigned char shin()
  93          // 从AT24Cxx移入数据到MCU
  94          {
  95   1              unsigned char i,read_data;
  96   1              for(i = 0; i < 8; i++)
  97   1              {
  98   2                      SCL = 1;
  99   2                      read_data <<= 1;
 100   2                      read_data |= (unsigned char)SDA;
 101   2                      SCL = 0;
 102   2              }
 103   1              return(read_data);
 104   1      }
 105          bit shout(unsigned char write_data)
 106          // 从MCU移出数据到AT24Cxx
 107          {
 108   1              unsigned char i;
 109   1              bit ack_bit;
 110   1              for(i = 0; i < 8; i++)          // 循环移入8个位
 111   1              {
 112   2                      SDA = (bit)(write_data & 0x80);
 113   2                      _nop_();
 114   2                      SCL = 1;
 115   2                      _nop_();
 116   2                      _nop_();
 117   2                      SCL = 0;
C51 COMPILER V7.08   WL007                                                                 02/23/2006 16:50:30 PAGE 3   

 118   2                      write_data <<= 1;
 119   2              }
 120   1              SDA = 1;                        // 读取应答
 121   1              _nop_();
 122   1              _nop_();
 123   1              SCL = 1;
 124   1              _nop_();
 125   1              _nop_();
 126   1              _nop_();
 127   1              _nop_();
 128   1              ack_bit = SDA;
 129   1              SCL = 0;
 130   1              return ack_bit;                 // 返回AT24Cxx应答位
 131   1      }
 132          
 133          void write_byte(unsigned char addr, unsigned char write_data)
 134          // 在指定地址addr处写入数据write_data
 135          {
 136   1              start();
 137   1              shout(OP_WRITE);
 138   1              shout(addr);
 139   1              shout(write_data);
 140   1              stop();
 141   1              delayms(10);            // 写入周期
 142   1      }
 143          
 144          void fill_byte(unsigned char fill_data)
 145          // 填充数据fill_data到EEPROM内
 146          {
 147   1              unsigned char i;
 148   1              for(i = 0; i < MAX_ADDR; i++)
 149   1              {
 150   2                      write_byte(i, fill_data);
 151   2              }
 152   1      
 153   1      }
 154          
 155          unsigned char read_current()
 156          // 在当前地址读取
 157          {
 158   1              unsigned char read_data;
 159   1              start();
 160   1              shout(OP_READ);
 161   1              read_data = shin();
 162   1              stop();
 163   1              return read_data;
 164   1      }
 165          
 166          unsigned char read_random(unsigned char random_addr)
 167          // 在指定地址读取
 168          {
 169   1              start();
 170   1              shout(OP_WRITE);
 171   1              shout(random_addr);
 172   1              return(read_current());
 173   1      }
 174          
 175          void delayms(unsigned char ms)  
 176          // 延时子程序
 177          {
 178   1              unsigned char i;
 179   1              while(ms--)
C51 COMPILER V7.08   WL007                                                                 02/23/2006 16:50:30 PAGE 4   

 180   1              {
 181   2                      for(i = 0; i < 120; i++);
 182   2              }
 183   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    246    ----
   CONSTANT SIZE    =      8    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----       3
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----       1
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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