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

📄 i2c.lst

📁 环境:keil c51 i2c调度工具
💻 LST
字号:
C51 COMPILER V7.07   I2C                                                                   03/26/2005 15:54:46 PAGE 1   


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

stmt level    source

   1          /******************************************************************************************
   2          I2C程序包
   3          作者:Lianyitian
   4          公司:XMMALATA
   5          日期:2004-3-19 14:05
   6          *******************************************************************************************/
   7          #include <i2c.h>
   8          #include <intrins.h>
   9          
  10          void i2c_start(void)
  11          {
  12   1              SDA = 1;
  13   1              _nop_();_nop_();
  14   1              SCL = 1;
  15   1              _nop_();_nop_();
  16   1              SDA = 0;
  17   1              _nop_();_nop_();
  18   1              SCL = 0;
  19   1              _nop_();_nop_();
  20   1      }
  21          
  22          void i2c_stop (void);
  23          void i2c_stop (void)
  24          {
  25   1              SCL = 0;
  26   1              _nop_();_nop_();
  27   1              SDA = 0;
  28   1              _nop_();_nop_();
  29   1              SCL = 1;
  30   1              _nop_();_nop_();
  31   1              SDA = 1;
  32   1              _nop_();_nop_();
  33   1      }
  34          
  35          void i2c_ack(void);
  36          void i2c_ack(void)
  37          {
  38   1              SCL = 0;
  39   1              _nop_();_nop_();
  40   1              SCL = 1;
  41   1              _nop_();_nop_();
  42   1              if(SDA==1)//no ack fail to write
  43   1              IIC_ERROR=1;
  44   1              else
  45   1              IIC_ERROR=0;
  46   1              SCL = 0;
  47   1              _nop_();_nop_();
  48   1      }
  49          
  50          void i2c_write (unsigned char  i2c_data);
  51          void i2c_write (unsigned char  i2c_data)
  52          {
  53   1              unsigned char index;
  54   1      
  55   1              for(index = 0; index < 8; index++)
C51 COMPILER V7.07   I2C                                                                   03/26/2005 15:54:46 PAGE 2   

  56   1              {
  57   2                      SCL = 0;
  58   2                      _nop_();_nop_();
  59   2                      SDA = ((i2c_data & 0x80) ? 1 : 0);
  60   2                      i2c_data  <<= 1;
  61   2                      _nop_();_nop_();
  62   2                      SCL = 1;
  63   2                      _nop_();_nop_();
  64   2              }
  65   1                      SCL = 0;
  66   1                      _nop_();_nop_();
  67   1      }
  68          
  69          
  70          unsigned char i2c_read(void);
  71          unsigned char i2c_read(void)
  72          {
  73   1              unsigned char index;
  74   1      
  75   1              for(index = 0; index < 8; index++)
  76   1              {
  77   2               SCL =0;
  78   2               delay_ms(1);
  79   2               SCL=1;
  80   2               delay_ms(1);
  81   2               i2c_data <<= 1;i2c_data |= SDA;
  82   2              }
  83   1              SCL=0;
  84   1              delay_ms(1);
  85   1         return i2c_data;
  86   1      }
  87          
  88          
  89          void i2c_device_sub_data(unsigned char i2c_device_address,i2c_sub_address,i2c_data_shift);
  90          void i2c_device_sub_data(unsigned char i2c_device_address,i2c_sub_address,i2c_data_shift)
  91          {
  92   1      unsigned char temp=2,temp1=0;
  93   1      for(;temp!=0;temp--)
  94   1      {
  95   2                   i2c_start();
  96   2                      _nop_();
  97   2                      i2c_write(i2c_device_address);
  98   2                      _nop_();_nop_();_nop_();
  99   2                      i2c_ack();
 100   2                        if(IIC_ERROR)
 101   2                        temp1=1;
 102   2                      _nop_();_nop_();_nop_();
 103   2                      i2c_write(i2c_sub_address);
 104   2                      _nop_();_nop_();_nop_();
 105   2                      i2c_ack();_nop_();_nop_();
 106   2                        if(IIC_ERROR)
 107   2                        temp1=1;
 108   2                      i2c_write(i2c_data_shift);
 109   2                      i2c_ack();
 110   2                        if(IIC_ERROR)
 111   2                        temp1=1;
 112   2                      i2c_stop();
 113   2                      delay_ms(250);
 114   2                      _nop_();
 115   2                      if(temp1==1)
 116   2                              {temp1=0;IIC_ERROR=1;}//fail
 117   2                      else
C51 COMPILER V7.07   I2C                                                                   03/26/2005 15:54:46 PAGE 3   

 118   2                         temp=0x01;//success
 119   2      }
 120   1      }
 121          
 122          
 123          unsigned char i2c_device_sub_data_r(unsigned char i2c_device_address,i2c_sub_address);
 124          unsigned char i2c_device_sub_data_r(unsigned char i2c_device_address,i2c_sub_address)
 125          {
 126   1                      _nop_();
 127   1                      _nop_();
 128   1                      _nop_();
 129   1                      _nop_();
 130   1                      delay_ms(250);
 131   1                      i2c_start();
 132   1                      _nop_();
 133   1                      _nop_();
 134   1                      i2c_write(i2c_device_address-1);
 135   1                      _nop_();
 136   1                      i2c_ack();
 137   1                      i2c_write(i2c_sub_address);
 138   1                      _nop_();
 139   1                      i2c_ack();
 140   1                      i2c_start();
 141   1                      i2c_write(i2c_device_address);
 142   1                      i2c_ack();
 143   1                      delay_ms(50);
 144   1                      i2c_read();
 145   1                      i2c_ack();
 146   1                      i2c_stop();
 147   1                      delay_ms(250);
 148   1                      return i2c_data;
 149   1      }
 150          
 151          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    313    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      11
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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