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

📄 twowire.lst

📁 terawin的t103 LCD驱动程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.50   TWOWIRE                                                               10/30/2006 16:14:40 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE TWOWIRE
OBJECT MODULE PLACED IN .\Obj\TWOWIRE.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE Source\Comm\TWOWIRE.C LARGE OPTIMIZE(6,SPEED) BROWSE INCDIR(.\Include\;.\So
                    -urce\;.\Include\Panel\;.\Include\GammaTable\;.\Include\tuner\) DEFINE(T103) DEBUG OBJECTEXTEND PRINT(.\TWOWIRE.lst) OBJE
                    -CT(.\Obj\TWOWIRE.obj)

line level    source

   1          //---------------------------------------------------------------------------
   2          // Terawins Inc. Company Confidential Strictly Private
   3          //
   4          // $Archive: $
   5          // $Revision: 1.9 $
   6          // $Author: jwang $
   7          // $Date: 2002/07/08 22:34:39 $
   8          //
   9          // --------------------------------------------------------------------------
  10          // >>>>>>>>>>>>>>>>>>>>>>>>> COPYRIGHT NOTICE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  11          // --------------------------------------------------------------------------
  12          // Copyright 2002 (c) Terawins Inc.
  13          // --------------------------------------------------------------------------
  14          
  15          #include "reg51.h"
  16          #include "common.h"
  17          #include "struct.h"
  18          #include "TW803Reg.h"
  19          #include "TwoWire.h"
  20          #include "SRC_ctrl.h"
  21          //#include "Global.h"
  22          //#include "System.h"
  23          
  24          #define TW_SLOW_SPEED
  25          //----------------------------------------
  26          // S_Condition for TWD protocol
  27          //----------------------------------------
  28          #if defined(TW_SLOW_SPEED)
  29          void StartCondition(void)
  30          {
  31   1          uCHAR ix;
  32   1          uCHAR cTWtrytime=0;
  33   1          ET0=0;
  34   1          while(++cTWtrytime)
  35   1          {
  36   2              Set_SDA_High;
  37   2              Set_SCL_High;        /* make sure two line is release */
  38   2              for(ix = 0; ix < TWD_LONG_TIME; ix++)
  39   2              { };  /* Delay 12us */
  40   2      
  41   2              Set_SDA_Low;
  42   2              for(ix = 0; ix < TWD_LONG_TIME; ix++)
  43   2              { };  /* Delay 12us */
  44   2      
  45   2              if((SCL_High)&&(SDA_Low))
  46   2                  break;
  47   2          }
  48   1      
  49   1          for(ix = 0; ix < TWD_SHORT_TIME; ix++)
  50   1          { };  /* Delay 12us */
  51   1      }
  52          
  53          //----------------------------------------
C51 COMPILER V7.50   TWOWIRE                                                               10/30/2006 16:14:40 PAGE 2   

  54          // P_Condition for TWD protocol
  55          //----------------------------------------
  56          void StopCondition(void)
  57          {
  58   1          uCHAR ix;
  59   1          uCHAR cTWtrytime=0;
  60   1      
  61   1          Set_SDA_Low;
  62   1          Set_SCL_High;
  63   1          for(ix = 0; ix < TWD_SHORT_TIME; ix++)
  64   1          { };  /* delay 12us */
  65   1      
  66   1          while(SCL_Low && ++cTWtrytime)
  67   1          { };
  68   1      
  69   1          for(ix = 0; ix < TWD_SHORT_TIME; ix++)
  70   1          { };  /* delay 12us */
  71   1      
  72   1          Set_SDA_High;
  73   1          for(ix = 0; ix < TWD_SHORT_TIME; ix++)
  74   1          { };  /* delay 12us */
  75   1              ET0=1;
  76   1      }
  77          
  78          //--------------------------------------------------
  79          // Send_Byte
  80          //    Send a byte to master with a acknowledge bit
  81          //--------------------------------------------------
  82          uCHAR Send_Byte(uCHAR cData)
  83          {
  84   1          uCHAR ix, j, cAcknowledge;
  85   1          uCHAR cTWtrytime=0;
  86   1      
  87   1          cAcknowledge = 0;
  88   1      
  89   1          for(ix = 0; ix < 8; ix++)
  90   1          {
  91   2              Set_SCL_Low;
  92   2              for(j = 0; j < TWD_SHORT_TIME; j++)
  93   2              { };
  94   2      
  95   2              if(cData&0x80)Set_SDA_High;
  96   2                      else Set_SDA_Low;
  97   2                      cData<<=1;
  98   2      
  99   2              for(j = 0; j < TWD_SHORT_TIME; j++)
 100   2              { };
 101   2      
 102   2              Set_SCL_High;
 103   2              while(SCL_Low && ++cTWtrytime)
 104   2              { };
 105   2      
 106   2              for(j = 0; j < TWD_SHORT_TIME; j++)
 107   2              { };
 108   2          }
 109   1          for(j = 0; j < TWD_SHORT_TIME; j++)
 110   1          { };
 111   1      
 112   1          Set_SCL_Low;
 113   1          for(j = 0; j < TWD_SHORT_TIME; j++)
 114   1          { };
 115   1      
C51 COMPILER V7.50   TWOWIRE                                                               10/30/2006 16:14:40 PAGE 3   

 116   1          Set_SDA_High;                /* release data line for acknowledge */
 117   1          for(j = 0; j < TWD_SHORT_TIME; j++)
 118   1          { };
 119   1      
 120   1          Set_SCL_High;                /* Send a clock for Acknowledge */
 121   1          while(SCL_Low)
 122   1          { };
 123   1          for(j = 0; j < TWD_SHORT_TIME; j++)
 124   1          { };
 125   1      
 126   1          if(SDA_High) 
 127   1             cAcknowledge = 1; /* No Acknowledge */
 128   1          Set_SCL_Low;                   /* Finish Acknoledge */
 129   1          for(j = 0; j < TWD_SHORT_TIME; j++)
 130   1          { };
 131   1      
 132   1          return(cAcknowledge);
 133   1      }
 134          
 135          
 136          /*uCHAR Send_Byte1(uCHAR cData)
 137          {
 138              uCHAR ix, j, cAcknowledge;
 139              uCHAR cTWtrytime=0;
 140          
 141              cAcknowledge = 0;
 142          
 143              for(ix = 0; ix < 8; ix++)
 144              {
 145           
 146          
 147                    if(cData&0x80)Set_SDA_High;
 148                          else Set_SDA_Low;
 149                          cData<<=1;
 150               Set_SCL_High;   
 151                  for(j = 0; j < TWD_SHORT_TIME; j++)
 152                  { };
 153          
 154                  Set_SCL_Low;
 155            
 156          
 157                  for(j = 0; j < TWD_SHORT_TIME; j++)
 158                  { };
 159              }
 160           
 161          
 162           
 163              return(1);
 164          }*/
 165          //--------------------------------------------------
 166          // Read_Byte
 167          //    Read a byte from master with a acknowledge bit
 168          //--------------------------------------------------
 169          uCHAR Read_Byte(uCHAR cNum)
 170          {
 171   1          uCHAR ix, j;
 172   1          uCHAR cRetval=0;
 173   1      
 174   1          for(ix=0;ix<8;ix++){
 175   2                Set_SCL_High;
 176   2                while(SCL_Low){};
 177   2                for(j=0;j<TWD_SHORT_TIME;j++){};
C51 COMPILER V7.50   TWOWIRE                                                               10/30/2006 16:14:40 PAGE 4   

 178   2                cRetval = (SDA_High)? (cRetval|(1<<(7-ix))):cRetval ;  /* MSB First */
 179   2                Set_SCL_Low;
 180   2           }
 181   1      
 182   1           if(cNum==1)
 183   1              Set_SDA_High;
 184   1           else
 185   1                      Set_SDA_Low;
 186   1           //SDA = (cNum==1) 1:0;
 187   1           Set_SCL_High;
 188   1           while(SCL_Low){};
 189   1           for(j = 0; j < TWD_SHORT_TIME; j++)
 190   1           { };
 191   1      
 192   1          Set_SCL_Low;
 193   1      
 194   1          Set_SDA_High;
 195   1          for(j = 0; j < TWD_SHORT_TIME; j++)
 196   1          { };
 197   1      
 198   1          return cRetval;
 199   1      }
 200          
 201          #else
              // for fast Two Wire Bus Speed
              
              void StartCondition(void)
              {
              //    uCHAR ix;
                  uCHAR cTWtrytime=0;
              
                  while(++cTWtrytime)
                  {
                      Set_SDA_High;
                      Set_SCL_High;        /* make sure two line is release */
              
                      Set_SDA_Low;
              
                      if((SCL_High)&&(SDA_Low))
                          break;
                  }
              }
              
              //----------------------------------------
              // P_Condition for TWD protocol
              //----------------------------------------
              void StopCondition(void)
              {
              //    uCHAR ix;
                  uCHAR cTWtrytime=0;
              
                  Set_SDA_Low;
                  Set_SCL_High;
              
                  Set_SDA_High;
              }
              
              //--------------------------------------------------
              // Send_Byte
              //    Send a byte to master with a acknowledge bit
              //--------------------------------------------------
              uCHAR Send_Byte(uCHAR cData)
