eerom.lst

来自「此程序实现无线信标定位」· LST 代码 · 共 201 行

LST
201
字号
C51 COMPILER V7.06   EEROM                                                                 01/02/2008 21:09:42 PAGE 1   


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

stmt level    source

   1          #include <AT89X51.h>
   2          
   3          // 对AT24C08的读、写
   4          // extern void DelayMs(unsigned int);
   5          // extern void ReadI2C(unsigned char *RamAddress,unsigned char RomAddress,unsigned char bytes);
   6          // extern void WriteI2C(unsigned char *RamAddress,unsigned char RomAddress,unsigned char bytes);
   7          
   8          extern unsigned char data recieve[15];//21 ="(244)6.5211N(1210)0.1536E";
   9          
  10          /***************************************************************************/
  11          #define WriteDeviceAddress 0xa0                 //写器件地址
  12          #define ReadDviceAddress 0xa1                   //读器件地址
  13          #define SCL     P2_7                                            //I2C时钟线SCL
  14          #define SDA     P2_6                                            //I2C数据线SDA
  15          #define DOG P3_7                                                //程序运行标志及数据读写正确标志
  16          #define N       15                                                      //一次存储数组长度
  17          
  18          /***************************************************************************/
  19          void DelayMs(unsigned int number)               //延时子程序,延时大小取决于工作频率和number值
  20          {
  21   1              unsigned char temp;
  22   1              for(;number!=0;number--)        //循环,DOG用于输出状态信号
  23   1              {
  24   2                      for(temp=112;temp!=0;temp--)    //空循环
  25   2                      {
  26   3                      }
  27   2              }
  28   1      }
  29          
  30          /***************************************************************************/
  31          void Start()                                                    //起始信号子程序
  32          {
  33   1       SDA=1;                                                                 
  34   1       DelayMs(1);                                                    //延时
  35   1       SCL=1;
  36   1       DelayMs(1);
  37   1       SDA=0;
  38   1       DelayMs(1);
  39   1       SCL=0;
  40   1       DelayMs(1);
  41   1      }
  42          
  43          /***************************************************************************/
  44          void Stop()                                                             //终止信号子程序
  45          {
  46   1       SCL=0;
  47   1       DelayMs(1);
  48   1       SDA=0;
  49   1       DelayMs(1);
  50   1       SCL=1;
  51   1       DelayMs(1);
  52   1       SDA=1;
  53   1       DelayMs(1);
  54   1      }
  55          
