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

📄 i2c.lst

📁 usb接口应用文件供参考 usb接口应用文件供参考
💻 LST
字号:
C51 COMPILER V7.10   I2C                                                                   03/27/2005 22:39:53 PAGE 1   


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

line level    source

   1          #define uchar unsigned char
   2          #define uint  unsigned int
   3          #define ulong unsigned long
   4          #include <reg52.h>
   5          #include <absacc.h>
   6          #include "intrins.h"
   7          #include "mylib.h"
   8          #define iicadd 0x10;
   9          sbit da=P2^6;
  10          sbit cl=P2^7;
  11          void sta()       //启动总线传输
  12           {
  13   1         da=1;
  14   1         _nop_();
  15   1         _nop_();
  16   1         _nop_();
  17   1         cl=1;
  18   1         _nop_();
  19   1         _nop_();
  20   1         _nop_();
  21   1         _nop_();
  22   1         _nop_();
  23   1         _nop_();
  24   1         _nop_();
  25   1         _nop_();
  26   1         da=0;
  27   1         _nop_();
  28   1         _nop_();
  29   1         _nop_();
  30   1         _nop_();
  31   1         _nop_();
  32   1         _nop_();
  33   1         _nop_();
  34   1         _nop_();
  35   1         _nop_();
  36   1         cl=0;
  37   1       }
  38          void stop()     //结束总线传输
  39          {
  40   1        da=0;
  41   1        cl=1;
  42   1         _nop_();
  43   1         _nop_();
  44   1         _nop_();
  45   1         _nop_();
  46   1         _nop_();
  47   1         _nop_();
  48   1         _nop_();
  49   1        da=1;
  50   1        _nop_();
  51   1        _nop_();
  52   1        _nop_();
  53   1        _nop_();
  54   1        _nop_();
  55   1        _nop_();
C51 COMPILER V7.10   I2C                                                                   03/27/2005 22:39:53 PAGE 2   

  56   1        _nop_();
  57   1        _nop_();
  58   1        da=0;
  59   1        cl=0;
  60   1      }
  61          void mack()//发送应答位
  62          {
  63   1        da=0;
  64   1         _nop_();
  65   1        _nop_();
  66   1        _nop_();
  67   1        _nop_();
  68   1        cl=1;
  69   1      
  70   1         _nop_();
  71   1         _nop_();
  72   1         _nop_();
  73   1         _nop_();
  74   1         _nop_();
  75   1         _nop_();
  76   1         _nop_();
  77   1        cl=0;
  78   1         _nop_();
  79   1        _nop_();
  80   1        _nop_();
  81   1        _nop_();
  82   1        _nop_();
  83   1        _nop_();
  84   1        _nop_();
  85   1        _nop_();
  86   1        da=1;
  87   1      }
  88          void nmack()//发送非应答位
  89          {
  90   1        da=1;
  91   1        _nop_();
  92   1         _nop_();
  93   1         _nop_();
  94   1         _nop_();
  95   1         _nop_();
  96   1         _nop_();
  97   1         _nop_();
  98   1        cl=1;
  99   1        _nop_();
 100   1        _nop_();
 101   1        _nop_();
 102   1        _nop_();
 103   1        _nop_();
 104   1        _nop_();
 105   1        _nop_();
 106   1        _nop_();
 107   1        cl=0;
 108   1        da=0;
 109   1      
 110   1      }
 111          bit cack() //发送状态检测
 112          {
 113   1        bit a=0;
 114   1        da=1;
 115   1        cl=1;
 116   1        if(da==0)
 117   1         {
C51 COMPILER V7.10   I2C                                                                   03/27/2005 22:39:53 PAGE 3   

 118   2          
 119   2          _nop_();
 120   2          _nop_();
 121   2          _nop_();
 122   2          _nop_();
 123   2          _nop_();
 124   2          _nop_();
 125   2          _nop_();
 126   2          _nop_(); cl=0;
 127   2          return(0);
 128   2         }
 129   1        else 
 130   1         {
 131   2          _nop_();
 132   2          _nop_();
 133   2          _nop_();
 134   2          _nop_();
 135   2          _nop_();
 136   2          _nop_();
 137   2          _nop_();
 138   2          _nop_(); cl=0;
 139   2          return(1);
 140   2         }
 141   1      }
 142          void wr1(void)//写数据1
 143          {
 144   1         da=1;
 145   1         cl=1;
 146   1         _nop_();
 147   1         _nop_();
 148   1         _nop_();
 149   1         _nop_();
 150   1         _nop_();
 151   1         _nop_();
 152   1         _nop_();
 153   1         _nop_();
 154   1         _nop_();
 155   1         cl=0;
 156   1         da=0;
 157   1      }
 158          void wr0()//写数据0
 159          {
 160   1        da=0;
 161   1        cl=1;
 162   1        _nop_();
 163   1        _nop_();
 164   1        _nop_();
 165   1        _nop_();
 166   1        _nop_();
 167   1        _nop_();
 168   1        _nop_();
 169   1        cl=0;
 170   1         _nop_();
 171   1        _nop_();
 172   1        _nop_();
 173   1        _nop_();
 174   1        _nop_();
 175   1        _nop_();
 176   1        _nop_();
 177   1      }
 178          wrbyt(uchar byt)//写一个字节的数据到总线上
 179          {
C51 COMPILER V7.10   I2C                                                                   03/27/2005 22:39:53 PAGE 4   

 180   1        uchar temp=0x00;
 181   1        uchar count;
 182   1        for(count=0;count<8;count++)
 183   1          {
 184   2            if((byt<<count)&0x80)
 185   2              wr1();
 186   2            else
 187   2              wr0();  
 188   2           }
 189   1      }
 190          uchar rdbyt() //从总线上读取一个字节的数据
 191          {
 192   1        uchar a=0,i=0;
 193   1        for(i=0;i<8;i++)
 194   1         {
 195   2           da=1;
 196   2           cl=1;
 197   2           if(da==1)
 198   2            {
 199   3                 a=(a<<1)+1;
 200   3             cl=0;
 201   3            }
 202   2           else if(da==0)
 203   2           {
 204   3             a=a<<1;
 205   3             cl=0;
 206   3           }
 207   2         }
 208   1          return(a);
 209   1      }
 210          bit wrnbyt(uchar add,uchar start,uchar num,uchar *k) //向24C02(ADD)从字节(START)开始写(NUM)个字节
 211          {       
 212   1          uchar *p=k;
 213   1              uchar dk;
 214   1          for(dk=0;dk<num;dk++,p++)
 215   1              {
 216   2          sta();
 217   2          wrbyt(add);
 218   2          mack();
 219   2          wrbyt(start);
 220   2              start=start+1;
 221   2          mack();
 222   2          wrbyt(*p);
 223   2          mack();
 224   2          stop();
 225   2              delay50();
 226   2          }
 227   1              return(1); 
 228   1       }
 229          bit rdnbyt(uchar add,uchar start,uchar num,uchar a[])  //从24C02(ADD)字节(START)开始读取(NUM)个字节

⌨️ 快捷键说明

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