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

📄 main.c

📁 宏芯T102芯片驱动(51单片机作主控)
💻 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"
#include "tuner.h"
#include "T515.h"
//****************************************************************************
// Private Function Prototypes
//****************************************************************************
void Initial            (void);
void SysInit	    	(void);

void SysInterruptEnable (void);
void ClosePanel         (void);
void OpenPanel          (void);
void BKPower            (void);
void PowerManage        (void);
//void Exchange_PAL_NTSC  (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_cOSDPreFunc;
uCHAR idata m_cOSDFunc;
uCHAR idata m_cOSDMenu;
uCHAR idata m_cOSDFactoryMenu;
uCHAR idata m_cSource;
uCHAR idata m_cMode;
uCHAR idata m_cLang;

uCHAR m_cFactryCnt;
//uCHAR idata m_cStandard=S_PAL;//PAL
uCHAR idata m_cStandard;//=S_NTSC;//NTSC
uCHAR idata m_cScaleratio=ScaleFULL;
uWORD m_wHRes;
uWORD m_wVRes;
uWORD idata m_wVTotal;

#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;
sbit Key				= Flag2 ^ 6;
sbit AdjustSig			= Flag2 ^ 7;

uWORD idata m_wBuff[3];
uCHAR idata m_cBuff[5];
uDWORD m_dwBuff[2];
extern uCHAR ir_data;

//----------------------------------------------------------------------------
//Main Function
//----------------------------------------------------------------------------
void main(void)
{
	//unsigned int i;
	Key = 0;
	Initial();
	SysInterruptEnable();
//OSD Font Initial
	m_cLang = I2CReadByte(EEPVIDEOBLOCK, idVIDEO_LANGUAGE_INDEX)&0x0f;
	if((m_cLang==0)||(m_cLang>=L_END))	 m_cLang=1;
	m_cMode=1;
    OSDInit();
	/* enable interrupt */
	I2CWriteByte(TW101,INT_MASK,0xF0); 
//上电开机流程
	m_cSource = I2CReadByte(EEPVIDEOBLOCK, idVIDEO_SOURCE_INDEX)&0x0f;
	if((m_cSource==0)||(m_cSource>=isrc_end)) m_cSource=1;
	#ifdef TV
     SetTuner(TVSetChannel(I2CReadByte(EEPVIDEOBLOCK, idTVCHANNEL_INDEX)-1));	 
    #endif	
    SourceSelect();
 	OSDShowSource();
/*#ifdef Guanlin
	m_cOSDEvent = FUNCADJ_IN;
	m_cSource =  isrc_T515_CVIDEO2;
	I2CWriteByte(EEPVIDEOBLOCK, idVIDEO_SOURCE_INDEX,m_cSource);
	SourceSelect();     
	OSDShowSource();
#endif*/
    OpenPanel();
	SetNTSC_PAL();	   
//Main loop
	while(1)
	{
//detect key press 		
			kyKeypad();	        
//handle ir event
        if(ir_enable)
        {
           	//for(i= 0;i< 10000;i++)
			//	;
			RemoteEvent();
			ir_enable=0;
        }
        else if(!EX1)
		{
			EX1=1;
			ir_data=0;
		}			  
//OSD Timeout
        if(m_bTimer0Overflow)
        {
            if(m_bOSDEnable)
                OSDExit();
        }

#ifdef AUTO_DETECT
   	  	m_wBuff[2]+=1;
	  	if(m_wBuff[2]>=0x4ff)
	  	{
			m_wBuff[2]=0x00;
		//kyRotate();
			Detect_NTSCPAL();
			Detect_Sig(0);
			if((AdjustSig==0)&&(Key == 0))
				OSDLogo();
			else if(AdjustSig==1)
				Detect_Sig(0);	
	  	}		


#endif
		
	}		
}
//**************************************************************************
//Power ON/OFF  BackLight 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;
//	I2CWriteByte(TW101, 0xC2, I2CReadByte(TW101, 0xC2)&~(PSYNC_STR|IGNORE_VSYNC));
//	I2CWriteByte(TW101, PATTERN_CTRL, I2CReadByte(TW101, PATTERN_CTRL)&~0x80); //Enable Frame Background Color
	I2CWriteByte(TW101,0x90,0x06);
	I2CWriteByte(TW101,PATTERN_CTRL,0x00);	
	I2CWriteByte(TW101,0xC2,0x00);	
	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;
#ifdef LEDCONTROL
		m_bLedOn=1;
#endif

	}
}

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); // when bit TPDB is 1,power on whole chip and pull up pad
		m_cOSDEvent=0;
		m_cOSDFunc=idNULLMENU;
		//When power on chip, force to reset chip
//		m_bForceReset=1;
		m_bChipPowerOn=1;
		//m_cSource=0x0F;
		twdDelay(100);
		OpenPanel();
		m_bBKPowerOn=1;   //add by zjl		*/
		BKLIGHT_EN = 0;  //add by zjl
		I2CWriteByte(EEPVIDEOBLOCK,idVIDEO_POWER_INDEX,BKLIGHT_EN);
		
//AUDIO_STANBY=0;		//Audio on
	}
	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;
		} */
		BKLIGHT_EN = 1;
//		OSDLogo();
		OSDEnable();
		OSDInit();
		I2CWriteByte(EEPVIDEOBLOCK,idVIDEO_POWER_INDEX,BKLIGHT_EN);
		switch(m_cSource)////add by cwyong for audio
					{
						case isrcCVIDEO1:
							Audio0 = 0;
							Audio1 = 0;
							break;
						case isrcCVIDEO2:
							Audio0 = 0;
							Audio1 = 0;
							break;
						case isrcSVIDEO:
							Audio0 = 0;
							Audio1 = 0;
							break;
						default:
							Audio0 = 1;
							Audio1 = 1;
							break;
					}
	}
}

//**************************************************************************
//系统初始化函数
//**************************************************************************
void Initial(void)
{
extern EEPVIDEO   idata EepVideo;
m_cStandard=S_NTSC;	
    SysInit();
#ifdef TCON
	TconInit();
#endif
#ifdef RSDS
	RsdsInit();
#endif	
//	SetNTSC_PAL();   Ruby modify 2004 4/4 if initial now output timing will error
//Ruby modify 2004-06-07	
	ClosePanel();
	OSDDisable();
	LoadGammaTable(0);
 	LoadFilter(0);
	PowerManage();
    OSDLogo();
#ifdef T515
		Init_T515();
#endif
}

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

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

	m_bPanelClose = 0;
	m_bBKPowerOn=1;
	m_bChipPowerOn=1;
//	FactoryModeEn=0;
	AdjustSig=1;
	//m_bAir_Cable=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
}

⌨️ 快捷键说明

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