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

📄 i2c.lst

📁 电子时钟
💻 LST
📖 第 1 页 / 共 3 页
字号:
C51 COMPILER V7.01  I2C                                                                    11/28/2003 11:13:40 PAGE 1   


C51 COMPILER V7.01, 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                                                  //i1c test//
   2                                          
   3                                                  #include        "ADUC812.h"
   4                                                  #include        "math.h"
   5                                                  #include        "intrins.h"
   6                                                  #include        "string.h"
   7                                                  #include        "stdio.h"
   8                                                  
   9                                                  
  10                                                  sbit    SDA=P3^2;
  11                                                  sbit    SCL=P3^3;       
  12                                                  #define deviceadd 0xa0
  13                                                  
  14                                                  
  15                                                  //************* Delay  *********//      
  16                                                  void delay(int n)
  17                                                  {
  18   1                                                      int     i;
  19   1                                                      for(i=0;i<=n;i++)
  20   1                                                      {
  21   2                                                              _nop_();
  22   2                                                      }
  23   1                                              }
  24                                                  
  25                                                  //************* Delay N ms *********//  
  26                                                  void delay_ms(int n)
  27                                                  {
  28   1                                                      int     i,j;
  29   1                                                      for(i=0;i<=n;i++)
  30   1                                                      {
  31   2                                                              for(j=0;j<=1000;j++)                    //** Delay 1 ms **//
  32   2                                                              {
  33   3                                                                      _nop_();
  34   3                                                              }
  35   2                                                      }
  36   1                                              }
  37                                                  
  38                                                  
  39                                                  //**************Start**********//
  40                                                  void I2C_start(void)
  41                                                  {
  42   1                                                      SDA=1;
  43   1                                                      SCL=1;
  44   1                                                      delay(3);
  45   1                                                      SDA=0;
  46   1                                                      delay(3);
  47   1                                                      SCL=0;
  48   1                                              }
  49                                                  
  50                                                  //*************Stop***********//
  51                                                  void I2C_stop(void)
  52                                                  {
  53   1                                                      SDA=0;
  54   1                                                      SCL=1;
  55   1                                                      delay(3);
C51 COMPILER V7.01  I2C                                                                    11/28/2003 11:13:40 PAGE 2   

  56   1                                                      SDA=1;
  57   1                                                      delay(3);
  58   1                                                      SCL=0;
  59   1                                              }
  60                                                  
  61                                                  //*************Ack**************//
  62                                                  void I2C_ack(void)
  63                                                  {
  64   1                                                      SDA=0;
  65   1                                                      SCL=1;
  66   1                                                      delay(3);
  67   1                                                      SCL=0;
  68   1                                                      SDA=1;
  69   1                                              }
  70                                                  
  71                                                  //*************No Ack*********//
  72                                                  void I2C_nack(void)
  73                                                  {
  74   1                                                      SDA=1;
  75   1                                                      SCL=1;
  76   1                                                      delay(3);
  77   1                                                      SCL=0;
  78   1                                                      SDA=0;
  79   1                                              }
  80                                                  
  81                                                  //*********Check ack signal*******//
  82                                                  bit I2C_Cack(void)
  83                                                  {
  84   1                                                      bit a;
  85   1                                                      SDA=1;
  86   1                                                      SCL=1;
  87   1                                                      delay(1);
  88   1                                                      a=SDA;
  89   1                                                      delay(1);
  90   1                                                      SCL=0;
  91   1                                                      delay(3);
  92   1                                                      if(a==1)
  93   1                                                      {
  94   2                                                              return  1;
  95   2                                                      }
  96   1                                                      else
  97   1                                                      {
  98   2                                                              return  0;
  99   2                                                      }
 100   1                                              }
 101                                                          
 102                                                  //**********Send a Bety*********//
 103                                                  void I2C_Send_byte(char da)
 104                                                  {
 105   1                                                      unsigned char i;
 106   1                                                      for(i=0;i<8;i++)
 107   1                                                      {
 108   2                                                              if((da<<i)&0x80)
 109   2                                                              {
 110   3                                                              SDA=1;                  //send "1"//
 111   3                                                              SCL=1;
 112   3                                                              delay(3);
 113   3                                                              SCL=0;
 114   3                                                              SDA=0;
 115   3                                                              delay(3);
 116   3                                                              }
 117   2                                                              else
C51 COMPILER V7.01  I2C                                                                    11/28/2003 11:13:40 PAGE 3   

 118   2                                                              {
 119   3                                                              SDA=0;                  //send "0"//
 120   3                                                              SCL=1;
 121   3                                                              delay(3);
 122   3                                                              SCL=0;
 123   3                                                              delay(3);       
 124   3                                                              }
 125   2                                                      }
 126   1                                              }

⌨️ 快捷键说明

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