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

📄 t100.c

📁 TFT 驱动 T100DEMO程序.做protable DVD的朋友可以参考一下.
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "REG51.H"
#include <intrins.h>
#include "Common.h"
//#include "Remote.h"


#define OSD_EN
//typedef unsigned char  uCHAR;

//#include "T100Data_A.h"
//#include "T100Data_PA.h"
#include "T100Data_AU.h"
//#include "T100Data_CPT.h"
//#include "T100Data_PANASONIC.h"
//#include "T100Data_PVI7.h"
//#include "T100Data_LG.h"
//#include "T100Data_FOX.h"


#ifdef OSD_EN
  #include "OSDFont1218_new.h"
  #include "OSD1218_new.h"
#endif

sbit 	T100_RESET	= P1^4;
sbit    SCL 		= P2^7;//P1^6;
sbit	SDA 		= P2^6;//P1^7;
sbit	BL_EN		= P2^3;
#if 1
#define kyKEY_MSK		0x81
#define KEYPORT			P0

#define kyMENU          0x08
#define kyDEC           0x04
#define kyINC           0x02
#define kySOURCE        0x10
#define kyUD_LR         0x20
#define kyFULL_43       0x40
#else
#define kyKEY_MSK		0xc0
#define KEYPORT			P2

#define kyMENU          0x02
#define kyDEC           0x08
#define kyINC           0x04
#define kySOURCE        0x10
#define kyUD_LR         0x20
#define kyFULL_43       0x01//0x40
#endif //*/
/*sbit	kyMENU     	= P0^1;
sbit 	kyDEC		= P0^2;
sbit    kyINC   	= P0^3;
sbit	kySOURCE	= P0^4;
sbit 	kyUD_LR		= P0^5;
sbit    kyFULL_43	= P0^6;//*/
bit ir_enable   =0;
bit bNTSC_PAL	= 0;      //0:PAL 		1:NTSC
bit bFULL_43	= 1;      //0:4:3 		1:FULL
bit bUP_DOWN	= 1;      //0:Down to Up 	1:Up to Down
bit bLEFT_RIGHT	= 1;      //0:Right to Left     1:Left to Right
uCHAR cSource	= 2;      //2-4:CVBS2-4         5:S-Video       6:ITU656
uCHAR cStandard	= 0xff;   //0:PAL               4:NTSC
uCHAR c60HZ_Mode=0;
uCHAR c50HZ_Mode=0;
uCHAR cKey_Curr,cKey_Pre;
uCHAR ir_data;
uCHAR Repeat_Times;
void Initial(void);
void Delay_ms(uCHAR);
void InitT100(void);
void ClosePanel(void);
void OpenPanel(void);
void DetectNTSC_PAL(void);
void SetSource(void);
void SetMode(void);
void SetUD_LR(void);
void I2CWriteTbl(char*);
uCHAR I2CReadByte(uCHAR, uCHAR);
uCHAR I2CWriteByte(uCHAR,uCHAR,uCHAR);
void kyKeypad(void);
#ifdef OSD_EN
void InitOSD(void);
void  OSDDisable(void);
void OSDEnable(void);
void OSDCtrl(char cDir);
uCHAR cLanguage=0; //0:English 1:French 2:German 3:Spanish 4:Japenese 5:Russian
uCHAR cOSDFunc=1;      //0:OSD Off 1:Bright 2:Color  3:Screen
uCHAR cBright,cColor=COLOR;

#endif
void main(void)
{
	Initial();
	while(1)
	{
		//kyKeypad();
	    DetectNTSC_PAL();
//                #ifdef OSD_EN
		        OSDEnable();
 //               #endif

//                OSDEnable();
	}//while
}//main

void Initial(void)
{
//Initial 8051
	P0=0xff;
	P1=0xff;
	P2=0xff;
	P3=0xff;
//8051Register Set
	IE    	= 0;   	// disable all interrupt
	TMOD 	= 0x11;  // Timer1 Mode 1, Timer0 Mode 1;
	//TMOD 	= 0x01; // Timer0 Mode 1;
  	EX0   	= 0;     // disable external interrupt 0, IE[0]
	EX1		= 0;
  	//ET0 	= 1;   	// enable bTimer 0
  	//IT0   = 1;     // falling endge generate interrupt, TCON[0]
  	INT0 	= 1;
	IT1   	= 1;     // falling endge generate interrupt, TCON[0]
  	INT1 	= 1;

//Initial T100
	T100_RESET	= 0 ;
	Delay_ms(50);  //50
	T100_RESET	= 1 ;
	Delay_ms(20);
	InitT100();
//	SetUD_LR();
        #ifdef OSD_EN
        InitOSD();
        #endif
}//Initial

void Delay_ms(uCHAR cTime)
{
	uCHAR i,j;
	for(i=0;i<cTime;i++)
	{
		for(j=0;j<250;j++)_nop_();
		for(j=0;j<250;j++)_nop_();
		for(j=0;j<250;j++)_nop_();
		for(j=0;j<250;j++)_nop_();
	}//For
}//Delay

void InitT100(void)
{
	I2CWriteTbl(TCONData);
	ClosePanel();
	I2CWriteTbl(T100Init);
	I2CWriteTbl(GAMMAData);
	I2CWriteTbl(FilterData);
	SetMode();
	SetSource();
	SetUD_LR();
//	OpenPanel();
}//InitT100
void ClosePanel(void)
{
	BL_EN=1;
	I2CWriteByte(TW100, 0xC2, I2CReadByte(TW100, 0xC2)|0x12);
	I2CWriteByte(TW100, 0x91, 0x87);//I2CReadByte(TW101, PATTERN_CTRL)|0x80);  //Enable Frame Background Color
}
void OpenPanel(void)
{
	I2CWriteByte(TW100, 0xC2, I2CReadByte(TW100, 0xC2)&0xED);
	I2CWriteByte(TW100, 0x91, I2CReadByte(TW100, 0x91)&~0x80); //Enable Frame Background Color
	Delay_ms(10);
	BL_EN=0;
}
void DetectNTSC_PAL(void)
{
	static int wBuff=0x000;
	uCHAR cBuff[2];
    wBuff+=1;
		if(wBuff==0x01)
		{
			wBuff=0x00;
			for(cBuff[1]=0;cBuff[1]<1;cBuff[1]++)
			{
   			    cBuff[0] = I2CReadByte(TW100, 0x5A)&0xe0;
			    if(cBuff[0]==cStandard)break;
//				Delay_ms(10);
                            if(cBuff[0]>=0x40)
                            {
                                ClosePanel();
                                return;
                            }     //*/
			}
           #ifdef ESS
                        if((bNTSC_PAL)&&(cSource==6))
                        {
                           cBuff[1] = I2CReadByte(TW100, 0x82);
                           if(cBuff[1]>0x90)I2CWriteByte(TW100+2, 0xd3,0x06);
                           else if(cBuff[1]<0x78)I2CWriteByte(TW100+2, 0xd3,0x04);
                        }
                        if((!bNTSC_PAL)&&(cSource==6))
                        {
                           cBuff[1] = I2CReadByte(TW100, 0x82);
                           if(cBuff[1]>0xb0)I2CWriteByte(TW100+2, 0xd3,0x0b);
                           else if(cBuff[1]<0x78)I2CWriteByte(TW100+2, 0xd3,0x04);
                        }
           #endif
			if(cBuff[0]!=cStandard)
    		        {
			    ClosePanel();
            		    cStandard=cBuff[0];
			    if(cStandard)
			    {
				bNTSC_PAL	= 0;
			    }
			   else bNTSC_PAL	= 1;
                           I2CWriteByte(TW100,0x0F,0x70);
                           I2CWriteByte(TW100+4,0x3f,0x01);
	                SetMode();
                       SetSource();
                       Delay_ms(25);
                       I2CWriteByte(TW100+4,0x3f,0x00);
		       OpenPanel();
 //                          I2CWriteByte(TW100,0x0F,0x00);
                       Delay_ms(10);
                    }
            else OpenPanel();
		}

}
void SetSource(void)
{
	switch(cSource)
	{
		case 2: I2CWriteTbl(CVBS2Data);
				break;
		case 3: I2CWriteTbl(CVBS3Data);
				break;
		case 4: I2CWriteTbl(CVBS4Data);
				break;
		case 5: I2CWriteTbl(SVIDEOData);
				break;
		case 6: I2CWriteTbl(ITU656Data);
	}
}
void SetMode(void)//N/P,Full/4:3
{
// uCHAR i;
	if(bNTSC_PAL)//NTSC&&FULL
	{
		I2CWriteTbl(NTSC_FULLData);
		if((!bFULL_43))//NTSC&&4:3
			I2CWriteTbl(NTSC_43Data);
                switch(c60HZ_Mode)
                {
                        case 1: I2CWriteTbl(NTSC443Data);
				break;
                        case 2: I2CWriteTbl(PAL_60Data);
				break;
                        case 3: I2CWriteTbl(PAL_MData);
				break;
                }//*/

		if(cSource!=5){
		      I2CWriteByte(TW100+4,0x03,0x00);
		     I2CWriteByte(TW100+4,0x00,0x00);
	             }
                else{ I2CWriteByte(TW100+4,0x03,0x03);
                     I2CWriteByte(TW100+4,0x00,0x01);
                }

	}
	else//PAL&&FULL
	{
		I2CWriteTbl(PAL_FULLData);
		if((!bFULL_43))//PAL&&4:3
			I2CWriteTbl(PAL_43Data);
//		for(i=0;i<=1;i++)
		{
//        if(c50HZ_Mode)I2CWriteTbl(PAL_CNData);
		if(cSource!=5){
			 I2CWriteByte(TW100+4,0x03,0x02);
			I2CWriteByte(TW100+4,0x00,0x32);
	        }
                else{
                   I2CWriteByte(TW100+4,0x03,0x03);
                  I2CWriteByte(TW100+4,0x00,0x33);
                }
                  //    Delay_ms(50);

//		if(cSource!=5)I2CWriteByte(TW100+4,0x00,0x32);//PAL-N 0x36
		//if((I2CReadByte(TW100+4,0x3c)&0x01))i=2;
		//else c50HZ_Mode=!c50HZ_Mode;
		}
	}
//		if(cSource==5)I2CWriteByte(TW100+4,0x0f,0x33);
}
void SetUD_LR(void)
{
        uCHAR cTemp;
	if(bUP_DOWN&bLEFT_RIGHT)
	{
		cTemp=UD_LR;
	}
	else if(bUP_DOWN&!bLEFT_RIGHT)
	{
		cTemp=UD_RL;
	}
	else if(!bUP_DOWN&bLEFT_RIGHT)
	{
		cTemp=DU_LR;
	}
	else if(!bUP_DOWN&!bLEFT_RIGHT)
	{
		cTemp=DU_RL;
	}
	I2CWriteByte(TW100,0xe1,cTemp);
}

