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

📄 i2c.lst

📁 此程序为twell8806驱动程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.50   I2C                                                                   08/20/2007 10:23:30 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 COMPACT OPTIMIZE(9,SIZE)

line level    source

   1          //-------------------------------------------------------------
   2          //      This is changed for sdcc compiler 2.2.0a        LJY000721
   3          //  ver0.11 2/20/2001   Support Z86129 Line 21 decoder.
   4          //-------------------------------------------------------------
   5          /*#include <io51.h>*/
   6          //#include <pk-51.h>    LJY000721
   7          
   8          #include "Config.h"
   9          
  10          #include "reg.h"
  11          #include "typedefs.h"
  12          #include "I2C.h"
  13          #include "main.h"
  14          #include "debug.h"
  15          #include "printf.h"
  16          #include "osdbasic.h"
  17          
  18          #define I2C_SCL         P1_0
  19          #define I2C_SDA         P1_1
  20          
  21          #define ID_ADDR         0xc5
  22          #define ID_DATA         0xc6
  23          
  24          extern  PDATA BYTE      DebugLevel;
  25          
  26          ///extern IDATA BYTE adc_i2c_address, CurrentADC;
  27          //IDATA BYTE I2CAddr, I2CIdx, I2CData;
  28          
  29          /*****************************************************************************/
  30          /*                                                                           */
  31          /*****************************************************************************/
  32          #define I2C_FAST
  33          
  34          #ifdef I2C_FAST
  35           #define I2Cdelay()
  36          #else
               void I2Cdelay(void)
               {
                       BYTE i;
                       for(i=0; i<1; i++){
                       }
               }
              #endif
  44          
  45          #if (defined  QVGA) || (defined WQVGA)
  46          void I2C_delay(void)
  47          {
  48   1               BYTE i;
  49   1               for(i=0; i<255; i++){
  50   2                      i=i;
  51   2               }
  52   1               for(i=0; i<128; i++){
  53   2                      i=i;
  54   2               }
  55   1      }
C51 COMPILER V7.50   I2C                                                                   08/20/2007 10:23:30 PAGE 2   

  56          #else
               #define I2C_delay() 
              #endif
  59          
  60          BYTE I2CWriteData_Wait(BYTE value);
  61          
  62          void WriteTW88(BYTE index, BYTE dat)
  63          {
  64   1              BYTE addr = TW88I2CAddress;
  65   1      
  66   1              #ifdef DEBUG_I2C
                      if( DebugLevel==0xff )
                              Printf("Write %02xh to [Adrs(%02xh)Index(%02xh)]\n\r", (WORD)dat, (WORD)addr, (WORD)index);
                      #endif
  70   1      
  71   1              I2CStart();
  72   1              I2CWriteData(addr);
  73   1              I2CWriteData(index);
  74   1              I2CWriteData(dat);
  75   1              I2CStop();
  76   1      }
  77          
  78          /* For testing chip.............................
  79          BYTE WriteTW88_Wait(BYTE index, BYTE dat)
  80          {
  81                  #ifdef DEBUG_I2C
  82                  if( DebugLevel==0xff )
  83                          Printf("Write %02xh to [Adrs(%02xh)Index(%02xh)]\n\r", (WORD)dat, (WORD)TW88I2CAddress, (WORD)index);
  84                  #endif
  85          
  86                  I2CStart();
  87                  if( !I2CWriteData_Wait(TW88I2CAddress & 0xFE) ) 
  88                          return 0;
  89                  if( !I2CWriteData_Wait(index) )
  90                          return 0;
  91                  if( !I2CWriteData_Wait(dat) )
  92                          return 0;
  93                  I2CStop();
  94                  return 1;
  95          
  96          }
  97          */
  98          
  99          BYTE ReadTW88(BYTE index)
 100          {
 101   1              BYTE val;
 102   1              BYTE addr = TW88I2CAddress;
 103   1      
 104   1              I2CStart();
 105   1              I2CWriteData(addr);
 106   1              I2CWriteData(index);
 107   1              I2CStart();
 108   1              I2CWriteData(addr | 0x01);
 109   1              val = I2CReadData();
 110   1              I2CStop();
 111   1      
 112   1              #ifdef DEBUG_I2C
                      if( DebugLevel==0xff )
                              Printf("Read [Adrs:%02xh,Index:%02xh] %02xh\r\n", (WORD)addr, (WORD)index, (WORD)val);
                      #endif
 116   1      
 117   1              return val;
C51 COMPILER V7.50   I2C                                                                   08/20/2007 10:23:30 PAGE 3   

 118   1      }
 119          
 120          #if defined( SUPPORT_PC ) || defined( SUPPORT_DTV )
 121          void WriteADC(BYTE index, BYTE dat)
 122          {
 123   1              //#ifdef DEBUG_OSD
 124   1              //if( DebugLevel==0xff )
 125   1      //              Printf("Write ADC %02xh to [Adrs(%02xh)Index(%02xh)\r\n", (WORD)dat, (WORD)ADCI2CAddress, (WORD)index 
             -);
 126   1              //#endif
 127   1      
 128   1              WriteTW88(ID_ADDR, index);      
 129   1              WriteTW88(ID_DATA, dat);        
 130   1      
 131   1      }
 132          
 133          BYTE ReadADC(BYTE index)
 134          {
 135   1              BYTE val, val1;
 136   1      
 137   1              val1=ReadTW88(0xb0);
 138   1              WriteTW88(0xb0, val1|0x80);     
 139   1      
 140   1              WriteTW88(ID_ADDR, index);      
 141   1              WriteTW88(ID_ADDR, index);      
 142   1              val = ReadTW88(ID_DATA);
 143   1      
 144   1              WriteTW88(0xb0, val1&0x7f);     
 145   1      
 146   1              //#ifdef DEBUG_OSD
 147   1              //if( DebugLevel==0xff )
 148   1      //              Printf("Read ADC[Adrs:%02xh,Index:%02xh] %02xh\r\n", (WORD)TW88I2CAddress, (WORD)index, (WORD)val);
 149   1              //#endif
 150   1              
 151   1              return val;
 152   1      }
 153          #endif  // SUPPORT_PC
 154          
 155          void WriteEEP(WORD index, BYTE dat)
 156          {
 157   1              BYTE addr;
 158   1      
 159   1              addr = (EEPROMI2CAddress | (index>>7)) & 0xfe;
 160   1      
 161   1              I2CStart();
 162   1              I2CWriteData(addr);
 163   1              I2CWriteData((BYTE)index);
 164   1              I2CWriteData(dat);
 165   1              I2CStop();
 166   1      
 167   1              #ifdef DEBUG_OSD
                      if( DebugLevel==0xff )
                              Printf("Write %02xh to [Adrs(%02xh)Index(%02xh)\r\n", (WORD)dat, (WORD)addr, (WORD)index );
                      #endif
 171   1      
 172   1              delay(2);
 173   1      }
 174          
 175          BYTE ReadEEP(WORD index)
 176          {
 177   1              BYTE val;
 178   1              BYTE addr;
C51 COMPILER V7.50   I2C                                                                   08/20/2007 10:23:30 PAGE 4   

 179   1      
 180   1              addr = (EEPROMI2CAddress | (index>>7)) & 0xfe;
 181   1      
 182   1              val = ReadI2C(addr,(BYTE)index);
 183   1      
 184   1              #ifdef DEBUG_OSD
                      if( DebugLevel==0xff )
                              Printf("Read [Adrs:%02xh,Index:%02xh] %02xh\r\n", (WORD)addr, (WORD)index, (WORD)val);
                      #endif
 188   1      
 189   1              return val;
 190   1      }
 191          
 192          BYTE ReadI2C(BYTE addr, BYTE index)
 193          {
 194   1              BYTE val;
 195   1      
 196   1              I2CStart();
 197   1              I2CWriteData(addr);
 198   1              I2CWriteData(index);
 199   1              I2CStart();
 200   1              I2CWriteData(addr | 0x01);
 201   1              val = I2CReadData();
 202   1              I2CStop();
 203   1      
 204   1              return val;
 205   1      }
 206          
 207          
 208          void WriteI2C(BYTE addr, BYTE index, BYTE val)
 209          {
 210   1              I2CStart();
 211   1              I2CWriteData(addr);
 212   1              I2CWriteData(index);
 213   1              I2CWriteData(val);
 214   1              I2CStop();
 215   1      }
 216          
 217          void WriteI2CnD(BYTE addr, BYTE index, BYTE val, BYTE cnt)
 218          {
 219   1              BYTE i;
 220   1      
 221   1              I2CStart();
 222   1              I2CWriteData(addr);
 223   1              I2CWriteData(index);
 224   1      
 225   1              for(i=0; i<cnt; i++){
 226   2                      I2CWriteData(val);              //LJY050101
 227   2                      I2C_delay();
 228   2              }
 229   1      
 230   1              I2CStop();
 231   1      }
 232          
 233          void WriteI2Cn(BYTE addr, BYTE index, BYTE *val, BYTE cnt)
 234          {
 235   1              BYTE i;
 236   1      
 237   1              I2CStart();
 238   1              I2CWriteData(addr);
 239   1              I2CWriteData(index);
 240   1      
C51 COMPILER V7.50   I2C                                                                   08/20/2007 10:23:30 PAGE 5   

 241   1              for(i=0; i<cnt; i++){
 242   2                      I2CWriteData(*(val+i)); 
 243   2                      I2C_delay();
 244   2              }
 245   1              I2CStop();
 246   1      }
 247          
 248          BYTE WriteI2Cn_(BYTE addr, BYTE *val, BYTE cnt)
 249          {
 250   1              BYTE rd=1, i;
 251   1      
 252   1              I2CStart();
 253   1              I2CWriteData(addr);
 254   1      
 255   1              for(i=0; i<cnt; i++){
 256   2                      I2CWriteData(*(val+i));         //LJY050101
 257   2              }
 258   1              I2CStop();
 259   1      
 260   1              return rd;
 261   1      }
 262          
 263          //BYTE I2CWriteData_Wait(BYTE value);
 264          void I2CReadByteMSP(BYTE addr, BYTE index, BYTE *pd, BYTE cnt)
 265          {
 266   1              BYTE i;
 267   1      
 268   1              I2CStart();
 269   1              I2CWriteData_Wait(addr);
 270   1              I2CWriteData(index);
 271   1              for(i=0; i<cnt; i++) {
 272   2                      I2CWriteData(*(pd+i));
 273   2              }
 274   1              I2CStart();
 275   1              I2CWriteData_Wait(addr | 0x01);
 276   1              *pd = I2CReadDataWithACK();
 277   1              *(pd+1) = I2CReadData();
 278   1      
 279   1              I2CStop();
 280   1      }
 281          
 282          #ifdef DEBUG_TV
              BYTE ReadI2CStatus( BYTE addr )
              {
                      BYTE val;
              
                      I2CStart();
                      I2CWriteData(addr | 0x01);
                      val = I2CReadData();
                      I2CStop();
              
                      return val;
              }
              #endif // DEBUG_TV
 295          
 296          
 297          #ifdef SERIAL
 298          BYTE I2CReadDataWithNAK(void)
 299          {
 300   1              return I2CReadData();

⌨️ 快捷键说明

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