📄 t101.lst
字号:
263 1 if(bNTSC_PAL)//NTSC&&FULL
264 1 {
265 2 I2CWriteTbl(NTSC_FULLData);
266 2 if((!bFULL_43))//NTSC&&4:3
267 2 I2CWriteTbl(NTSC_43Data);
268 2 switch(c60HZ_Mode)
269 2 {
270 3 case 1: I2CWriteTbl(NTSC443Data);
271 3 break;
272 3 case 2: I2CWriteTbl(PAL_60Data);
273 3 break;
274 3 case 3: I2CWriteTbl(PAL_MData);
275 3 break;
276 3 }//*/
277 2
278 2 if(cSource!=5){
279 3 I2CWriteByte(TW100+4,0x03,0x00);
280 3 I2CWriteByte(TW100+4,0x00,0x00);
281 3 }
282 2 else{ I2CWriteByte(TW100+4,0x03,0x03);
283 3 I2CWriteByte(TW100+4,0x00,0x01);
284 3 }
285 2
286 2 }
287 1 else//PAL&&FULL
288 1 {
289 2 I2CWriteTbl(PAL_FULLData);
290 2 if((!bFULL_43))//PAL&&4:3
291 2 I2CWriteTbl(PAL_43Data);
292 2 // for(i=0;i<=1;i++)
293 2 {
294 3 // if(c50HZ_Mode)I2CWriteTbl(PAL_CNData);
295 3 if(cSource!=5){
296 4 I2CWriteByte(TW100+4,0x03,0x02);
297 4 I2CWriteByte(TW100+4,0x00,0x32);
298 4 }
299 3 else{
300 4 I2CWriteByte(TW100+4,0x03,0x03);
301 4 I2CWriteByte(TW100+4,0x00,0x33);
302 4 }
C51 COMPILER V7.06 T101 01/12/2006 15:42:51 PAGE 6
303 3 // Delay_ms(50);
304 3
305 3 // if(cSource!=5)I2CWriteByte(TW100+4,0x00,0x32);//PAL-N 0x36
306 3 //if((I2CReadByte(TW100+4,0x3c)&0x01))i=2;
307 3 //else c50HZ_Mode=!c50HZ_Mode;
308 3 }
309 2 }
310 1 // if(cSource==5)I2CWriteByte(TW100+4,0x0f,0x33);
311 1 }
312 void SetUD_LR(void)
313 {
314 1 uCHAR cTemp;
315 1 if(bUP_DOWN&bLEFT_RIGHT)
316 1 {
317 2 cTemp=UD_LR;
318 2 }
319 1 else if(bUP_DOWN&!bLEFT_RIGHT)
320 1 {
321 2 cTemp=UD_RL;
322 2 }
323 1 else if(!bUP_DOWN&bLEFT_RIGHT)
324 1 {
325 2 cTemp=DU_LR;
326 2 }
327 1 else if(!bUP_DOWN&!bLEFT_RIGHT)
328 1 {
329 2 cTemp=DU_RL;
330 2 }
331 1 I2CWriteByte(TW100,0xe1,cTemp);
332 1 }
333
334 #define Set_SDA_High SDA = 1,SDA = 1
335 #define Set_SDA_Low SDA = 0,SDA = 0
336 #define Set_SCL_High SCL = 1,SCL = 1
337 #define Set_SCL_Low SCL = 0,SCL = 0
338
339 #define SDA_High SDA!=0
340 #define SDA_Low SDA==0
341 #define SCL_High SCL!=0
342 #define SCL_Low SCL==0
343
344 #define TWD_SPEED 0x01 //value: 1 (Fastest), 2 (slower), ... N (much slower)
345 #define TWD_LONG_TIME (TWD_SPEED*8)
346 #define TWD_SHORT_TIME (TWD_SPEED*1)
347 void StartCondition(void)
348 {
349 1 uCHAR ix;
350 1 uCHAR cTWtrytime=0;
351 1 EA=0;
352 1 while(++cTWtrytime)
353 1 {
354 2 Set_SDA_High;
355 2 Set_SCL_High; /* make sure two line is release */
356 2 for(ix = 0; ix < TWD_LONG_TIME; ix++)
357 2 { }; /* Delay 12us */
358 2
359 2 Set_SDA_Low;
360 2 for(ix = 0; ix < TWD_LONG_TIME; ix++)
361 2 { }; /* Delay 12us */
362 2
363 2 if((SCL_High)&&(SDA_Low))
364 2 break;
C51 COMPILER V7.06 T101 01/12/2006 15:42:51 PAGE 7
365 2 }
366 1
367 1 for(ix = 0; ix < TWD_SHORT_TIME; ix++)
368 1 { }; /* Delay 12us */
369 1 }
370
371 //----------------------------------------
372 // P_Condition for TWD protocol
373 //----------------------------------------
374 void StopCondition(void)
375 {
376 1 uCHAR ix;
377 1 uCHAR cTWtrytime=0;
378 1
379 1 Set_SDA_Low;
380 1 Set_SCL_High;
381 1 for(ix = 0; ix < TWD_SHORT_TIME; ix++)
382 1 { }; /* delay 12us */
383 1
384 1 while(SCL_Low && ++cTWtrytime)
385 1 { };
386 1
387 1 for(ix = 0; ix < TWD_SHORT_TIME; ix++)
388 1 { }; /* delay 12us */
389 1
390 1 Set_SDA_High;
391 1 for(ix = 0; ix < TWD_SHORT_TIME; ix++)
392 1 { }; /* delay 12us */
393 1 EA=1;
394 1 }
395
396 //--------------------------------------------------
397 // Send_Byte
398 // Send a byte to master with a acknowledge bit
399 //--------------------------------------------------
400 uCHAR Send_Byte(uCHAR cData)
401 {
402 1 uCHAR ix, j, cAcknowledge;
403 1 uCHAR cTWtrytime=0;
404 1
405 1 cAcknowledge = 0;
406 1
407 1 for(ix = 0; ix < 8; ix++)
408 1 {
409 2 Set_SCL_Low;
410 2 for(j = 0; j < TWD_SHORT_TIME; j++)
411 2 { };
412 2
413 2 if(cData&0x80)Set_SDA_High;
414 2 else Set_SDA_Low;
415 2 cData<<=1;
416 2
417 2 for(j = 0; j < TWD_SHORT_TIME; j++)
418 2 { };
419 2
420 2 Set_SCL_High;
421 2 while(SCL_Low && ++cTWtrytime)
422 2 { };
423 2
424 2 for(j = 0; j < TWD_SHORT_TIME; j++)
425 2 { };
426 2 }
C51 COMPILER V7.06 T101 01/12/2006 15:42:51 PAGE 8
427 1 for(j = 0; j < TWD_SHORT_TIME; j++)
428 1 { };
429 1
430 1 Set_SCL_Low;
431 1 for(j = 0; j < TWD_SHORT_TIME; j++)
432 1 { };
433 1
434 1 Set_SDA_High; /* release data line for acknowledge */
435 1 for(j = 0; j < TWD_SHORT_TIME; j++)
436 1 { };
437 1
438 1 Set_SCL_High; /* Send a clock for Acknowledge */
439 1 while(SCL_Low)
440 1 { };
441 1 for(j = 0; j < TWD_SHORT_TIME; j++)
442 1 { };
443 1
444 1 if(SDA_High) cAcknowledge = 1; /* No Acknowledge */
445 1 Set_SCL_Low; /* Finish Acknoledge */
446 1 for(j = 0; j < TWD_SHORT_TIME; j++)
447 1 { };
448 1
449 1 return(cAcknowledge);
450 1 }
451
452 //--------------------------------------------------
453 // Read_Byte
454 // Read a byte from master with a acknowledge bit
455 //--------------------------------------------------
456 uCHAR Read_Byte(uCHAR cNum)
457 {
458 1 uCHAR ix, j;
459 1 uCHAR cRetval=0;
460 1
461 1 for(ix=0;ix<8;ix++){
462 2 Set_SCL_High;
463 2 while(SCL_Low){};
464 2 for(j=0;j<TWD_SHORT_TIME;j++){};
465 2 cRetval = (SDA_High)? (cRetval|(1<<(7-ix))):cRetval ; /* MSB First */
466 2 Set_SCL_Low;
467 2 }
468 1
469 1 if(cNum==1)
470 1 Set_SDA_High;
471 1 else
472 1 Set_SDA_Low;
473 1 //SDA = (cNum==1) 1:0;
474 1 Set_SCL_High;
475 1 while(SCL_Low){};
476 1 for(j = 0; j < TWD_SHORT_TIME; j++)
477 1 { };
478 1
479 1 Set_SCL_Low;
480 1
481 1 Set_SDA_High;
482 1 for(j = 0; j < TWD_SHORT_TIME; j++)
483 1 { };
484 1
485 1 return cRetval;
486 1 }
487 uCHAR I2CReadByte(uCHAR cAddr, uCHAR cReg)
488 {
C51 COMPILER V7.06 T101 01/12/2006 15:42:51 PAGE 9
489 1 uCHAR cTemp;
490 1
491 1 StartCondition();
492 1 Send_Byte(cAddr);
493 1 Send_Byte(cReg);
494 1 StartCondition();
495 1 Send_Byte(cAddr|0x01);
496 1 cTemp=Read_Byte(1);
497 1 StopCondition();
498 1
499 1 return cTemp;
500 1 }
501 uCHAR I2CWriteByte(uCHAR cAddr,uCHAR cReg,uCHAR cData)
502 {
503 1 StartCondition();
504 1 Send_Byte(cAddr);
505 1 Send_Byte(cReg);
506 1 Send_Byte(cData);
507 1 StopCondition();
508 1 return 0;
509 1 }
510 void I2CWriteTbl(char *pString)
511 {
512 1 uCHAR cAddr,cReg,cNum0,cNum1,cINC;
513 1 while(*pString != EOT)
514 1 {
515 2 cAddr = *pString++;
516 2 cNum0 = *pString++;
517 2 while(cNum0)
518 2 {
519 3 cReg = *pString++;
520 3 cNum1 = *pString++;
521 3 cNum0 -= (cNum1+2);
522 3 if(cNum1!=1)
523 3 {
524 4 cINC = *pString++;
525 4 cNum1 -= 1;
526 4 }
527 3 while(cNum1--)
528 3 {
529 4 I2CWriteByte(cAddr,cReg,*pString++);
530 4 cReg+=cINC;
531 4 }
532 3 }
533 2 }
534 1 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -