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

📄 twowire.lst

📁 terawin的t103 LCD驱动程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
 331   1          if(Send_Byte(cReg))
 332   1              return 0;
 333   1      
 334   1          /* read data */
 335   1          StartCondition();
 336   1          if (Send_Byte(cDevAddr | 0x01)) // Read address
 337   1              return 0;
 338   1          cResult = Read_Byte(1);
 339   1      
 340   1          StopCondition();
 341   1          return cResult;
 342   1      }
 343          
 344          
 345          uCHAR I2CWriteByte(uCHAR cDevAddr, uCHAR cReg, uCHAR cData)
 346          {
 347   1      
 348   1      
 349   1          /* start condition */
 350   1          StartCondition();
 351   1        cDevAddr &= 0xFE;   // Force WRITE address
 352   1          /* send device ID and write data */
 353   1          if(!Send_Byte(cDevAddr))
 354   1          {
 355   2              if(!Send_Byte(cReg))
 356   2              {
 357   3                  if(!Send_Byte(cData))
 358   3                  {
 359   4                      StopCondition();
 360   4                      return(0);      /* success */
 361   4                  }
 362   3              }
 363   2          }
C51 COMPILER V7.50   TWOWIRE                                                               10/30/2006 16:14:40 PAGE 7   

 364   1          StopCondition();
 365   1          return(1);
 366   1      }
 367                    /*
 368          uCHAR I2CWriteByte1(uCHAR cDevAddr, uCHAR cReg, uCHAR cData)
 369          {
 370          Set_SCL_Low;
 371          Set_SDA_Low;
 372          Send_Byte1(cDevAddr);
 373          Send_Byte1(cReg);
 374          Send_Byte1(cData);
 375            Set_SCL_Low;
 376           Set_SDA_Low;
 377              return(1);
 378          }
 379                  */
 380          //--------------------------------------------------
 381          // 041901, Added for TWD Burst Write
 382          // 1. PT8655X_Wr_Burst_A    (Start + Slave_ID + Address)
 383          // 2. PT8655X_Wr_Burst_D    (Data)
 384          // 3. PT8655X_Wr_Burst_P    (stop)
 385          //--------------------------------------------------
 386          uCHAR twdWr_Burst_A(uCHAR cReg)
 387          {
 388   1          StartCondition();
 389   1          if(!Send_Byte(TW803_P0))
 390   1          {
 391   2              if(!Send_Byte(cReg))
 392   2              {
 393   3                  return(0);               //
 394   3              }
 395   2          }
 396   1          return(1);                  //
 397   1      }
 398          
 399          #ifdef TW100K
              void twdWr_Burst_D(uCHAR cData)
              {
                  uCHAR ix;
              
                  for(ix = 0; ix < 8; ix++)
                  {
                      Set_SCL_Low;
                      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);
              
              }
              
              #else
 423          void twdWr_Burst_D(uCHAR cData)
 424          {
 425   1          uCHAR ix;
C51 COMPILER V7.50   TWOWIRE                                                               10/30/2006 16:14:40 PAGE 8   

 426   1      //uCHAR cAcknowledge;
 427   1      //    uCHAR cTWtrytime=0;
 428   1      //    cAcknowledge = 0;
 429   1      
 430   1          for(ix = 0; ix < 8; ix++)
 431   1          {
 432   2              Set_SCL2Low;
 433   2              if(cData&0x80)Set_SDA2High;
 434   2                      else Set_SDA2Low;
 435   2                      cData<<=1;
 436   2              Set_SCL2High;
 437   2          }
 438   1          Set_SCL2Low;
 439   1          Set_SDA2High;                /* release data line for acknowledge */
 440   1          Set_SCL2High;                /* Send a clock for Acknowledge */
 441   1      //    if(SDA_High) cAcknowledge = 1; /* No Acknowledge */
 442   1          Set_SCL2Low;                   /* Finish Acknoledge */
 443   1      
 444   1      //    return(cAcknowledge);
 445   1      
 446   1      }
 447          #endif
 448          
 449          void twdWr_Burst_P(void)
 450          {
 451   1          StopCondition();
 452   1      }
 453          
 454          //twdWriteTable() is used for burst write for
 455          //any I2C standar device
 456          #if VIDEO_AVAILABLE
 457          #ifdef VIDEO_SAA7114
              #define EOT     -1
              BOOL twdWriteTable(uCHAR cDevAddr, char *pString)
              {
                      uCHAR  cReg=0;
                uCHAR  cNum=0;
                while(*pString != EOT)
                {
                              cReg = *pString++;
                              cNum = *pString++;
                      if(!I2CWriteBytes(cDevAddr, cReg, cNum, pString))
                                      break;
                              else
                                      pString += cNum;
                      }
              }
              #endif
 474          #endif
 475          //--------------------------------------------------
 476          // Write Multiple Bytes to Device
 477          //--------------------------------------------------
 478          
 479          
 480          #if  0
              BOOL I2CWriteBytes(uCHAR cDevAddr, uCHAR cReg, uCHAR cNum, char *cData)
              {
                /* start condition */
                      StartCondition();
              
                /* send device ID and write data */
                if(!Send_Byte(cDevAddr))
C51 COMPILER V7.50   TWOWIRE                                                               10/30/2006 16:14:40 PAGE 9   

                {
                      if(!Send_Byte(cReg))
                              {
                              while(cNum--)
                              {
                                              if(Send_Byte(*cData++))  //If false: release line and return
                              {
                                      StopCondition();
                              return(0);      /* unsuccess */
                                              }
                                      }
                              StopCondition();
                              return(1);
                      }
                      }
                StopCondition();
                return(0);                  /* fail */
              }
              #endif
 507          //--------------------------------------------------
 508          // Read Multiple Bytes to Device
 509          //--------------------------------------------------
 510          BOOL I2CReadBytes(uCHAR cDevAddr, uCHAR cReg, uCHAR *pString, uCHAR cNum)
 511          {
 512   1              /* write reg offset */
 513   1              StartCondition();
 514   1        if(Send_Byte(cDevAddr))
 515   1                      return 0;  // Write address
 516   1        if(Send_Byte(cReg))
 517   1                      return 0;
 518   1      
 519   1              /* read data */
 520   1        StartCondition();
 521   1        if (Send_Byte(cDevAddr | 0x01)) // Read address
 522   1                      return 0;
 523   1              while(cNum)
 524   1        {
 525   2              *pString++ = Read_Byte(cNum);
 526   2                      cNum--;
 527   2              }
 528   1      
 529   1              StopCondition();
 530   1        return 1;
 531   1      }
 532          
 533          
 534          void twdDelay(uWORD wLoops)
 535          {
 536   1              uWORD wTemp;
 537   1      
 538   1          while (wLoops--) {
 539   2                  wTemp = 1000/6;     // one loop below takes about 11 us
 540   2              while (wTemp--);
 541   2          }
 542   1      }
 543          void twdDelay1(uWORD wLoops)
 544          {
 545   1              uWORD wTemp;
 546   1      
 547   1          while (wLoops--) {
 548   2                  wTemp = 1000/6;     // one loop below takes about 11 us
 549   2              while (wTemp--);
C51 COMPILER V7.50   TWOWIRE                                                               10/30/2006 16:14:40 PAGE 10  

 550   2          }
 551   1              /*
 552   1              I2CWriteByte(TW803_P0,0x32,0x0f);
 553   1          while (wLoops){
 554   1                 if(I2CReadByte(TW803_P0,0x32)&0x01){
 555   1                      I2CWriteByte(TW803_P0,0x32,0x0f);
 556   1              wLoops--;
 557   1                 }
 558   1          }*/
 559   1      }
 560          
 561          // OSD config register Write
 562          void OSDCfgWr(uCHAR index,uCHAR dat)
 563          {
 564   1       I2CWriteByte(TW803_P0,OSD_CFG_INDEX,index);
 565   1       I2CWriteByte(TW803_P0,OSD_CFG_DATA,dat);
 566   1      }
 567          
 568          #ifdef TV
              uCHAR TunerReadByte(uCHAR cDevAddr)  //uCHAR cReg)
              {
                      uCHAR cResult = 0;
                  
              #ifdef TWO_TW_BUS
                gbTwBusSel=0; 
              #endif
                 /* read data */
                 StartCondition();
                 if (Send_Byte(cDevAddr | 0x01)) // Read address
                              return 0;
                 cResult = Read_Byte(1);
              
                 StopCondition();
                 return cResult;
              }
              //--------------------------------------------------
              // Write Byte to Device 
              //--------------------------------------------------
              
              #ifdef PAL
              #define STEPCODE        0xC8    //Step:50KHz
              #endif
              #ifdef NTSC
              #define STEPCODE        0xCE    //Step:62.5KHz
              #endif
              
              uCHAR TunerWriteByte1(uCHAR cDevAddr, uCHAR cDecH, uCHAR cDecL,uCHAR bData, uCHAR cData)
              {
                  cDevAddr &= 0xFE;   // Force WRITE address
                  
                  // start condition 
                  StartCondition();
              
                  // send device ID and write data 
                 if(!Send_Byte(cDevAddr))
                 {
                              if(!Send_Byte(cDecH))
                              {
                                      if(!Send_Byte(cDecL))
                              {
                                              if(!Send_Byte(bData))
                                              {
C51 COMPILER V7.50   TWOWIRE                                                               10/30/2006 16:14:40 PAGE 11  

                                      if(!Send_Byte(cData))
                                      {
                                      StopCondition();
                                              return(0);      // success 
                                                      }
                              }
                              }
                              }
                  }
                  StopCondition();
                  return(1);                  // fail 
              }
              
              uCHAR TunerWriteByte(uCHAR cDevAddr, uCHAR cDecH, uCHAR cDecL, uCHAR cData)
              {
                  cDevAddr &= 0xFE;   // Force WRITE address
                  
                  // start condition 
                  StartCondition();
              
                  // send device ID and write data 
                 if(!Send_Byte(cDevAddr))
                 {
                              if(!Send_Byte(cDecH))
                              {
                                      if(!Send_Byte(cDecL))
                              {
                                              if(!Send_Byte(STEPCODE))
                                              {
                                      if(!Send_Byte(cData))
                                      {
                                      StopCondition();
                                              return(0);      // success 
                                                      }
                              }
                              }
                              }
                  }
                  StopCondition();
                  return(1);                  // fail 
              }
              #endif
 654          
 655          
 656          


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