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