C51 COMPILER V7.50   TWOWIRE                                                               10/30/2006 16:14:40 PAGE 5   

              {
                  uCHAR ix;
                  uCHAR cAcknowledge;
                  uCHAR cTWtrytime=0;
              
                  cAcknowledge = 0;
              
                  for(ix = 0; ix < 8; ix++)
                  {
                      Set_SCL_Low;
                      //        (cData&(1<<(7-ix)))?(Set_SDA_High):(Set_SDA_Low);  /* MSB First */
                      if(cData&0x80)Set_SDA_High;
                              else Set_SDA_Low;
                              cData<<=1;
              
              
                      Set_SCL_High;
                  }
              
                  Set_SCL_Low;
                  Set_SDA_High;                /* release data line for acknowledge */
                  Set_SCL_High;                /* Send a clock for Acknowledge */
              
                  if(SDA_High) cAcknowledge = 1; /* No Acknowledge */
                  Set_SCL_Low;                   /* Finish Acknoledge */
              
                  return(cAcknowledge);
              }
              
              
              
              
              //--------------------------------------------------
              // Read_Byte
              //    Read a byte from master with a acknowledge bit
              //--------------------------------------------------
              uCHAR Read_Byte(void)
              {
                  uCHAR ix, j;
                  uCHAR cRetval;
                  uCHAR cTWtrytime=0;
              
              //    cRetval = 0;
                  Set_SDA_High;
              
                  for(ix = 0; ix < 8; ix++)
                  {
                      Set_SCL_Low;
                      for(j = 0; j < TWD_SHORT_TIME; j++)
                      { };
              
                      Set_SCL_High;
                      while(SCL_Low)
                      { };
              
                      for(j = 0; j < TWD_SHORT_TIME; j++)
                      { };
              
                              cRetval<<=1;
                              if(SDA_High) cRetval++;
                      }
              
C51 COMPILER V7.50   TWOWIRE                                                               10/30/2006 16:14:40 PAGE 6   

                  for(j = 0; j < TWD_SHORT_TIME; j++)
                  { };
              
                  Set_SCL_Low;
                  for(j = 0; j < TWD_SHORT_TIME; j++)
                  { };
              
                  return cRetval;
              }
              
              
              #endif
 314          
 315          //--------------------------------------------------
 316          // Write Byte to Device
 317          //--------------------------------------------------
 318          
 319          //--------------------------------------------------
 320          // Read Byte to Device
 321          //--------------------------------------------------
 322          uCHAR I2CReadByte(uCHAR cDevAddr, uCHAR cReg)
 323          {
 324   1          uCHAR cResult = 0;
 325   1      
 326   1      
 327   1          /* write reg offset */
 328   1          StartCondition();
 329   1          if(Send_Byte(cDevAddr))
 330   1              return 0;  // Write address

⌨️ 快捷键说明

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