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

📄 i2c.lst

📁 利用超级终端调TFT液晶驱动和一个I2C调试工具。
💻 LST
字号:
C51 COMPILER V7.20   I2C                                                                   01/19/2006 13:31:03 PAGE 1   


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

line level    source

   1          #include "reg52.h"
   2          #include "define.h"
   3          #include "i2c.h"
   4          
   5          
   6          /****************************************************************************
   7             Project    : LCD Display
   8             Version    : 1.0
   9             File Name  : VP_IIC.c
  10             Functions  : i2c interface routine
  11             Revision   :
  12          
  13             1999-05-18  OriginalTeam    First Created
  14             2005-01-25  Alf Hsu         Modified for Vipor
  15             2005-03-08  Alf Hsu         Released Version 1.0
  16          ****************************************************************************/
  17          
  18          /**************************************************************************/
  19          /* INCLUDE FILES                                                          */
  20          /**************************************************************************/
  21           
  22          #include  <intrins.h>
  23          /**************************************************************************/
  24          /**************************************************************************/
  25          #define  SUCCESS   0
  26          #define  FAILURE   1
  27          
  28          
  29          /**************************************************************************/
  30          /**************************************************************************/
  31          extern Bool  WriteI2CData(Byte,Byte,Byte);
  32          extern BYTE  ReadI2CData(Byte,Byte,Byte);
  33          
  34          extern Bool  IIC_SendByte(Byte);
  35          extern Byte  IIC_ReadByte(Bool);
  36          extern void  IIC_Start(void);
  37          extern void  IIC_Stop(void);
  38          
  39          
  40          Byte   TrmBuf[16];
  41          
  42          /**************************************************************************/
  43          /**************************************************************************/
  44          #if  0//(VIPOR_CHIP==VP77)
              void IIC_NOP(Byte max)
              {
                 #if (CPU_DOUBLE_RATE==2)
                   Byte i;
              
                   max = max<<1;
                   for(i=0; i<max; i++)
                   {
                      _nop_();
                   }
                 #else
C51 COMPILER V7.20   I2C                                                                   01/19/2006 13:31:03 PAGE 2   

                   max = 0;
                 #endif
              }
              #else
  60            #define IIC_NOP(val)
  61          #endif
  62          #define IIC_ByteDelay()
  63          /**************************************************************************/
  64          /**************************************************************************/
  65          Bool  WriteI2CData(Byte slv_addr,Byte base_addr,Byte cValue)
  66          {
  67   1          Byte  i,j;
  68   1          Bool  no_ack,fg_base_addr,fg_eeprom;
  69   1          Bool  fg_Byte_delay=1;
  70   1              
  71   1              Byte Byte_cnt = 1;
  72   1          no_ack = 1;
  73   1          fg_eeprom     = (slv_addr & 0xA0)==0xA0 ? 1 : 0;
  74   1          fg_base_addr  = (Byte_cnt & IIC_NO_BASE_ADDR)==0x00 ? 1 : 0;
  75   1          Byte_cnt &= 0x0F;
  76   1          for( i=0; i<10; i++)  /* retry for 10 times */
  77   1          {
  78   2             IIC_NOP(10);
  79   2             IIC_Start();
  80   2             if( IIC_SendByte(slv_addr) )
  81   2             {
  82   3                 IIC_Stop();
  83   3                 if( fg_eeprom )  ShortDelay(5);
  84   3                 continue;
  85   3             }
  86   2             if( fg_Byte_delay )  IIC_ByteDelay();
  87   2      
  88   2             if( fg_base_addr )
  89   2             {
  90   3                if( IIC_SendByte(base_addr) != SUCCESS )
  91   3                {
  92   4                    IIC_Stop();
  93   4                    if( fg_eeprom )  ShortDelay(5);
  94   4                    continue;
  95   4                }
  96   3                if( fg_Byte_delay )  IIC_ByteDelay();
  97   3             }
  98   2      
  99   2             no_ack = 0;
 100   2             for(j=0; j<Byte_cnt; j++)
 101   2             {
 102   3                if( IIC_SendByte(cValue) != SUCCESS )
 103   3                {
 104   4                   no_ack = 1;
 105   4                   break;
 106   4                }
 107   3                if( fg_Byte_delay )  IIC_ByteDelay();
 108   3             }
 109   2             IIC_Stop();
 110   2             if( no_ack==0 )  break;    /* complete */
 111   2             if( fg_eeprom )  ShortDelay(5);
 112   2          }
 113   1          return  no_ack;
 114   1      }
 115          /**************************************************************************/
 116          /**************************************************************************/
 117          BYTE  ReadI2CData(Byte slv_addr,Byte base_addr,Byte Byte_cnt)
