?? twowire.lst
字號:
330 1
331 1 /* read data */
332 1 StartCondition();
333 1 if (Send_Byte(cDevAddr | 0x01)) // Read address
334 1 return 0;
335 1 cResult = Read_Byte(1);
336 1
337 1 StopCondition();
338 1 return cResult;
339 1 }
340
341
342 uCHAR I2CWriteByte(uCHAR cDevAddr, uCHAR cReg, uCHAR cData)
343 {
344 1
345 1
346 1 /* start condition */
347 1 StartCondition();
348 1 cDevAddr &= 0xFE; // Force WRITE address
349 1 /* send device ID and write data */
350 1 if(!Send_Byte(cDevAddr))
351 1 {
352 2 if(!Send_Byte(cReg))
353 2 {
354 3 if(!Send_Byte(cData))
355 3 {
356 4 StopCondition();
357 4 return(0); /* success */
358 4 }
359 3 }
360 2 }
361 1 StopCondition();
362 1 return(1);
363 1 }
364
C51 COMPILER V7.50 TWOWIRE 06/16/2006 15:29:43 PAGE 7
365 uCHAR I2CWriteByte1(uCHAR cDevAddr, uCHAR cReg, uCHAR cData)
366 {
367 1 Set_SCL_Low;
368 1 Set_SDA_Low;
369 1 Send_Byte1(cDevAddr);
370 1 Send_Byte1(cReg);
371 1 Send_Byte1(cData);
372 1 Set_SCL_Low;
373 1 Set_SDA_Low;
374 1 return(1);
375 1 }
376
377 //--------------------------------------------------
378 // 041901, Added for TWD Burst Write
379 // 1. PT8655X_Wr_Burst_A (Start + Slave_ID + Address)
380 // 2. PT8655X_Wr_Burst_D (Data)
381 // 3. PT8655X_Wr_Burst_P (stop)
382 //--------------------------------------------------
383 uCHAR twdWr_Burst_A(uCHAR cReg)
384 {
385 1 StartCondition();
386 1 if(!Send_Byte(TW101))
387 1 {
388 2 if(!Send_Byte(cReg))
389 2 {
390 3 return(0); //
391 3 }
392 2 }
393 1 return(1); //
394 1 }
395
396 #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
420 void twdWr_Burst_D(uCHAR cData)
421 {
422 1 uCHAR ix;
423 1 //uCHAR cAcknowledge;
424 1 // uCHAR cTWtrytime=0;
425 1 // cAcknowledge = 0;
426 1
C51 COMPILER V7.50 TWOWIRE 06/16/2006 15:29:43 PAGE 8
427 1 for(ix = 0; ix < 8; ix++)
428 1 {
429 2 Set_SCL2Low;
430 2 if(cData&0x80)Set_SDA2High;
431 2 else Set_SDA2Low;
432 2 cData<<=1;
433 2 Set_SCL2High;
434 2 }
435 1 Set_SCL2Low;
436 1 Set_SDA2High; /* release data line for acknowledge */
437 1 Set_SCL2High; /* Send a clock for Acknowledge */
438 1 // if(SDA_High) cAcknowledge = 1; /* No Acknowledge */
439 1 Set_SCL2Low; /* Finish Acknoledge */
440 1
441 1 // return(cAcknowledge);
442 1
443 1 }
444 #endif
445
446 void twdWr_Burst_P(void)
447 {
448 1 StopCondition();
449 1 }
450
451 //twdWriteTable() is used for burst write for
452 //any I2C standar device
453 #if VIDEO_AVAILABLE
454 #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
471 #endif
472 //--------------------------------------------------
473 // Write Multiple Bytes to Device
474 //--------------------------------------------------
475
476
477 #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--)
C51 COMPILER V7.50 TWOWIRE 06/16/2006 15:29:43 PAGE 9
{
if(Send_Byte(*cData++)) //If false: release line and return
{
StopCondition();
return(0); /* unsuccess */
}
StopCondition();
return(1);
}
}
StopCondition();
return(0); /* fail */
}
#endif
504 //--------------------------------------------------
505 // Read Multiple Bytes to Device
506 //--------------------------------------------------
507 BOOL I2CReadBytes(uCHAR cDevAddr, uCHAR cReg, uCHAR *pString, uCHAR cNum)
508 {
509 1 /* write reg offset */
510 1 StartCondition();
511 1 if(Send_Byte(cDevAddr))
512 1 return 0; // Write address
513 1 if(Send_Byte(cReg))
514 1 return 0;
515 1
516 1 /* read data */
517 1 StartCondition();
518 1 if (Send_Byte(cDevAddr | 0x01)) // Read address
519 1 return 0;
520 1 while(cNum)
521 1 {
522 2 *pString++ = Read_Byte(cNum);
523 2 cNum--;
524 2 }
525 1
526 1 StopCondition();
527 1 return 1;
528 1 }
529
530
531 void twdDelay(uWORD wLoops)
532 {
533 1 uWORD wTemp;
534 1
535 1 while (wLoops--) {
536 2 wTemp = 1000/6; // one loop below takes about 11 us
537 2 while (wTemp--);
538 2 }
539 1 }
540 void twdDelay1(uWORD wLoops)
541 {
542 1 uWORD wTemp;
543 1
544 1 while (wLoops--) {
545 2 wTemp = 1000/6; // one loop below takes about 11 us
546 2 while (wTemp--);
547 2 }
548 1 /*
549 1 I2CWriteByte(TW101,0x32,0x0f);
550 1 while (wLoops){
C51 COMPILER V7.50 TWOWIRE 06/16/2006 15:29:43 PAGE 10
551 1 if(I2CReadByte(TW101,0x32)&0x01){
552 1 I2CWriteByte(TW101,0x32,0x0f);
553 1 wLoops--;
554 1 }
555 1 }*/
556 1 }
557
558 // OSD config register Write
559 void OSDCfgWr(uCHAR index,uCHAR dat)
560 {
561 1 I2CWriteByte(TW101,OSD_CFG_INDEX,index);
562 1 I2CWriteByte(TW101,OSD_CFG_DATA,dat);
563 1 }
564
565 #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))
{
if(!Send_Byte(cData))
{
StopCondition();
return(0); // success
C51 COMPILER V7.50 TWOWIRE 06/16/2006 15:29:43 PAGE 11
}
}
}
}
}
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
651
652
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 729 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 11
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -