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

📄 twowire.lst

📁 T112 MCU源程码,用于T112外接MCU篇程,用来驱动模拟屏
💻 LST
📖 第 1 页 / 共 3 页
字号:
C51 COMPILER V7.06   TWOWIRE                                                               03/01/2007 08:05:39 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE TWOWIRE
OBJECT MODULE PLACED IN TWOWIRE.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE source\TWOWIRE.C BROWSE INCDIR(Z:\CB\T112项目\原始资料\AV总备份\1.8\include
                    -\) DEBUG OBJECTEXTEND PRINT(.\TWOWIRE.lst) OBJECT(TWOWIRE.obj)

stmt 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 "System.h"
  18                                          #include "TW10xReg.h"
  19                                          #include "TwoWire.h"
  20          
  21          
  22                                          #define TW_SLOW_SPEED
  23                                          //----------------------------------------
  24                                          // S_Condition for TWD protocol
  25                                          //----------------------------------------
  26                                          #if defined(TW_SLOW_SPEED)
  27                                          void StartCondition(void)
  28                                          {
  29   1                                          uCHAR ix;
  30   1                                          uCHAR cTWtrytime=0;
  31   1                                          EA=0;
  32   1                                          while(++cTWtrytime)
  33   1                                          {
  34   2                                              Set_SDA_High;
  35   2                                              Set_SCL_High;        /* make sure two line is release */
  36   2                                              for(ix = 0; ix < TWD_LONG_TIME; ix++)
  37   2                                              { };  /* Delay 12us */
  38   2                                      
  39   2                                              Set_SDA_Low;
  40   2                                              for(ix = 0; ix < TWD_LONG_TIME; ix++)
  41   2                                              { };  /* Delay 12us */
  42   2                                      
  43   2                                              if((SCL_High)&&(SDA_Low))
  44   2                                                  break;
  45   2                                          }
  46   1                                      
  47   1                                          for(ix = 0; ix < TWD_SHORT_TIME; ix++)
  48   1                                          { };  /* Delay 12us */
  49   1                                      }
  50                                          
  51                                          //----------------------------------------
  52                                          // P_Condition for TWD protocol
  53                                          //----------------------------------------
  54                                          void StopCondition(void)
C51 COMPILER V7.06   TWOWIRE                                                               03/01/2007 08:05:39 PAGE 2   

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

 117   1                                      
 118   1                                          Set_SCL_High;                /* Send a clock for Acknowledge */
 119   1                                          while(SCL_Low)
 120   1                                          { };
 121   1                                          for(j = 0; j < TWD_SHORT_TIME; j++)
 122   1                                          { };
 123   1                                      
 124   1                                          if(SDA_High) 
 125   1                                             cAcknowledge = 1; /* No Acknowledge */
 126   1                                          Set_SCL_Low;                   /* Finish Acknoledge */
 127   1                                          for(j = 0; j < TWD_SHORT_TIME; j++)
 128   1                                          { };
 129   1                                      
 130   1                                          return(cAcknowledge);
 131   1                                      }
 132                                          
 133                                          //--------------------------------------------------
 134                                          // Read_Byte
 135                                          //    Read a byte from master with a acknowledge bit
 136                                          //--------------------------------------------------
 137                                          uCHAR Read_Byte(uCHAR cNum)
 138                                          {
 139   1                                          uCHAR ix, j;
 140   1                                          uCHAR cRetval=0;
 141   1                                      
 142   1                                          for(ix=0;ix<8;ix++){
 143   2                                                Set_SCL_High;
 144   2                                                while(SCL_Low){};
 145   2                                                for(j=0;j<TWD_SHORT_TIME;j++){};
 146   2                                                cRetval = (SDA_High)? (cRetval|(1<<(7-ix))):cRetval ;  /* MSB First */

⌨️ 快捷键说明

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