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

📄 at24c02.lst

📁 0834实现数据的采集
💻 LST
字号:
C51 COMPILER V7.00  AT24C02                                                                05/22/2007 16:53:19 PAGE 1   


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

stmt level    source

   1          #include <reg52.h>
   2          #define uchar  unsigned char
   3          #define uint   unsigned int
   4          
   5          #define PAGE_SIZE               7
   6          sbit sda_rom=P1^4;
   7          sbit clk_rom=P1^3;
   8          
   9          void Set_Sda(bit sw)
  10          {
  11   1               sda_rom=sw;
  12   1      }
  13          
  14          void Set_Scl(bit sw)
  15          {
  16   1               clk_rom=sw;
  17   1      }
  18          
  19          void Set_Start_Condition()
  20          {
  21   1               Set_Scl(0);
  22   1               Set_Sda(1);
  23   1               Set_Scl(1);
  24   1               Set_Sda(0);
  25   1      }
  26          
  27          void Set_Stop_Condition()
  28          {
  29   1               Set_Scl(0);
  30   1               Set_Sda(0);
  31   1               Set_Scl(1);
  32   1               Set_Sda(1);
  33   1      }
  34          
  35          void Send_Byte_Memory(uchar  value)
  36          {
  37   1               uchar  i,shift;
  38   1               shift=0x80;
  39   1               for(i=0;i<8;i++)
  40   1               {
  41   2                       Set_Scl(0);
  42   2                       if(value&shift)
  43   2                       {
  44   3                              Set_Sda(1);
  45   3                       }
  46   2                       else
  47   2                       {
  48   3                              Set_Sda(0);
  49   3                       }
  50   2                       shift>>=1;
  51   2                       Set_Scl(1);
  52   2               }
  53   1               Set_Scl(0);
  54   1               Set_Sda(1);
  55   1               Set_Scl(1);
C51 COMPILER V7.00  AT24C02                                                                05/22/2007 16:53:19 PAGE 2   

  56   1      }
  57          
  58          uchar Revice_Byte_Memory()
  59          {
  60   1              uchar  i,value=0;
  61   1              for(i=0;i<8;i++)
  62   1              {
  63   2                      value<<=1;
  64   2                      Set_Scl(1);
  65   2                      if(sda_rom) value|=1;
  66   2                      Set_Scl(0);
  67   2              }
  68   1              return value;
  69   1      }
  70          
  71          bit Write_Device(uint  addr)
  72          {
  73   1               uchar  i,k;
  74   1               i=(addr>>8)&0xff;
  75   1               i<<=1;
  76   1               i|=0xa0;
  77   1      
  78   1               for(k=0;k<100;k++)
  79   1               {
  80   2                      Set_Start_Condition();    //Set_Sda(0);此指令前data=clk=1;产生起始位
  81   2                      Send_Byte_Memory(i);
  82   2                      if(!sda_rom) goto ack_ok;
  83   2               }
  84   1               return 1;
  85   1      ack_ok:
  86   1               i=addr&0xff;
  87   1               Send_Byte_Memory(i);
  88   1               return 0;
  89   1      }
  90          
  91          //return =0 fail
  92          //       =1 success
  93          bit ReadEeprom(uchar *s,int  addr,int  len)
  94          {
  95   1               int i;
  96   1               if(Write_Device(addr)) return 0;
  97   1           i=(addr>>8)&0xff;
  98   1               i<<=1;
  99   1               i|=0xa1;
 100   1              Set_Start_Condition();
 101   1              Send_Byte_Memory(i);
 102   1              Set_Scl(0);
 103   1              Set_Sda(1);
 104   1              s[0]=Revice_Byte_Memory();
 105   1              for(i=1;i<len;i++)
 106   1              {
 107   2                      Set_Sda(0);
 108   2                      Set_Scl(1);
 109   2                      Set_Scl(0);
 110   2                      Set_Sda(1);
 111   2                      s[i]=Revice_Byte_Memory();
 112   2              }
 113   1      
 114   1              Set_Sda(1);
 115   1              Set_Scl(1);
 116   1              Set_Stop_Condition();
 117   1              return 1;
C51 COMPILER V7.00  AT24C02                                                                05/22/2007 16:53:19 PAGE 3   

 118   1      }
 119          
 120          //return =1 success
 121          //       =0 fail
 122          bit WriteEeprom(uchar  *s, int  addr,int  len)
 123          {
 124   1               uchar temp;
 125   1      start_label:
 126   1               if(Write_Device(addr))return 0;
 127   1               while(len>0)
 128   1               {
 129   2                      len--;
 130   2                      Send_Byte_Memory(*s);
 131   2                      //temp=addr&PAGE_SIZE;
 132   2                      addr++;
 133   2                      s++;
 134   2              temp=addr&PAGE_SIZE;
 135   2                      if(temp==0)           //原版:if(temp==PAGE_SIZE)
 136   2                      {
 137   3                              Set_Stop_Condition();
 138   3                              goto start_label;
 139   3                      }
 140   2               }
 141   1               Set_Stop_Condition();
 142   1               return 1;
 143   1      }
 144          
 145          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    406    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      16
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----       2
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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