📄 main.c
字号:
/****************************************************************************
* File: MAIN.c *
* Description: main routine *
* History: 2005/08/12 *
* *
* Copyright 2005 (c) Terawins Inc. *
****************************************************************************/
/****************************************************************************
* Include File *
****************************************************************************/
#include "MCU.h"
#include "reg51.h"
#include "math.h"
#include "common.h"
#include "MCU.h"
#include "struct.h"
#include "system.h"
#include "twowire.h"
//#include "gamma.h"
#include "filter.h"
#include "keypad.h"
#include "Nvram.h"
#include "Video.h"
#include "T101_Util.h"
#include "TW10xReg.h"
#include "remote.h"
#include "osdctrl.h"
#include "osddraw.h"
#include "tuner.h"
#include "T515.h"
#ifdef T100A
#include "T100OSD.h" // add by Sherman
#else //T102
#include "T102OSD.h" // add by Sherman
#endif
/*****************************************************************************
* Public Function Prototypes *
*****************************************************************************/
void Initial (void);
void SysInit (void);
void SysInterruptEnable (void);
void ClosePanel (uCHAR uR, uCHAR uG, uCHAR uB);
void OpenPanel (void);
void BKPower (void);
void PowerManage (void);
#ifdef TIMER0
void Timer0Reset(void);
void Timer0Start(void);
void Timer0Stop(void);
#endif
/****************************************************************************
* Public Global Variable *
****************************************************************************/
//uCHAR bdata Flag1;
//uCHAR bdata Flag2;
//uCHAR bdata Flag3;
uCHAR bdata Flag1;
uCHAR bdata Flag2;
uCHAR bdata Flag3;
uCHAR idata m_cOSDEvent;
uCHAR idata m_cOSDFunc;
uCHAR idata m_cOSDMenu;
uCHAR idata m_cSource;
uCHAR ir_data;
uCHAR m_cFactryCnt;
//uCHAR idata m_cStandard=4;//PAL
uCHAR idata m_cStandard=S_NTSC;//NTSC
uCHAR idata m_cChroma=S_NTSC; //NTSC // add by Sherman 06'01'13
uCHAR idata m_cScaleratio=ScaleFULL;
uWORD m_wHRes;
uWORD m_wVRes;
uWORD idata m_wVTotal;
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];
/****************************************************************************
* Public Function *
****************************************************************************/
//uCHAR code iBright_E1 []={0x01,0x02,0x03,0x04,0x05};
void main(void)
{
Initial();
SysInterruptEnable();
//OSD Font Initial
OSDInit();
//twdDelay(NVRDELAY);
m_cSource = I2CReadByte(EEPVIDEOBLOCK, idVIDEO_SOURCE_INDEX)&0x0f;
#if (defined T106) | (defined T116)
if((m_cSource<5)||(m_cSource>=isrc_end))
m_cSource=5;
#else
if((m_cSource==0)||(m_cSource>=isrc_end))
m_cSource=1;
#endif
m_cSource=1;
SourceSelect();
m_bPanelClose = 0; // sm 06'04'07
ClosePanel(0x00,0x40,0x8a); // sm 06'04'07
SetSignalStd();
SetOPTiming();
twdDelay1(20);
DetectSignalStd();
OSDShowSource();
OpenPanel();
//I2CWriteByte(TW101, 0xC7, 0x07);zhonghuadong
//Main loop
//detect key press
//I2CWriteByte(TW101, 0xE9, 0x30);
I2CWriteByte(TW101, 0xE8, 0x12); // PWM General Control Reg
I2CWriteByte(TW101, 0xEB, 0xFF); // ??
I2CWriteByte(TW101, 0xEA, 0x10); // ??
I2CWriteByte(TW101, 0xE3, 0x00); // RGB-565 Input Sel
I2CWriteByte(TW101, 0x0a, 0x60); // ADC ACR Channel Offset
I2CWriteByte(TW101, 0x0b, 0x61); // ADC AY Channel Offset
I2CWriteByte(TW101, 0x1a, 0x83); // Analog AGC Sel
I2CWriteByte(TW101, 0x1c, 0x9d); //Blank sync level
I2CWriteByte(TW101, 0x60, 0x01); // Bandwidth of digital color transient improvement
I2CWriteByte(TW101, 0xe5, 0x10);//zhonghuadong ???
I2CWriteByte(TW101, 0xe6, 0x10);//zhonghuadong ???
I2CWriteByte(TW101, 0xe9, 0x00);//zhonghuadong PWM Active high time counter
I2CWriteByte(TW101+4, 0x01,0x09); // Bandwidth control
// I2CWriteByte(TW101+4, 0x07, 0x23);
I2CWriteByte(TW101+4, 0x0f, 0x0c); // ???
I2CWriteByte(TW101+4, 0x80, 0x03); // Luma peaking Control
I2CWriteByte(TW101+4, 0x3f, 0x01); // Soft reset start
twdDelay1(20);
I2CWriteByte(TW101+4, 0x3f, 0x00); // soft reset end
// I2CWriteByte(TW101, 0x9f, uB);
while(1)
{
// OSDPosition(CENTER);
// OsdShowIcon(0x27,1,1,0x2F);
// OSDEnable ();
kyKeypad();
//handle ir event
if(ir_enable){
RemoteEvent();
ir_enable=0;
}
else if(!EX1){
EX1=1;
ir_data=0;
}
//OSD Timeout
if(m_bTimer0Overflow){
if(m_bOSDEnable)
OSDExit();
}
m_wBuff[2]+=1;
#ifdef AUTO_DETECT
// if(m_wBuff[2]>=0x4ff){
m_wBuff[2]=0x00;
DetectSignalStd();
Detect_Sig(0);
// }
#endif
}
}
void ClosePanel(uCHAR uR, uCHAR uG, uCHAR uB)
{
if(!m_bPanelClose){
m_bPanelClose = 1;
I2CWriteByte(TW101, 0xC2, I2CReadByte(TW101, 0xC2)|(PSYNC_STR|IGNORE_VSYNC));
I2CWriteByte(TW101, 0x9d, uR);
I2CWriteByte(TW101, 0x9e, uG);
I2CWriteByte(TW101, 0x9f, uB);
// I2CWriteByte(TW101, 0x90, 0x00);
I2CWriteByte(TW101, PATTERN_CTRL, 0x87);//I2CReadByte(TW101, PATTERN_CTRL)|0x80); //Enable Frame Background Color
I2CWriteByte(TW101, 0xe2, 0x11);
}
}
void OpenPanel(void)
{
if(m_bPanelClose){
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
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
MCU_PORT6_F38[7]=0;
I2CWriteByte(TW101, 0xE0, I2CReadByte(TW101, 0xE0)|TPDB); // reset video decoder
m_cOSDEvent=0;
m_cOSDFunc=0;
//When power on chip, force to reset chip
m_bChipPowerOn=1;
//m_cSource=0x0F;
twdDelay(100);
OpenPanel();
//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(0x00,0x40,0x8a);
twdDelay(200);
I2CWriteByte(TW101, 0xE0, I2CReadByte(TW101, 0xE0)&~TPDB|PDMD);
m_bChipPowerOn=0;
}
}
}
void Initial(void)
{
extern EEPVIDEO idata EepVideo;
SysInit();
#ifdef TCON_PANEL
TconInit();
#endif
//Ruby modify 2005-06-07
ClosePanel(0x00,0x40,0x8a);
OSDDisable();
LoadGammaTable(0);
//OSDLogo();
}
void SysInit(void)
{
#ifndef CUSTMCU
PADMOD2=0xcf; //
P0=0xff;
P1=0xff;
P2=0xff;
P3=0xff;
#endif
#ifdef CUSTMCU
BYTE i;
// PADMOD = PAD PORT TYPE
MCU_PADMODE_F50 = 0x00; // No A/D is used
MCU_PADMODE_F51 = 0x3F; // sel: P5.0~P5.5 I/O pin
MCU_PADMODE_F52 = 0x80; // HSCL1,HSDA1, P5.6~P5.6, P6.6
MCU_PADMODE_F53 = 0xFF; // All set as output pin
MCU_PADMODE_F54 = 0xFF; // All set as output pin
MCU_PADMODE_F55 = 0x00; // standard 8051 pin for P1
MCU_OPTION_F56 = 0x88; //
MCU_PADMODE_F5E = 0x00;
MCU_PADMODE_F5F = 0xC0; // P77/P76 output
MCU_EINT1PEN_F8E = 0x80;
for (i=0; i<8;i++)
{
MCU_PORT6_F38[i] =0;
//MCU_PORT6_F38[1] =0;
}
/*
MCU_IICCTR_F00 = 0x00; //x.hu, for P5.7 read only zero. 0xC0; // Enable IIC Interface and define ddc2 active at HSDA/HSCL
MCU_INTFLG_F03 = 0x00; // Clear IIC Interrupt register
MCU_INTEN_F04 = 0x00; // Detect WslvA1 IIC Stop Condition
MCU_DDCCTRA1_F06 = 0x52; // Enable DDC1 and DDCRAM 128 Access
MCU_SLVA1ADR_F07 = (0x80 | (0xA0 >> 1)); // DDC Slave A1 address
MCU_SLVBADR_F09 = (0x80 | (0x74 >> 1)); // DEBUG Slave address
MCU_CTRSLVB_F0A = 0x02;
MCU_DDCCTRA2_F86 = 0x52; // Enable DDC1 and DDCRAM 128 Access
MCU_SLVA2ADR_F87 = (0x80 | (0xA0 >> 1)); //DDC Slave A2 address
*/
#endif
//Chip Reset
CHIP_RESET = 0;
VIDEO_RESET=0;
twdDelay(60);
CHIP_RESET = 1;
VIDEO_RESET=1;
twdDelay(20);
//8051Register Set
IE = 0; // disable all interrupt
TMOD = 0x11; // Timer1 Mode 1, Timer0 Mode 1; mode1 = 16 bit timer
//TMOD = 0x01; // Timer0 Mode 1;
EX0 = 0; // disable external interrupt 0, IE[0]
EX1 = 0; // disable external interrupt 1
//ET0 = 1; // enable bTimer 0
//IT0 = 1; // falling endge generate interrupt, TCON[0]
INT0 = 1; // set low to INT0 port
IT1 = 1; // falling endge generate interrupt, TCON[0] for IR receiving
INT1 = 1; // set low to INT1 port
//twdDelay(10);
//ClosePanel(0x00,0x40,0x60);
#if (defined T100)|(defined T101)
LoadFilter(3);//3
#endif
#ifdef T101A
LoadFilter(0);//2
#endif
#ifdef T102
//LoadFilter(6);
#endif
InitT10x();
#ifdef NVRAM
#ifdef RESET_EEPROM
InitEEPRom();
OSDResetVideoData();
#else
EEPLoadPubData();
#endif
#endif
kyKeypadInit();
m_bPanelClose = 0;
m_bBKPowerOn=0;
m_bKyPowerOn=1;
m_bChipPowerOn=1;
LED_GREEN=0;
}
void SysInterruptEnable(void)
{
#ifdef TIMER1
// Timer1Reset();
ET1 = 1; // Enable Timer1 interrupt
TR1=0; // Timer 1 run control bit
#endif
#ifdef TIMER0
Timer0Reset();
ET0 = 1; // Enable Timer0 interrupt
TR0 = 0; // Timer 0 run control bit
#endif
#ifdef INTERRUPT1
EX1 = 1; // Enable INT1 (IR)
#endif
EA = 1; // Enable Interrupt
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -