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

📄 twowire.lst

📁 宏芯T102芯片驱动(51单片机作主控)
💻 LST
📖 第 1 页 / 共 2 页
字号:
 299   1          if (Send_Byte(cDevAddr | 0x01)) // Read address
 300   1              return 0;
 301   1          cResult = Read_Byte(1);
 302   1      
C51 COMPILER V7.06   TWOWIRE                                                               12/28/2004 10:14:02 PAGE 6   

 303   1          StopCondition();
 304   1          return cResult;
 305   1      }
 306          
 307          
 308          uCHAR I2CWriteByte(uCHAR cDevAddr, uCHAR cReg, uCHAR cData)
 309          {
 310   1      
 311   1      
 312   1          /* start condition */
 313   1          StartCondition();
 314   1        cDevAddr &= 0xFE;   // Force WRITE address
 315   1          /* send device ID and write data */
 316   1          if(!Send_Byte(cDevAddr))
 317   1          {
 318   2              if(!Send_Byte(cReg))
 319   2              {
 320   3                  if(!Send_Byte(cData))
 321   3                  {
 322   4                      StopCondition();
 323   4                      return(0);      /* success */
 324   4                  }
 325   3              }
 326   2          }
 327   1          StopCondition();
 328   1          return(1);
 329   1      }
 330          //--------------------------------------------------
 331          // 041901, Added for TWD Burst Write
 332          // 1. PT8655X_Wr_Burst_A    (Start + Slave_ID + Address)
 333          // 2. PT8655X_Wr_Burst_D    (Data)
 334          // 3. PT8655X_Wr_Burst_P    (stop)
 335          //--------------------------------------------------
 336          uCHAR twdWr_Burst_A(uCHAR cReg)
 337          {
 338   1          StartCondition();
 339   1          if(!Send_Byte(TW101))
 340   1          {
 341   2              if(!Send_Byte(cReg))
 342   2              {
 343   3                  return(0);               //
 344   3              }
 345   2          }
 346   1          return(1);                  //
 347   1      }
 348          
 349          #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 */
C51 COMPILER V7.06   TWOWIRE                                                               12/28/2004 10:14:02 PAGE 7   

              //    if(SDA_High) cAcknowledge = 1; /* No Acknowledge */
                  Set_SCL_Low;                   /* Finish Acknoledge */
              
              //    return(cAcknowledge);
              
              }
              
              #else
 373          void twdWr_Burst_D(uCHAR cData)
 374          {
 375   1          uCHAR ix;
 376   1      //uCHAR cAcknowledge;
 377   1      //    uCHAR cTWtrytime=0;
 378   1      //    cAcknowledge = 0;
 379   1      
 380   1          for(ix = 0; ix < 8; ix++)
 381   1          {
 382   2              Set_SCL2Low;
 383   2              if(cData&0x80)Set_SDA2High;
 384   2                      else Set_SDA2Low;
 385   2                      cData<<=1;
 386   2              Set_SCL2High;
 387   2          }
 388   1          Set_SCL2Low;
 389   1          Set_SDA2High;                /* release data line for acknowledge */
 390   1          Set_SCL2High;                /* Send a clock for Acknowledge */
 391   1      //    if(SDA_High) cAcknowledge = 1; /* No Acknowledge */
 392   1          Set_SCL2Low;                   /* Finish Acknoledge */
 393   1      
 394   1      //    return(cAcknowledge);
 395   1      
 396   1      }
 397          #endif
 398          
 399          void twdWr_Burst_P(void)
 400          {
 401   1          StopCondition();
 402   1      }
 403          
 404          //twdWriteTable() is used for burst write for
 405          //any I2C standar device
 406          #if VIDEO_AVAILABLE
 407          #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
 424          #endif
 425          //--------------------------------------------------
 426          // Write Multiple Bytes to Device
