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

📄 t100.c.bak

📁 在51单片机上用C写的T100,T101TFT屏的控制程序,有OSD
💻 BAK
📖 第 1 页 / 共 4 页
字号:
#include "REG51.H"
#include <intrins.h>
#include "Common.h"
#include "Remote.h"
//#include "Struct.h"
#include "OSDDraw.h"
//#include "OSDCtrl.h"
//#include "Video.h"
#include "TwoWire.h"
#include "TW100Reg.h"

#include "T100Data_AU.h"
//////////////////////////////////////////////////
#include "KSP7001.h" // function declaration
#include "OSD_main.h"
#include "OSD_source.h"
#include "OSD_audio.h"
#include "OSD_video.h"
#include "OSD_screen.h"
#include "OSD_system.h"
/////////////////////////////////////////////////



sbit 	T100_RESET	= P1^4;
sbit    SCL 		= P1^6;
sbit	SDA 		= P1^7;
sbit	BL_EN		= P0^7;
/*#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*/
//EEPVIDEO   idata EepVideo;
/*uCHAR bdata Flag1;
uCHAR bdata Flag2;

sbit m_bPanelClose      = Flag1 ^ 0;
sbit m_bBKPowerOn		= Flag1 ^ 1;
sbit m_bKyPowerOn 		= Flag1 ^ 2;
sbit m_bChipPowerOn		= Flag1 ^ 3;
sbit m_bTimer0Overflow  = Flag1 ^ 4;
sbit m_bOSDEnable       = Flag1 ^ 5;
sbit ir_enable          = Flag1 ^ 6;
sbit m_bKyblocked		= Flag1 ^ 7;
sbit m_bFactryMode		= Flag2 ^ 0;
sbit m_bFactryReady		= Flag2 ^ 1;
sbit m_bRelease			= Flag2 ^ 2;
sbit m_bAir_Cable		= Flag2 ^ 3;
sbit m_bTV_Num_Bits		= Flag2 ^ 4;
sbit m_bTV_Skip			= Flag2 ^ 5;*/
/*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 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
bit ir_enable   =0;
//bit bGAMMA_ADJ   =0;      //0: Nomral            1: Gamma Adjust
uCHAR idata ir_data;
uCHAR idata cSource	= 5;      //2-4:CVBS2-4         5:S-Video       6:ITU656
uCHAR idata cStandard	= 0xff;   //0:PAL               4:NTSC
//uCHAR idata c60HZ_Mode=0;
//uCHAR idata c50HZ_Mode=0;
//uCHAR idata cKey_Curr,cKey_Pre;

//uCHAR idata Repeat_Times;
//uWORD idata m_wBuff[3];
//uCHAR idata m_cBuff[5];
//uCHAR idata m_cOSDEvent;
//uCHAR idata m_cOSDFunc;
//uCHAR idata m_cCurreKey;
//uCHAR idata m_cPreKey;
//uCHAR idata m_cItem;
//uCHAR idata m_cGammaFlag;

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*);
//bit IRGammaAdjust(void);
uCHAR I2CReadByte(uCHAR, uCHAR);
uCHAR I2CWriteByte(uCHAR,uCHAR,uCHAR);

//IR
//void IRSourceSelCtrl(void);
//void IRSCALEREvent(void);
//void IRDismodeEvent(void);
//bit IRDECREASEEvent(void);
//bit IRINCREASEEvent(void);
//bit IRMENUEvent(void);
//bit IRDownKeyCtrl(void);
//bit IRUpKeyCtrl(void);

//bit ir_auto = 0;

//uCHAR idata AddPoint=0;
//uCHAR idata GammaBuffer=0;
//void AdjustGammmaDate(void);
//void SaveEeprom(void);

////////////////////////////////////////////////////
// OSD variables
/////////////////////////////////////////////////////////
// key flag
bit osd = 0;
bit enter = 0;
bit up = 0;
bit down = 0;
bit left = 0;
bit right = 0;

//variable for auto press
//bit AutoRemo=0;
//unsigned int AutoRemo_time=0;

bit OSD_enable; //0:disable, 1:enable
unsigned int OSD_time=0;

//cursor position/state
//bit modify; //0 modify disable, 1 modify enable
uCHAR window; //0 OSD main menu
            //1 OSD sub-menu
            //2 Reset question

unsigned char cursor1, cursor2;

//OSD main menu

//unsigned char source_val; //source chosen
unsigned char CurMode;

//Audio
  /*  unsigned char bass; //0(-7)->14(+7)
    unsigned char treble; //0(-7)->14(+7)
    unsigned char balance; //0(L7)->14(R7)
    unsigned char fade; //0(F7)->14(R7)*/

    unsigned char	Aud_BassLevel;		//'0~15d'
    unsigned char	Aud_TrebleLevel;	//'0~15d'
    unsigned char	Aud_BalanceLevel;	//'0~15d'
    unsigned char	Aud_FaderLevel;		//'0~15d'

    unsigned int AudioStatus=0;
    /*
    bit subwoofer; //0 off, 1 on
    bit beep; //0 off, 1 on*/

    //unsigned char start_vol; //0->50
    unsigned char 	Aud_IniVol;		//	'0~45d'

//Video
    unsigned char bright;
    unsigned char contrast;
    unsigned char color;
    unsigned char sharp;
//screen
    unsigned int	VideoStatus=0;
 /*
    bit direction; //1 inverse, 0 normal
    bit full;    //0 4:3, 1 16:9
  */
//System
    //unsigned char in_out; //0 none, 1 level-1,
                          //2 level-2, 3 level-3
    unsigned char MinoutState;

    //unsigned char tilt_range; //2 auto, 3 1-3,
                              //4 1-4, 5 1-5
    unsigned char TiltLimit;

    //unsigned char tv_sys; //0 NTSC, 1 PAL, 2 CHINESE
     unsigned char ChannelType;

    //unsigned char tv_sound; //0 sound-3, 1 sound-1
                            //2 sound-2
    unsigned char PalType;

    //bit tilt; //0 auto, 1 manual
    unsigned int TiltFlag0;
    //bit backlight; //0 normal, 1 bright

//Reset
    bit reset_valid; //0: no   1:ok

void main(void)
{
	Initial();
        OSDInit();
        KSP7001_Init();
	while(1)
	{
	    DetectNTSC_PAL();
             if(ir_enable)
               {ir_enable=0;
           	   RemoteEvent();
                }
           else if(!EX1)
		{
			EX1=1;
			ir_data=0;
		}
            if(osd)
            {
                if(!OSD_enable)
                    OSD_OpenMain();
                else
                {
                    OSDExit();
                    OSD_enable = 0;
                }
                osd=0;
            }
            if(OSD_enable)
            {
    	        if(enter) OSD_Enter();
                if(up || down) OSD_UpDown();
                if(left || right) OSD_LeftRight();

                if(OSD_time>300)
                {
                    OSDExit();
                    OSD_time=0;
                }
                OSD_time++;
            }
		//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();
/*	EepVideo.cBright=0x80;
	EepVideo.cContrast=0x80;
	EepVideo.cSharp=0x05;
	EepVideo.cSat=0x80;
	EepVideo.cHue=0x80;*/
//	m_cGammaFlag=I2CReadByte(EEPBLOCK0,0x10);
	/*if(m_cGammaFlag==0xA3)
	      AdjustGammmaDate();
        else
              SaveEeprom();*/
//	SetUD_LR();
       // OSDInit();
       // OSDShowSource();
}//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();
}//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(TW101+4, 0x3c)&0x04; /
   			    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;
	                   SetMode();
                           Delay_ms(100);
		           OpenPanel();
                           Delay_ms(10);
                        }
            else OpenPanel();
		}

}
void SetSource(void)
{
	cSource=2;
	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);
	}
//	OSDShowSource();
}
void SetMode(void)//N/P,Full/4:3
{
// uCHAR data i;
	if(bNTSC_PAL)//NTSC&&FULL
	{
		I2CWriteTbl(NTSC_FULLData);
		if((!bFULL_43))//NTSC&&4:3
			I2CWriteTbl(NTSC_43Data);
		if(cSource!=5)
		{
		      I2CWriteByte(TW100+4,0x03,0x00);
		      I2CWriteByte(TW100+4,0x00,0x00);
	  }
    else
    {
          I2CWriteByte(TW100+4,0x03,0x03);
          I2CWriteByte(TW100+4,0x00,0x01);
    }
                /*I2CWriteTbl(NTSC443Data);
                if(cSource!=5){
                       I2CWriteByte(TW100+4,0x03,0x03);
		       I2CWriteByte(TW100+4,0x00,0x00);
                 }
                else{
                       I2CWriteByte(TW100+4,0x03,0x03);
                       I2CWriteByte(TW100+4,0x00,0x01);
                    }*/
		/*I2CWriteTbl(PAL_MData);
		 if(cSource!=5){
		       I2CWriteByte(TW100+4,0x03,0x00);
		       I2CWriteByte(TW100+4,0x00,0x04);
		      }
                  else{
                        I2CWriteByte(TW100+4,0x03,0x03);
                         I2CWriteByte(TW100+4,0x00,0x05);
                       }*/
                /*  I2CWriteTbl(PAL_60Data);
		if(cSource!=5){
		      I2CWriteByte(TW100+4,0x03,0x02);
		      I2CWriteByte(TW100+4,0x00,0x02);
	             }
                else{
                      I2CWriteByte(TW100+4,0x03,0x03);
                      I2CWriteByte(TW100+4,0x00,0x03);
                     }*/
/*#if 0
                switch(c60HZ_Mode)
                {
                        case 1: I2CWriteTbl(NTSC443Data);
                                if(cSource!=5)
                                {
                                     I2CWriteByte(TW100+4,0x03,0x03);
		                                 I2CWriteByte(TW100+4,0x00,0x00);
		                            }
                                else
                                {
                                     I2CWriteByte(TW100+4,0x03,0x03);
                                     I2CWriteByte(TW100+4,0x00,0x01);
                                 }
				                         break;
                        case 2:
                                I2CWriteTbl(PAL_60Data);
                                 if(cSource!=5)
                                 	{
                                     I2CWriteByte(TW100+4,0x03,0x02);
		                                 I2CWriteByte(TW100+4,0x00,0x02);
		                              }
                                  else{
                                     I2CWriteByte(TW100+4,0x03,0x03);
                                     I2CWriteByte(TW100+4,0x00,0x03);
                                   }
				                          break;
                        case 3: I2CWriteTbl(PAL_MData);
                                 if(cSource!=5)
                                 	{
                                     I2CWriteByte(TW100+4,0x03,0x00);
		                                 I2CWriteByte(TW100+4,0x00,0x04);
		                             }

⌨️ 快捷键说明

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