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

📄 t100.c

📁 在51单片机上用C写的T100,T101TFT屏的控制程序,有OSD
💻 C
📖 第 1 页 / 共 4 页
字号:
                                 else
                                 {
                                     I2CWriteByte(TW100+4,0x03,0x03);
                                     I2CWriteByte(TW100+4,0x00,0x05);
                                 }
				                        break;
                }
#endif*/
	}
	else//PAL&&FULL
	{
		I2CWriteTbl(PAL_FULLData);
		if((!bFULL_43))//PAL&&4:3
			I2CWriteTbl(PAL_43Data);
		if(cSource!=5)
		{
		    I2CWriteByte(TW100+4,0x03,0x02);
		    I2CWriteByte(TW100+4,0x00,0x32);
	  }
    else
    {
        I2CWriteByte(TW100+4,0x03,0x03);
        I2CWriteByte(TW100+4,0x00,0x33);
    }
               /* I2CWriteTbl(PAL_CNData);
                   if(cSource!=5){
		        I2CWriteByte(TW100+4,0x00,0x36);
		        I2CWriteByte(TW100+4,0x03,0x03);
		    }
                    else{
                        I2CWriteByte(TW100+4,0x03,0x03);
                        I2CWriteByte(TW100+4,0x00,0x37);
                    }*/
		/*for(i=0;i<=1;i++)
		{
                  // if(c50HZ_Mode)
                   I2CWriteTbl(PAL_CNData);
                   if(cSource!=5){
		        I2CWriteByte(TW100+4,0x00,0x36);
		        I2CWriteByte(TW100+4,0x03,0x03);
		    }
                    else{
                        I2CWriteByte(TW100+4,0x03,0x03);
                        I2CWriteByte(TW100+4,0x00,0x37);
                    }*/
                    //  Delay_ms(50);
		    //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);
}

//*************************************************
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;

    cAcknowledge = 0;

    for(ix = 0; ix < 8; ix++)
    {
        Set_SCL_Low;
        for(j = 0; j < TWD_SHORT_TIME; j++)
        { };

        if(cData&0x80)Set_SDA_High;
		    else Set_SDA_Low;

		    cData<<=1;

        for(j = 0; j < TWD_SHORT_TIME; j++)
        { };

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

        for(j = 0; j < TWD_SHORT_TIME; j++)
        { };
    }
    for(j = 0; j < TWD_SHORT_TIME; j++)
    { };

    Set_SCL_Low;
    for(j = 0; j < TWD_SHORT_TIME; j++)
    { };

    Set_SDA_High;                /* release data line for acknowledge */
    for(j = 0; j < TWD_SHORT_TIME; j++)
    { };

    Set_SCL_High;                /* Send a clock for Acknowledge */
    while(SCL_Low)
    { };
    for(j = 0; j < TWD_SHORT_TIME; j++)
    { };

    if(SDA_High) cAcknowledge = 1; /* No Acknowledge */
    Set_SCL_Low;                   /* Finish Acknoledge */
    for(j = 0; j < TWD_SHORT_TIME; j++)
    { };

    return(cAcknowledge);
}

//--------------------------------------------------
// Read_Byte
//    Read a byte from master with a acknowledge bit
//--------------------------------------------------
uCHAR Read_Byte(uCHAR cNum)
{
    uCHAR ix, j;
    uCHAR cRetval=0;

    for(ix=0;ix<8;ix++){
          Set_SCL_High;
          while(SCL_Low){};
          for(j=0;j<TWD_SHORT_TIME;j++){};
          cRetval = (SDA_High)? (cRetval|(1<<(7-ix))):cRetval ;  // MSB First
	  Set_SCL_Low;
     }

     if(cNum==1)
     	Set_SDA_High;
     else
		Set_SDA_Low;
     //SDA = (cNum==1) 1:0;
     Set_SCL_High;
     while(SCL_Low){};
     for(j = 0; j < TWD_SHORT_TIME; j++)
     { };

    Set_SCL_Low;

    Set_SDA_High;
    for(j = 0; j < TWD_SHORT_TIME; j++)
    { };

    return cRetval;
}
uCHAR I2CReadByte(uCHAR cAddr, uCHAR cReg)
{
	uCHAR cTemp;

	StartCondition();
	Send_Byte(cAddr);
	Send_Byte(cReg);
	StartCondition();
	Send_Byte(cAddr|0x01);
	cTemp=Read_Byte(1);
 	StopCondition();

	return cTemp;
}
uCHAR I2CWriteByte(uCHAR cAddr,uCHAR cReg,uCHAR cData)
{
	StartCondition();
	Send_Byte(cAddr);
	Send_Byte(cReg);
	Send_Byte(cData);
 	StopCondition();
	return 0;
}
void I2CWriteTbl(char *pString)
{
	uCHAR cAddr,cReg,cNum0,cNum1,cINC;
  while(*pString != EOT)
  {
		cAddr=*pString++;
		cNum0=*pString++;
		while(cNum0)
		{
			cReg=*pString++;
			cNum1=*pString++;
			cNum0-=(cNum1+2);
			if(cNum1!=1)
			{
				cINC=*pString++;
				cNum1-=1;
			}
			while(cNum1--)
			{
				I2CWriteByte(cAddr,cReg,*pString++);
				cReg+=cINC;
			}
		 }
   }
}