C51 COMPILER V7.06   TWOWIRE                                                               12/28/2004 10:14:02 PAGE 8   

 427          //--------------------------------------------------
 428          
 429          
 430          #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))
                {
                      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
 457          //--------------------------------------------------
 458          // Read Multiple Bytes to Device
 459          //--------------------------------------------------
 460          BOOL I2CReadBytes(uCHAR cDevAddr, uCHAR cReg, uCHAR *pString, uCHAR cNum)
 461          {
 462   1              /* write reg offset */
 463   1              StartCondition();
 464   1        if(Send_Byte(cDevAddr))
 465   1                      return 0;  // Write address
 466   1        if(Send_Byte(cReg))
 467   1                      return 0;
 468   1      
 469   1              /* read data */
 470   1        StartCondition();
 471   1        if (Send_Byte(cDevAddr | 0x01)) // Read address
 472   1                      return 0;
 473   1              while(cNum)
 474   1        {
 475   2              *pString++ = Read_Byte(cNum);
 476   2                      cNum--;
 477   2              }
 478   1      
 479   1              StopCondition();
 480   1        return 1;
 481   1      }
 482          
 483          
 484          void twdDelay(uWORD wLoops)
 485          {
 486   1              uWORD wTemp;
 487   1      
 488   1          while (wLoops--) {
C51 COMPILER V7.06   TWOWIRE                                                               12/28/2004 10:14:02 PAGE 9   

 489   2                  wTemp = 1000/6;     // one loop below takes about 11 us
 490   2              while (wTemp--);
 491   2          }
 492   1      }
 493          
 494          
 495          // OSD config register Write
 496          void OSDCfgWr(uCHAR index,uCHAR dat)
 497          {
 498   1       I2CWriteByte(TW101,OSD_CFG_INDEX,index);
 499   1       I2CWriteByte(TW101,OSD_CFG_DATA,dat);
 500   1      }
 501          
 502          #ifdef TV
 503          uCHAR TunerReadByte(uCHAR cDevAddr)  //uCHAR cReg)
 504          {
 505   1              uCHAR cResult = 0;
 506   1          
 507   1      #ifdef TWO_TW_BUS
                gbTwBusSel=0; 
              #endif
 510   1         /* read data */
 511   1         StartCondition();
 512   1         if (Send_Byte(cDevAddr | 0x01)) // Read address
 513   1                      return 0;
 514   1         cResult = Read_Byte(1);
 515   1      
 516   1         StopCondition();
 517   1         return cResult;
 518   1      }
 519          //--------------------------------------------------
 520          // Write Byte to Device 
 521          //--------------------------------------------------
 522          
 523          #ifdef PAL
              #define STEPCODE        0xC8    //Step:50KHz
              #endif
 526          #ifdef NTSC
 527          #define STEPCODE        0xCE    //Step:62.5KHz
 528          #endif
 529          
 530          uCHAR TunerWriteByte1(uCHAR cDevAddr, uCHAR cDecH, uCHAR cDecL,uCHAR bData, uCHAR cData)
 531          {
 532   1          cDevAddr &= 0xFE;   // Force WRITE address
 533   1          
 534   1          // start condition 
 535   1          StartCondition();
 536   1      
 537   1          // send device ID and write data 
 538   1         if(!Send_Byte(cDevAddr))
 539   1         {
 540   2                      if(!Send_Byte(cDecH))
 541   2                      {
 542   3                              if(!Send_Byte(cDecL))
 543   3                      {
 544   4                                      if(!Send_Byte(bData))
 545   4                                      {
 546   5                              if(!Send_Byte(cData))
 547   5                              {
 548   6                              StopCondition();
 549   6                                      return(0);      // success 
 550   6                                              }
C51 COMPILER V7.06   TWOWIRE                                                               12/28/2004 10:14:02 PAGE 10  

 551   5                      }
 552   4                      }
 553   3                      }
 554   2          }
 555   1          StopCondition();
 556   1          return(1);                  // fail 
 557   1      }
 558          
 559          uCHAR TunerWriteByte(uCHAR cDevAddr, uCHAR cDecH, uCHAR cDecL, uCHAR cData)
 560          {
 561   1          cDevAddr &= 0xFE;   // Force WRITE address
 562   1          
 563   1          // start condition 
 564   1          StartCondition();
 565   1      
 566   1          // send device ID and write data 
 567   1         if(!Send_Byte(cDevAddr))
 568   1         {
 569   2                      if(!Send_Byte(cDecH))
 570   2                      {
 571   3                              if(!Send_Byte(cDecL))
 572   3                      {
 573   4                                      if(!Send_Byte(STEPCODE))
 574   4                                      {
 575   5                              if(!Send_Byte(cData))
 576   5                              {
 577   6                              StopCondition();
 578   6                                      return(0);      // success 
 579   6                                              }
 580   5                      }
 581   4                      }
 582   3                      }
 583   2          }
 584   1          StopCondition();
 585   1          return(1);                  // fail 
 586   1      }
 587          #endif
 588          
 589          


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