C51 COMPILER V7.06   EEROM                                                                 01/02/2008 21:09:42 PAGE 2   

  56          /***************************************************************************/
  57          void Ack()                                                              //发送应答位子程序
  58          {
  59   1       SDA=0;
  60   1       DelayMs(1);
  61   1       SCL=1;
  62   1       DelayMs(1);
  63   1       SCL=0;
  64   1       DelayMs(1);
  65   1       SDA=1;
  66   1       DelayMs(1);
  67   1      }
  68          
  69          /***************************************************************************/
  70          void NoAck()                                                    //发送非应答位子程序
  71          {
  72   1       SDA=1;
  73   1       DelayMs(1);
  74   1       SCL=1;
  75   1       DelayMs(1);
  76   1       SCL=0;
  77   1       DelayMs(1);
  78   1      }
  79          
  80          /***************************************************************************/
  81          bit TestAck()                                                   //应答位检查子程序
  82          {
  83   1       bit ErrorBit;
  84   1       SDA=1;
  85   1       DelayMs(1);
  86   1       SCL=1;
  87   1       DelayMs(1);
  88   1       ErrorBit=SDA;                                                  //读入数据线上的应答状态
  89   1       DelayMs(1);
  90   1       SCL=0;
  91   1       DelayMs(1);
  92   1       return(ErrorBit);                                              //返回应答状态,0为正常应答信号,1为非应答信号
  93   1      }
  94          
  95          /***************************************************************************/
  96          bit Write8Bit(unsigned char input)              //写一个字节数据子程序
  97          {                                                                               //input为待发送的数据
  98   1       unsigned char temp;
  99   1       for(temp=8;temp!=0;temp--)                             //循环移位,逐位发送数据
 100   1       {
 101   2        SDA=(bit)(input&0x80);                                //取数据的最高位
 102   2        DelayMs(1);
 103   2        SCL=1;
 104   2        DelayMs(1);
 105   2        SCL=0;
 106   2        DelayMs(1);
 107   2        input=input<<1;                                               //左移一位
 108   2       }
 109   1       return 1;
 110   1      }
 111          
 112          /***************************************************************************/
 113          void WriteI2C(unsigned char *Wdata,unsigned char RomAddress,unsigned char number)
 114          {                                                                               //写n个字节数据子程序
 115   1       Start();                                                               //启动
 116   1       Write8Bit(WriteDeviceAddress);                 //写写器件的寻址地址
 117   1       TestAck();                                                             //应答检查
C51 COMPILER V7.06   EEROM                                                                 01/02/2008 21:09:42 PAGE 3   

 118   1       Write8Bit(RomAddress);                                 //写入I2C器件内部的数据存储首地址
 119   1       TestAck();                                                             //应答检查
 120   1       for(;number!=0;number--)                               //循环,逐个字节发送
 121   1       {
 122   2        Write8Bit(*Wdata);                                    //写一个字节
 123   2        TestAck();                                                    //应答检查
 124   2        Wdata++;                                                              //指针增加,指向下一个数据
 125   2       }
 126   1       Stop();                                                                //停止
 127   1       DelayMs(10);
 128   1      }
 129          
 130          /***************************************************************************/
 131          unsigned char Read8Bit()                                //读一个字节数据子程序
 132          {
 133   1       unsigned char temp,rbyte=0;
 134   1       for(temp=8;temp!=0;temp--)                             //循环,逐位读入字节数据
 135   1       {
 136   2        SCL=1;
 137   2        DelayMs(1);
 138   2        rbyte=rbyte<<1;                                               //左移一位
 139   2        DelayMs(1);
 140   2        rbyte=rbyte|((unsigned char)(SDA));   //数据线SDA上的数据存入rbyte的最低位
 141   2        SCL=0;
 142   2        DelayMs(1);
 143   2       }
 144   1       return(rbyte);                                                 //返回读入的字节数据
 145   1      }
 146          
 147          /***************************************************************************/
 148          void ReadI2C(unsigned char *RamAddress,unsigned char RomAddress,unsigned char bytes)
 149          {                                                                               //读n个字节数据子程序
 150   1       Start();                                                               //启动
 151   1       Write8Bit(WriteDeviceAddress);                 //写写器件的寻址地址
 152   1       TestAck();                                                             //应答检查
 153   1       Write8Bit(RomAddress);                                 //写I2C器件内部数据的读取首地址
 154   1       TestAck();                                                             //应答检查
 155   1       Start();                                                               //重新启动
 156   1       Write8Bit(ReadDviceAddress);                   //写读器件的寻址地址
 157   1       TestAck();                                                             //应答检查
 158   1       while(bytes!=1)                                                //循环读入字节数据
 159   1       {
 160   2       *RamAddress=Read8Bit();                                //读入一个字节
 161   2       Ack();                                                                 //应答
 162   2       RamAddress++;                                                  //地址指针递增
 163   2       bytes--;                                                               //待读入数据个数递减
 164   2       }
 165   1       *RamAddress=Read8Bit();                                //读入最后一个字节数据
 166   1       NoAck();                                                               //非应答
 167   1       Stop();                                                                //停止
 168   1      }
 169          
 170                  
 171          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    326    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      10
C51 COMPILER V7.06   EEROM                                                                 01/02/2008 21:09:42 PAGE 4   

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