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

📄 i2c.lst

📁 dvr
💻 LST
字号:
C51 COMPILER V7.50   I2C                                                                   12/14/2005 10:05:34 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE I2C
OBJECT MODULE PLACED IN .\OBJ\i2c.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE i2c.c LARGE OPTIMIZE(9,SIZE) BROWSE PRINT(.\LST\i2c.lst) OBJECT(.\OBJ\i2c.o
                    -bj)

line level    source

   1          /*
   2          ********************************************************************************
   3          *
   4          * (c) Copyright 2002, Vineyard Technologies, Inc.
   5          *
   6          * Filename : i2c.c
   7          * Programmer(s): Steve KyeongHyeon Lee
   8          * Created : 2003/05/07
   9          * Modified :
  10          *
  11          * Description : 
  12          ********************************************************************************
  13          */
  14          #include "types.h"
  15          
  16          #include "8052reg.h"
  17          #include "gio.h"
  18          #include "i2c.h"
  19          
  20          // try to make I2C clock around 100KHz when using 40MHz MCU clock
  21          
  22          //------------------------------------------------------------------------------
  23          // I2C Peripheral Function Prototypes
  24          //------------------------------------------------------------------------------
  25          
  26          void i2c_delay(void)
  27          {
  28   1              idata u8 m=1;
  29   1              
  30   1              return;
  31   1      }
  32          
  33          void i2c_delay2(u8 delay_duration)
  34          {
  35   1              xdata u8 i;
  36   1              for(i=0;i<delay_duration;i++);
  37   1      }
  38          
  39          //------------------------------------------------------------------------------
  40          //
  41          //------------------------------------------------------------------------------
  42          void i2c_pkt_write(u8 ipw_channel, u8 ipw_regidx, u8 ipw_regval)
  43          {
  44   1              i2c_start();
  45   1              i2c_write(ipw_channel);
  46   1              i2c_write(ipw_regidx);
  47   1              i2c_write(ipw_regval);
  48   1              i2c_stop();
  49   1      }
  50          
  51          //------------------------------------------------------------------------------
  52          //
  53          //------------------------------------------------------------------------------
  54          u8 i2c_pkt_read(u8 ipr_channel, u8 ipr_regidx)