C51 COMPILER V7.20   I2C                                                                   01/19/2006 13:31:03 PAGE 3   

 118          {
 119   1          Byte  i,j;
 120   1          Bool  no_ack,fg_base_addr,fg_last_Byte;
 121   1          Bool  fg_Byte_delay=1;
 122   1              BYTE  cValue;
 123   1              
 124   1              Byte_cnt = 1;
 125   1          no_ack = 1;
 126   1          fg_base_addr  = (Byte_cnt & IIC_NO_BASE_ADDR)==0x00 ? 1 : 0;
 127   1          Byte_cnt &= 0x0F;
 128   1          for( i=0; i<10; i++)  /* retry for 10 times */
 129   1          {
 130   2             IIC_NOP(10);
 131   2             if( fg_base_addr )
 132   2             {
 133   3                IIC_Start();
 134   3                if( IIC_SendByte(slv_addr) )
 135   3                {
 136   4                    IIC_Stop();
 137   4                    continue;
 138   4                }
 139   3                if( fg_Byte_delay )  IIC_ByteDelay();
 140   3      
 141   3                if( IIC_SendByte(base_addr) != SUCCESS )
 142   3                {
 143   4                    IIC_Stop();
 144   4                    continue;
 145   4                }
 146   3                if( fg_Byte_delay )  IIC_ByteDelay();
 147   3             }
 148   2             else  // IIC_NO_BASE_ADDR, check base_addr for sub_address count in TrmBuf[4..n]
 149   2             {
 150   3                if( base_addr!=0 )
 151   3                {
 152   4                   IIC_Start();
 153   4                   if( IIC_SendByte(slv_addr) )
 154   4                   {
 155   5                       IIC_Stop();
 156   5                       continue;
 157   5                   }
 158   4                   if( fg_Byte_delay )
 159   4                   {
 160   5                       IIC_ByteDelay();
 161   5                   }
 162   4      
 163   4                   no_ack = 0;
 164   4                   for(j=0; j<base_addr; j++)
 165   4                   {
 166   5                      if( IIC_SendByte(TrmBuf[4+j]) != SUCCESS )
 167   5                      {
 168   6                          no_ack = 1;
 169   6                          break;
 170   6                      }
 171   5                      if( fg_Byte_delay )  IIC_ByteDelay();
 172   5                   }
 173   4                   if( j!=base_addr )
 174   4                   {
 175   5                      IIC_Stop();
 176   5                      continue;
 177   5                   }
 178   4                }
 179   3             }
C51 COMPILER V7.20   I2C                                                                   01/19/2006 13:31:03 PAGE 4   

 180   2      
 181   2             IIC_Start();
 182   2             if( IIC_SendByte(slv_addr+1) )
 183   2             {
 184   3                IIC_Stop();
 185   3                continue;
 186   3             }
 187   2             if( fg_Byte_delay )  IIC_ByteDelay();
 188   2      
 189   2             for(j=0; j<Byte_cnt; j++)
 190   2             {
 191   3                fg_last_Byte = (j==(Byte_cnt-1)) ? 1 : 0;
 192   3                cValue = IIC_ReadByte(fg_last_Byte);
 193   3                if( fg_Byte_delay )  IIC_ByteDelay();
 194   3             }
 195   2             IIC_Stop();
 196   2      
 197   2             no_ack = 0;
 198   2             break;
 199   2          }
 200   1          return  cValue;
 201   1      }
 202          /**************************************************************************/
 203          /**************************************************************************/
 204          Bool IIC_SendByte(Byte bval)
 205          {
 206   1          Byte  i;
 207   1          Bool  no_ack = 0;
 208   1      
 209   1          IIC_NOP(4);
 210   1          for(i=8; i!=0; i--)
 211   1          {
 212   2              SDA_PIN = (bval & 0x80);
 213   2              _nop_();
 214   2              IIC_NOP(2);
 215   2              SCL_PIN = 1;
 216   2              bval <<= 1;
 217   2              IIC_NOP(2);
 218   2              SCL_PIN = 0;
 219   2              IIC_NOP(2);
 220   2          }
 221   1          SDA_PIN = 1;
 222   1          _nop_();
 223   1          _nop_();
 224   1          IIC_NOP(2);
 225   1          SCL_PIN = 1;
 226   1          for(i=64; i!=0; i--)
 227   1          {
 228   2             IIC_NOP(2);
 229   2             if( SDA_PIN==0 )  break;
 230   2          }
 231   1          if( i==0 )  no_ack = 1;
 232   1          IIC_NOP(2);
 233   1          SCL_PIN = 0;
 234   1          _nop_();
 235   1          _nop_();
 236   1          IIC_NOP(2);
 237   1          SDA_PIN = 0;
 238   1      
 239   1          return  no_ack;
 240   1      }
 241          /**************************************************************************/
C51 COMPILER V7.20   I2C                                                                   01/19/2006 13:31:03 PAGE 5   

 242          /**************************************************************************/
 243          Byte IIC_ReadByte(Bool fg_last_Byte)
 244          {
 245   1          Byte  i,bval;
 246   1      
 247   1          bval = 0;
 248   1      
 249   1          IIC_NOP(4);
 250   1          SDA_PIN = 1;
 251   1          IIC_NOP(4);  // It's necessary
 252   1          for(i=0; i<8; i++)
 253   1          {
 254   2             SCL_PIN = 1;
 255   2             IIC_NOP(2);
 256   2             bval = bval << 1;
 257   2             if( SDA_PIN )  bval |= 0x01;
 258   2             IIC_NOP(2);
 259   2             SCL_PIN = 0;
 260   2             _nop_();
 261   2             _nop_();
 262   2             _nop_();
 263   2             IIC_NOP(2);
 264   2          }
 265   1          if( fg_last_Byte )  SDA_PIN = 1;
 266   1          else                SDA_PIN = 0;
 267   1          _nop_();
 268   1          IIC_NOP(1);
 269   1          SCL_PIN = 1;
 270   1          _nop_();
 271   1          _nop_();
 272   1          _nop_();
 273   1          _nop_();
 274   1          IIC_NOP(4);
 275   1          SCL_PIN = 0;
 276   1          _nop_();
 277   1          IIC_NOP(1);
 278   1          SDA_PIN = 1;
 279   1      
 280   1          return bval;
 281   1      }
 282          /**************************************************************************/
 283          /**************************************************************************/
 284          void IIC_Start(void)
 285          {
 286   1          SDA_PIN = 1;
 287   1          _nop_();
 288   1          IIC_NOP(1);
 289   1          SCL_PIN = 1;
 290   1          _nop_();
 291   1          _nop_();
 292   1          _nop_();
 293   1          _nop_();
 294   1          IIC_NOP(4);
 295   1          SDA_PIN = 0;
 296   1          _nop_();
 297   1          _nop_();
 298   1          _nop_();
 299   1          _nop_();
 300   1          IIC_NOP(4);
 301   1          SCL_PIN = 0;
 302   1          IIC_NOP(4);
 303   1      }
C51 COMPILER V7.20   I2C                                                                   01/19/2006 13:31:03 PAGE 6   

 304          /**************************************************************************/
 305          /**************************************************************************/
 306          void IIC_Stop(void)
 307          {
 308   1          SDA_PIN = 0;
 309   1          _nop_();
 310   1          IIC_NOP(1);
 311   1          SCL_PIN = 1;
 312   1          _nop_();
 313   1          _nop_();
 314   1          _nop_();
 315   1          _nop_();
 316   1          IIC_NOP(4);
 317   1          SDA_PIN = 1;
 318   1          _nop_();
 319   1          _nop_();
 320   1          _nop_();
 321   1          _nop_();
 322   1          IIC_NOP(4);
 323   1      }
 324          /************************************************************************/
 325          /************************************************************************/
 326          void ShortDelay(Byte count)
 327          {
 328   1          Byte  i,j;
 329   1      #if 1//(CPU_DOUBLE_RATE==0)
 330   1         for(i=0; i<count; i++)
 331   1         {
 332   2            for(j=0; j<169; j++)
 333   2            {
 334   3               _nop_();
 335   3               _nop_();
 336   3            }
 337   2         }
 338   1      #else
                 for(i=0; i<count; i++)
                 {
                    for(j=0; j<204; j++)
                    {
                       _nop_();
                       _nop_();
                       _nop_();
                       _nop_();
                       _nop_();
                       _nop_();
                    }
                 }
              #endif
 352   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    469    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     16      12
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----      10
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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