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

📄 main.c

📁 TFT LCD驱动芯片T100A+AU7" Source code
💻 C
字号:
//---------------------------------------------------------------------------
// Terawins Inc. Company Confidential Strictly Private
//
// $Archive: Main.c $
// $Revision: 1.01 $
// $Author: JasonGuo $
// $Date: 2004/05/06 $
//
// --------------------------------------------------------------------------
// >>>>>>>>>>>>>>>>>>>>>>>>> COPYRIGHT NOTICE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// --------------------------------------------------------------------------
// Copyright 2004 (c) Terawins Inc.
//
// This is an unpublished work.
// --------------------------------------------------------------------------

#include "reg51.h"
#include "math.h"
#include "common.h"
#include "system.h"
#include "struct.h"
#include "TW101Reg.h"
#include "twowire.h"
#include "gamma.h"
#include "filter.h"
#include "keypad.h"
#include "Nvram.h"
#include "Video.h"
#include "T101_Util.h"
#include "remote.h"
#include "osddraw.h"


//****************************************************************************
// Private Function Prototypes
//****************************************************************************
void Initial            (void);
void SysInit	    	(void);
void InitFactry			(void);

void SysInterruptEnable (void);
void ClosePanel         (void);
void OpenPanel          (void);
void BKPower            (void);
void PowerManage        (void);
void InitPt2313			(void);
//void Exchange_PAL_NTSC  (void); //Kuo
void RegisterSetting(void);


#ifdef TIMER0
void Timer0Reset		(void);
void Timer0Start		(void);
void Timer0Stop			(void);
#endif

uCHAR bdata Flag1;
uCHAR bdata Flag2;
uCHAR bdata Flag3;

uCHAR idata m_cOSDEvent;
uCHAR idata m_cOSDFunc;
uCHAR idata m_cSource;
uCHAR ir_data;
uCHAR m_cFactryCnt;
//uCHAR idata m_cStandard=4;//PAL
uCHAR idata m_cStandard=0;//NTSC
uCHAR idata m_cScaleratio=ScaleFULL;
uWORD m_wHRes;
uWORD m_wVRes;
uWORD XCLK_MCU;

uWORD idata m_wVTotal;
uCHAR cPAL_Dot=5,cNTSC_Dot=4;
uCHAR cSTV1_ON;
uCHAR cSTV_OFFSET;
uCHAR cPAL_OFFSET,cNTSC_OFFSET,cGATE_PREDRIVE;
uCHAR cFactry_Addr=0x00,cFactry_Data;
bit bFactry_Menu,bFactry_Func;
#ifdef TV
uCHAR idata m_cTV_Num;
uCHAR m_cSoundSystem=PAL_I;
#endif

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;
uWORD idata m_wBuff[3];
uCHAR idata m_cBuff[5];
uDWORD m_dwBuff[2];
//----------------------------------------------------------------------------
//Main Function
//----------------------------------------------------------------------------
extern unsigned char Win_Flag;

unsigned int D_Count;

#define DEBUG_C  0


void main(void)
{
	  m_wBuff[2]=DETECT_TIMER-1;
//	I2CWriteByte(0xa0, 0xd9, 0x00);
	  InitFactry();
//System Initial
	  Initial();
	  SysInterruptEnable();
#ifdef TVP5150
    I2CWriteByte(0xba,0x00, 0x02);
    I2CWriteByte(0xba,0x03, 0x09);
#endif
//上电开机流程
	  m_cSource = I2CReadByte(EEPVIDEOBLOCK, idVIDEO_SOURCE_INDEX)&0x0f;
	  if(m_cSource==0) m_cSource=1;	 
    SourceSelect();
//OSD Font Initial
    OSDInit();
	  Detect_NTSCPAL(); 
 	  OSDShowSource();
    OpenPanel();
 	  if(!m_bBKPowerOn)
 		BKPower();
//Main loop
	  while(1)
	  {
        kyKeypad();
        if(ir_enable)
        {
           	RemoteEvent();
			      ir_enable=0;
        }
        else if(!EX1)
		    {
			      EX1=1;
		    }//*/
        if(m_bTimer0Overflow)
        {
            if(m_bOSDEnable) OSDExit();                
        }//*/
		    Detect_NTSCPAL(); 
#if DEBUG_C
        D_Count ++;
        if(D_Count >= 100)
        {
            D_Count = 0;
		        if(Win_Flag == 0) Win_Flag = 1;
						else              Win_Flag = 0;
						if(Win_Flag == 1) Osd_Window_Enable();
						else              Osd_Window_Disable();
        }
#endif
	}
}
//**************************************************************************
//Power ON/OFF  BackLight ON/OFF Panel ON/OFF
//**************************************************************************



void ClosePanel(void)
{
	m_bPanelClose = 1;
	I2CWriteByte(TW101, 0xC2, I2CReadByte(TW101, 0xC2)|(PSYNC_STR|IGNORE_VSYNC));
	I2CWriteByte(TW101, PATTERN_CTRL, 0x87);//I2CReadByte(TW101, PATTERN_CTRL)|0x80);  //Enable Frame Background Color
}

void OpenPanel(void)
{
	m_bPanelClose = 0;
/*	if(!m_cStandard)I2CWriteByte(TW101, 0xB8, (I2CReadByte(TW101, 0xb8)-cNTSC_Dot));
	else
	I2CWriteByte(TW101, 0xB8, (I2CReadByte(TW101, 0xb8)-cPAL_Dot));*/
	I2CWriteByte(TW101, 0xC2, I2CReadByte(TW101, 0xC2)&~(PSYNC_STR|IGNORE_VSYNC));
	I2CWriteByte(TW101, PATTERN_CTRL, I2CReadByte(TW101, PATTERN_CTRL)&~0x80); //Enable Frame Background Color
//	twdDelay(100);	
}
void BKPower(void)
{
	if(m_bBKPowerOn)
	{
  		BKLIGHT_EN = 1;     // BKLIGHT shut down
		twdDelay(100);
		m_bBKPowerOn = 0;
	}
	else
	{
		twdDelay(100);
		BKLIGHT_EN = 0;     // BKLIGHT power on
		m_bBKPowerOn = 1;
	}
}

void PowerManage(void)
{
 	if(m_bKyPowerOn) //Power on
	{
		LED_RED = 1;	//Turn Off
		LED_GREEN = 0;   	//Turn On
		I2CWriteByte(TW101, 0xE0, I2CReadByte(TW101, 0xE0)|TPDB);
		m_cOSDEvent=0;
		m_cOSDFunc=0;
		//When power on chip, force to reset chip
		m_bChipPowerOn=1;
		twdDelay(100);
		OpenPanel();
 			if(!m_bBKPowerOn)
 				BKPower();
	}
	else 	//Forced Power Off
	{
		if(m_bChipPowerOn)
		{
			LED_RED =0;			//Turn On
		    LED_GREEN = 1;   	//Turn Off
			twdDelay(100);
			OSDExit();
 			if(m_bBKPowerOn)
 				BKPower();
			ClosePanel();
			twdDelay(200);
			I2CWriteByte(TW101, 0xE0, I2CReadByte(TW101, 0xE0)&~TPDB|PDMD);
			m_bChipPowerOn=0;
		}
	}
}

//**************************************************************************
//系统初始化函数
//**************************************************************************
void Initial(void)
{
extern EEPVIDEO   idata EepVideo;	
    SysInit();
#ifdef TCON
	TconInit();
#endif
#ifdef RSDS
	RsdsInit();
#endif
//Ruby modify 2005-06-07
	ClosePanel();
	OSDDisable();
	LoadGammaTable(0);
	LoadFilter(3);   //Ruby 2004-10-07
//    EepVideo.cSharp=0;
// 	LoadFilter(3); //del charles
//	RegisterSetting();
//  LoadFilter(3);  

//    OSDLogo();
}

void SysInit(void)
{
	P0=0xff;
	P1=0xff;
	P2=0xff;
	P3=0xff;
//Chip Reset
	CHIP_RESET = 0;
    VIDEO_RESET=0;
	twdDelay(100);
	CHIP_RESET = 1;
    VIDEO_RESET=1;
	twdDelay(50);
//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;

	twdDelay(10);
//  	if(!m_bPanelClose)
//  	ClosePanel();

#ifdef NVRAM
	EEPLoadPubData();
#else
	OSDFactryReset();
	OSDResetPubData();
	//OSDResetVideoData();
	OSDSetValues();
#endif
	InitTW101();
	InitPt2313();
	kyKeypadInit();

	m_bPanelClose = 0;
	m_bBKPowerOn=0;
	m_bKyPowerOn=1;
	m_bChipPowerOn=1;

	LED_GREEN=0;
//Ruby add
	IRScaleratioCtrl();

}
void SysInterruptEnable(void)
{
#ifdef TIMER1
//	Timer1Reset();
	ET1 = 1;    // Enable Timer1 interrupt
	TR1=0;
#endif
#ifdef TIMER0
	Timer0Reset();
	ET0 = 1; 	// Enable Timer0 interrupt
	TR0 = 0;
#endif
#ifdef INTERRUPT1
	EX1 = 1;		// Enable INT1 (IR)
#endif
	EA	 = 1;		// Enable Interrupt
}
void InitFactry(void)
{
	if(!(ReadPort()&kyMENU))
	{
	twdDelay(NVRDELAY);
		I2CWriteByte(0xa0, 0x0f ,0x01);
	twdDelay(NVRDELAY);

	}	
	if(I2CReadByte(0xa0, 0x0f ))
	{
	twdDelay(NVRDELAY);
		I2CWriteByte(0xa0, 0x0f ,0x00);
	twdDelay(NVRDELAY);
		I2CWriteByte(0xa0, 0x10 ,0x0A);
	twdDelay(NVRDELAY);
		I2CWriteByte(0xa0, 0x11 ,0x08);
	twdDelay(NVRDELAY);
		I2CWriteByte(0xa0, 0x12 ,0x01);
	twdDelay(NVRDELAY);
		I2CWriteByte(0xa0, 0x13 ,0x06);//STV_OFFSET
	twdDelay(NVRDELAY);
		I2CWriteByte(0xa0, 0x14 ,0x0f);//PAL_OFFSET
	twdDelay(NVRDELAY);
		I2CWriteByte(0xa0, 0x15 ,0x12);//NTSC_OFFSET
	twdDelay(NVRDELAY);
		I2CWriteByte(0xa0, 0x16 ,0x03);//Gate_Drive_Predriving
	twdDelay(NVRDELAY);
	}
	ReadFactryData();
}

⌨️ 快捷键说明

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