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

📄 eerom.lst

📁 此程序实现无线信标定位
💻 LST
字号:
C51 COMPILER V7.06   EEROM                                                                 07/07/2008 21:47:20 PAGE 1   


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

stmt level    source

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

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

 118   1       TestAck();                                                             //应答检查
 119   1       Write8Bit(RomAddress);                                 //写入I2C器件内部的数据存储首地址
 120   1       TestAck();                                                             //应答检查
 121   1       for(;number!=0;number--)                               //循环,逐个字节发送
 122   1       {
 123   2        Write8Bit(*Wdata);                                    //写一个字节
 124   2        TestAck();                                                    //应答检查
 125   2        Wdata++;                                                              //指针增加,指向下一个数据
 126   2       }
 127   1       Stop();                                                                //停止
 128   1       DelayMs(10);
 129   1      }
 130          
 131          /***************************************************************************/
 132          unsigned char Read8Bit()                                //读一个字节数据子程序
 133          {
 134   1       unsigned char temp,rbyte=0;
 135   1       for(temp=8;temp!=0;temp--)                             //循环,逐位读入字节数据
 136   1       {
 137   2        SCL=1;
 138   2        DelayMs(1);
 139   2        rbyte=rbyte<<1;                                               //左移一位
 140   2        DelayMs(1);
 141   2        rbyte=rbyte|((unsigned char)(SDA));   //数据线SDA上的数据存入rbyte的最低位
 142   2        SCL=0;
 143   2        DelayMs(1);
 144   2       }
 145   1       return(rbyte);                                                 //返回读入的字节数据
 146   1      }
 147          
 148          /***************************************************************************/
 149          void ReadI2C(unsigned char *RamAddress,unsigned char RomAddress,unsigned char bytes)
 150          {                                                                               //读n个字节数据子程序
 151   1       Start();                                                               //启动
 152   1       Write8Bit(WriteDeviceAddress);                 //写写器件的寻址地址
 153   1       TestAck();                                                             //应答检查
 154   1       Write8Bit(RomAddress);                                 //写I2C器件内部数据的读取首地址
 155   1       TestAck();                                                             //应答检查
 156   1       Start();                                                               //重新启动
 157   1       Write8Bit(ReadDviceAddress);                   //写读器件的寻址地址
 158   1       TestAck();                                                             //应答检查
 159   1       while(bytes!=1)                                                //循环读入字节数据
 160   1       {
 161   2       *RamAddress=Read8Bit();                                //读入一个字节
 162   2       Ack();                                                                 //应答
 163   2       RamAddress++;                                                  //地址指针递增
 164   2       bytes--;                                                               //待读入数据个数递减
 165   2       }
 166   1       *RamAddress=Read8Bit();                                //读入最后一个字节数据
 167   1       NoAck();                                                               //非应答
 168   1       Stop();                                                                //停止
 169   1      }
 170          
 171          /* store the message & read it out at once to check out if right, the result of time show it */
 172          unsigned char store(unsigned char *addw,unsigned char time)
 173          {
 174   1              unsigned char readByte[N];                      //用于存读入的N个字节数据
 175   1              unsigned char *addr;
 176   1              unsigned int store_address;                             //读数据指针操作
 177   1              addr = readByte;                                //读地址映射
 178   1              store_address = time * N;
 179   1              WriteI2C(addw,store_address,N);         //写数据
C51 COMPILER V7.06   EEROM                                                                 07/07/2008 21:47:20 PAGE 4   

 180   1              ReadI2C(addr,store_address,N);          //读数据
 181   1              if(strcmp(recieve,readByte) == 0) ;
 182   1              {
 183   2                      time ++;
 184   2              }
 185   1              return time;
 186   1      }       
 187          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    395    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      34
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----       1
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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