#define Set_SDA_High  SDA = 1,SDA = 1
#define Set_SDA_Low   SDA = 0,SDA = 0
#define Set_SCL_High  SCL = 1,SCL = 1
#define Set_SCL_Low   SCL = 0,SCL = 0

#define SDA_High      SDA!=0
#define SDA_Low       SDA==0
#define SCL_High      SCL!=0
#define SCL_Low       SCL==0

#define	TWD_SPEED       0x01		//value: 1 (Fastest), 2 (slower), ... N (much slower)
#define	TWD_LONG_TIME	(TWD_SPEED*8)
#define	TWD_SHORT_TIME	(TWD_SPEED*1)
void StartCondition(void)
{
    uCHAR ix;
    uCHAR cTWtrytime=0;
    EA=0;
    while(++cTWtrytime)
    {
        Set_SDA_High;
        Set_SCL_High;        /* make sure two line is release */
        for(ix = 0; ix < TWD_LONG_TIME; ix++)
        { };  /* Delay 12us */

        Set_SDA_Low;
        for(ix = 0; ix < TWD_LONG_TIME; ix++)
        { };  /* Delay 12us */

        if((SCL_High)&&(SDA_Low))
            break;
    }

    for(ix = 0; ix < TWD_SHORT_TIME; ix++)
    { };  /* Delay 12us */
}

//----------------------------------------
// P_Condition for TWD protocol
//----------------------------------------
void StopCondition(void)
{
    uCHAR ix;
    uCHAR cTWtrytime=0;

    Set_SDA_Low;
    Set_SCL_High;
    for(ix = 0; ix < TWD_SHORT_TIME; ix++)
    { };  /* delay 12us */

    while(SCL_Low && ++cTWtrytime)
    { };

    for(ix = 0; ix < TWD_SHORT_TIME; ix++)
    { };  /* delay 12us */

    Set_SDA_High;
    for(ix = 0; ix < TWD_SHORT_TIME; ix++)
    { };  /* delay 12us */
	EA=1;
}

//--------------------------------------------------
// Send_Byte
//    Send a byte to master with a acknowledge bit
//--------------------------------------------------
uCHAR Send_Byte(uCHAR cData)
{
    uCHAR ix, j, cAcknowledge;
    uCHAR cTWtrytime=0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -