wl007.lst

来自「单片机开发资料 基于51单片机的单片机开发板 包括《实验例程」· LST 代码 · 共 210 行

LST
210
字号
C51 COMPILER V7.08   WL007                                                                 11/03/2004 11:07:41 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-11-5                                                    *
   5          *    Version    : 1.0                                                          *
   6          *                                                                              *
   7          ********************************************************************************
   8          *    Descriptoon:                                                              *
   9          *                读写AT24C01演示程序                                           *
  10          *                                                                              *
  11          *                                                                              *
  12          *                                                                              *
  13          *******************************************************************************/
  14          #include <reg51.h>
  15          #include <intrins.h>
  16          
  17          #define OP_READ 0xa1            // 器件地址以及读取操作
  18          #define OP_WRITE 0xa0           // 器件地址以及写入操作
  19          #define MAX_ADDR 0x7f           // AT24C01最大地址
  20          
  21          unsigned char code dis_code[] = {0x7e,0xbd,0xdb,0xe7,0xdb,0xbd,0x7e,0xff};
  22                                          // 写入到AT24C01的数据串
  23          
  24          sbit SDA = P1^1;
  25          sbit SCL = P1^0;
  26          
  27          
  28          void start();
  29          void stop();
  30          unsigned char shin();
  31          bit shout(unsigned char write_data);
  32          unsigned char read_random(unsigned char random_addr);
  33          void write_byte( unsigned char addr, unsigned char write_data);
  34          void fill_byte(unsigned char fill_data);
  35          void delayms(unsigned char ms);
  36          
  37          main(void)
  38          {
  39   1              unsigned char i;
  40   1              SDA = 1;
  41   1              SCL = 1;
  42   1              fill_byte(0xff);                // 全部填充0xff
  43   1      
  44   1              for(i = 0 ; i < 8; i++)         //写入显示代码到AT24Cxx
  45   1              {
  46   2                      write_byte(i, dis_code[i]);
  47   2              }
  48   1      
  49   1              i = 0;
  50   1              while(1)
  51   1              {
  52   2      
  53   2                      P0 = read_random(i);    // 循环读取24Cxx内容,并输出到P0口
  54   2                      i++;
  55   2                      i &= 0x07;              // 循环读取范围为0x00~0x07
C51 COMPILER V7.08   WL007                                                                 11/03/2004 11:07:41 PAGE 2   

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

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

 180   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 + -
显示快捷键?