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

📄 i2c.lst

📁 单片机键值测定程序
💻 LST
字号:
C51 COMPILER V7.50   I2C                                                                   05/31/2008 10:36:54 PAGE 1   


C51 COMPILER V7.50, 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          /****************************************************************************
   2          *                                                                           *
   3          *                                                       I2C Driving Routines                                                    *
   4          *                                                                           *
   5          ****************************************************************************/
   6          #include "define.h"
   7          #include "global.h"
   8          #include <regX52.H>
   9          #include <intrins.h>
  10          
  11          void I2C_BitDelay(void)
  12          {
  13   1      _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
  14   1      
  15   1      }
  16          
  17          /****************************************************************************
  18          * Name: Send_I2C_Start
  19          * Description: This function assumes that SCCLK and SDA are both high upon entrance,
  20           and generates the I2C start condition required for initiating
  21           communication
  22          Return value: NONE
  23          ****************************************************************************/
  24          void Send_I2C_Start(void)
  25          {
  26   1              PIN_SDA=1;I2C_BitDelay(); PIN_SCL=1;
  27   1              I2C_BitDelay();
  28   1      
  29   1              PIN_SDA=0;                              // drive SDA low while SCCLK is high for I2C start
  30   1              I2C_BitDelay();
  31   1      
  32   1              PIN_SCL=0;                              // drive SCCLK low to prepare for data transfer
  33   1              I2C_BitDelay();
  34   1      }
  35          
  36          
  37          /****************************************************************************
  38          * Name: Send_I2C_Stop
  39          * Description: This function generates the I2C stop condition required for
  40           proper termination of I2C communication
  41          Return value: NONE
  42          ****************************************************************************/
  43          void Send_I2C_Stop(void)
  44          {
  45   1              PIN_SDA=0;                              //ensure that SDA is low
  46   1              I2C_BitDelay();
  47   1              PIN_SCL=1;                              //drive SCCLK high to prepare for I2C stop
  48   1              I2C_BitDelay();
  49   1      
  50   1              PIN_SDA=1;                              //SDA rising edge while SCCLK high = I2C stop
  51   1              I2C_BitDelay();
  52   1      
  53   1      }
  54          
  55          /***************************************************************************/
C51 COMPILER V7.50   I2C                                                                   05/31/2008 10:36:54 PAGE 2   

  56          //法送确认信号
  57          
  58          void SendAcknowledge(bit ack)
  59          {
  60   1      
  61   1       PIN_SDA=ack;
  62   1       I2C_BitDelay();
  63   1       PIN_SCL=1;
  64   1       I2C_BitDelay();
  65   1       PIN_SCL=0;
  66   1      }
  67          
  68          
  69          
  70          /****************************************************************************
  71          * Name: Write_I2C_Byte
  72          * Description: 
  73           This function will write one byte through the parallel port in I2C serial 
  74           communication format. The SCCLK is assumed LOW upon entering this function, 
  75           and is left LOW upon exiting.
  76          ****************************************************************************/
  77          
  78          
  79          bit Write_I2C_Byte(uchar mybyte){
  80   1      
  81   1      register uchar i,t;                             // bit counter
  82   1      bit ack;
  83   1              for (i=0;i<8;i++){
  84   2      
  85   2              if(mybyte & 0x80)
  86   2                        {PIN_SDA=1;P2_3=0;}
  87   2                      else {PIN_SDA=0;P2_3=1;}
  88   2      
  89   2                      I2C_BitDelay();
  90   2                      PIN_SCL=1;                              // clock out
  91   2                      for(t=0;t<12;t++)
  92   2                      {
  93   3      
  94   3                      I2C_BitDelay();
  95   3                      }
  96   2                      P2_2=0;
  97   2                      for(t=0;t<1;t++)
  98   2                      {
  99   3      
 100   3                      I2C_BitDelay();
 101   3                      }
 102   2                      P2_2=1;
 103   2                                      for(t=0;t<12;t++)
 104   2                      {
 105   3      
 106   3                      I2C_BitDelay();
 107   3                      }
 108   2      
 109   2                      PIN_SCL=0;
 110   2                      mybyte<<=1;
 111   2              }
 112   1                      
 113   1              PIN_SDA=1;                      // release SDA for ACK
 114   1              I2C_BitDelay();
 115   1      
 116   1                      
 117   1              // ************* to get ACK ***************
C51 COMPILER V7.50   I2C                                                                   05/31/2008 10:36:54 PAGE 3   

 118   1              PIN_SCL=1;P2_2=0;
 119   1              I2C_BitDelay();
 120   1       
 121   1      P2_2=1;
 122   1      
 123   1              PIN_SCL=0;      
 124   1              I2C_BitDelay();if(PIN_SDA==0)ack=0;else ack=1;if(ack==1)P2_3=0;
 125   1              return ack;                             // Received ACK, return 0
 126   1      
 127   1      
 128   1      }
 129          
 130          
 131          /****************************************************************************
 132          ; Name: Read_I2C_Byte
 133          ; Description: 
 134          ; This function will read one byte through I2C serial 
 135          ; communication format. The SCCLK is assumed LOW upon entering this function, 
 136          ; and is left LOW upon exiting.
 137          ;****************************************************************************/
 138          
 139          uchar Read_I2C_Byte(void){
 140   1      register uchar i;
 141   1      uchar Byte;
 142   1              for(i=0;i<8;i++){
 143   2                      PIN_SCL=1;
 144   2                      I2C_BitDelay(); 
 145   2              Byte<<=1;
 146   2              if(PIN_SDA)Byte=Byte | 0x01;
 147   2                      I2C_BitDelay();
 148   2                      PIN_SCL=0;
 149   2                      I2C_BitDelay();
 150   2              
 151   2      
 152   2              }               
 153   1      
 154   1      return Byte;
 155   1      }
 156          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    181    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   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 + -