C51 COMPILER V7.50   I2C                                                                   12/14/2005 10:05:34 PAGE 2   

  55          {
  56   1              xdata u8 ipr_data_in;
  57   1      
  58   1              i2c_start();
  59   1              i2c_write(ipr_channel);
  60   1              i2c_write(ipr_regidx);
  61   1              i2c_stop();
  62   1      
  63   1              i2c_start();
  64   1              i2c_write(ipr_channel+1);
  65   1              ipr_data_in = i2c_read();
  66   1              i2c_stop();
  67   1              return ipr_data_in;
  68   1      }
  69          
  70          //------------------------------------------------------------------------------
  71          // I2C Functions - Bit Banged
  72          //------------------------------------------------------------------------------
  73          void i2c_start(void)
  74          {
  75   1              SDATA = HIGH;                                                   // Set data line high
  76   1              i2c_delay(); //(10);
  77   1      
  78   1              SCLK = HIGH;                                                    // Set clock line high
  79   1              i2c_delay(); //(10);
  80   1      
  81   1              SDATA = LOW;                                                    // Set data line low (START SIGNAL)
  82   1              i2c_delay(); //(4);
  83   1              
  84   1              SCLK = LOW;                                                             // Set clock line low
  85   1              i2c_delay(); //(4);
  86   1              
  87   1      }
  88          
  89          //------------------------------------------------------------------------------
  90          //
  91          //------------------------------------------------------------------------------
  92          void i2c_stop (void)
  93           {
  94   1              xdata u8 is_input_var;
  95   1      
  96   1              SCLK  = LOW;                                                    // Set clock line low .. need more delay
  97   1              i2c_delay2(1);
  98   1      
  99   1              SDATA = LOW;                                                    // Set data line low
 100   1              i2c_delay(); //(4);
 101   1              
 102   1              SCLK  = HIGH;                                                   // Set clock line high
 103   1              i2c_delay(); //(4);
 104   1              
 105   1              SDATA = HIGH;                                                   // Set data line high (STOP SIGNAL)
 106   1              is_input_var = SDATA;                                           // Put port pin into HiZ
 107   1      }
 108          
 109          //------------------------------------------------------------------------------
 110          //
 111          //------------------------------------------------------------------------------
 112          void i2c_write (u8 iw_output_data)
 113          {
 114   1              u8 iw_index;
 115   1      
 116   1              for(iw_index = 0; iw_index < 8; iw_index++)     // Send 8 bits to the I2C Bus
C51 COMPILER V7.50   I2C                                                                   12/14/2005 10:05:34 PAGE 3   

 117   1              {
 118   2                      SDATA = ((iw_output_data & 0x80) ? 1 : 0);
 119   2              iw_output_data  <<= 1;                          // Shift the byte by one bit
 120   2                      i2c_delay(); //(3);
 121   2      
 122   2                      SCLK = HIGH;                                    // Clock the data into the I2C Bus
 123   2                      i2c_delay(); //(4);
 124   2      
 125   2                      SCLK = LOW;
 126   2                      i2c_delay(); //(2);
 127   2              }
 128   1      
 129   1              // need more delay
 130   1              i2c_delay2(1);
 131   1              iw_index = SDATA;                                       // Put data pin into read mode1
 132   1      
 133   1              SCLK = HIGH;                                    // Clock the ACK from the I2C Bus
 134   1              i2c_delay(); //(7);
 135   1      
 136   1              SCLK = LOW;
 137   1              i2c_delay(); //(4);
 138   1      }
 139          
 140          //------------------------------------------------------------------------------
 141          //
 142          //------------------------------------------------------------------------------
 143          u8 i2c_read (void)
 144          {
 145   1              u8 ir_index;
 146   1              u8 ir_input_data;
 147   1      
 148   1              ir_index = SDATA;                                                       // Put data pin into read mode
 149   1              ir_input_data = 0x00;
 150   1      
 151   1              for(ir_index = 0; ir_index < 8; ir_index++)     // Send 8 bits to the I2C Bus
 152   1              {
 153   2                      ir_input_data <<= 1;                                    // Shift the byte by one bit
 154   2              ir_input_data |= SDATA;                                 // Input the data from the I2C Bus
 155   2                      SCLK = HIGH;                                    // Clock the data into the I2C Bus
 156   2                      i2c_delay(); //(4);
 157   2      
 158   2                      SCLK = LOW;
 159   2                      i2c_delay(); //(3);
 160   2              }
 161   1      
 162   1              // need more delay
 163   1              i2c_delay2(1);
 164   1      
 165   1              ir_index = SDATA;                                       // Put data pin into read mode1
 166   1              SCLK = HIGH;                                            // Clock the ACK from the I2C Bus
 167   1              i2c_delay(); //(7);
 168   1      
 169   1              SCLK = LOW;
 170   1              i2c_delay(); //(4);
 171   1      
 172   1              return ir_input_data;
 173   1      }
 174          
 175          u8 I2C_RxByte(u8 bSLA, u8 bREG)// 20051020 add for BIT1601
 176          {
 177   1              xdata u8 ipr_data_in;
 178   1      
C51 COMPILER V7.50   I2C                                                                   12/14/2005 10:05:34 PAGE 4   

 179   1              i2c_start();
 180   1              i2c_write(bSLA);
 181   1              i2c_write(bREG);
 182   1      
 183   1              i2c_start();
 184   1              i2c_write(bSLA | 0x01);
 185   1              
 186   1              ipr_data_in = i2c_read();
 187   1              i2c_stop();
 188   1              return ipr_data_in;
 189   1      }
 190          


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