uCHAR twdWr_Burst_A(uCHAR cReg)
{
    StartCondition();
    if(!Send_Byte(TW100))
    {
        if(!Send_Byte(cReg))
        {
            return(0);               //
        }
    }
    return(1);                  //
}

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);

}

/*void twdWr_Burst_DQ(uCHAR cData)
{
    uCHAR ix;
//uCHAR cAcknowledge;
//    uCHAR cTWtrytime=0;
//    cAcknowledge = 0;

    for(ix = 0; ix < 8; ix++)
    {
        Set_SCL_Low;
        if(cData&0x1)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);

}*/



void twdWr_Burst_P(void)
{
    StopCondition();
}

/*void twdDelay(uWORD wLoops)
{
	uWORD wTemp;

    while (wLoops--) {
	    wTemp = 1000/6;	// one loop below takes about 11 us
        while (wTemp--);
    }
}
*/

// OSD config register Write
void OSDCfgWr(uCHAR index,uCHAR dat)
{
 I2CWriteByte(TW100,OSD_CFG_INDEX,index);
 I2CWriteByte(TW100,OSD_CFG_DATA,dat);
}

//*****************************************************
bit Filter13(bit le)
{
	bit r;
	r=INT1;
	if(le==1)
	{
		_nop_();
		_nop_();
		_nop_();
		r&=INT1;
		_nop_();
		_nop_();
		_nop_();
		r&=INT1;
	}
	else
	{
		_nop_();
		_nop_();
		_nop_();
		r|=INT1;
		_nop_();
		_nop_();
		_nop_();
		r|=INT1;
	}
	if(r==le)
		return 1;
	else
		return 0;
}
/*遥控接收在此中断程序内完成
  数据放在ir_data内*/
/************************************/
/*  Interrupt for IR subroutine     */
/*  external interrupt source INT0  */
/************************************/
void int1Remote(void) interrupt 2
{
	unsigned int mask=1; //sary !LSB first

	register BYTE i;
	unsigned int count;		/*计时变量*/
	unsigned int  temp0,temp1,ir_code=0;
	ir_enable=TRUE;
	TMOD=0x11;             /*timer 0 operate in 16 bit mode*/
	EX1=0;
	TL0=0;
	TH0=0;
	TR0=1;
	/************************************/
	/*   Detect IR Head                 */
	/************************************/
	do                /*Detect IR head 9mS*/
	{
		count=(TL0+TH0*256);   /*count :us unit */
		if(Filter13(1)==1) break;
	}while(count<=(IR_HEAD+DELTA));
	TR0=0;			/*停止计时*/

	if(Filter13(0)==1||count<(IR_HEAD-DELTA*25))       /*for some noise disturb IR*/
		{
		ir_enable=FALSE; /* no IR head or not suitable for Ir head*/
		EX1=1;
		TR0=1;
		return;
		}
	/************************************/
	/*   Detect OFF CODE     4.5mS      */
	/************************************/
	while(Filter13(0)==1);
	TR0=0;
	TL0=0;
	TH0=0;
	TR0=1;
	do                /*Detect IR OFF CODE*/
	{
		count=(TL0+TH0*256);   /*count :us unit */
		if(Filter13(0)==1) break;
	}while(count<(OFF_CODE+DELTA));
	TR0=0;
	count=(TL0+TH0*256);   /*count :us unit */
	if(count<=(OFF_CODE-DELTA*4))
	{
		/*重复码OFF=2.25*/
		if((count>(OFF_REP-DELTA)&&count<(OFF_REP+DELTA)))
		{     TR0=0;
		      TL0=0;
	              TH0=0;
		      TR0=1;

			do
			{
				count=(TL0+TH0*256);   /*count :us unit */
				if(Filter13(1)==1) break;
			}while(count<=(REP_CODE+DELTA));
			TR0=0;
			count=(TL0+TH0*256);   /*count :us unit */
			if(INT1==1)
			{
				TR0=0;

				if(ir_data==LEFT||ir_data==RIGHT)
				{
				ir_enable=TRUE;	/*注意:ir_data不变*/
				EX1=0;
				}
				else
				{
				ir_data=0;
				ir_enable=FALSE;
				EX1=1;
				TR0=1;
				}
				return;
			}
		}
                else if(count>(OFF_REP+DELTA))
                {

                 ir_enable=TRUE;	/*注意:ir_data不变*/
	         EX1=0;

                }
		else
		{
			ir_enable=FALSE;   /*not suitable for off code*/
			EX1=1;
			TR0=1;
			return;
		}
	}

⌨️ 快捷键说明

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