📄 main.c
字号:
/*****************************************************************************/
/* */
/* TW880x Demo Board Techwell,Inc */
/* */
/* CPU : Winbond 78E62BP-40 */
/* LANGUAGE : Tasking C / Keil C */
/* PROGRAMMER : Jooyeon Lee / Harry Han */
/* */
/*****************************************************************************/
/* See 'Release.txt' for firmware revision history */
#include "Config.h"
#include "reg.h"
#include "typedefs.h"
#include "main.h"
#include "tw88.h"
#include "i2c.h"
#include "adc.h"
#include "cc.h"
#include "osdbasic.h"
#include "dispinfo.h"
#include "debug.h"
#include "etc_eep.h"
#include "eds.h"
#include "measure.h"
#include "Printf.h"
#include "tuner.h"
#include "audio.h"
#include "osdmenu.h"
#include "pc_eep.h"
#include "KeyRemo.h"
#include "rgbmix.h"
#include "panel.h"
#ifdef SUPPORT_TELETEXT
#include "TeleText.h" // for teletext
#endif // SUPPORT_TELETEXT
void Loader(BYTE);
extern CODE BYTE NTSC_Regs[];
extern CODE BYTE PAL_Regs[];
#ifdef ADD_ANALOGPANEL
extern CODE BYTE NTSC_Regs_Analog[];
extern CODE BYTE PAL_Regs_Analog[];
#endif
#ifdef SUPPORT_COMPONENT
extern CODE BYTE COMP_YPbPr_480I_Reg[];
extern CODE BYTE COMP_YPbPr_576I_Reg[];
#ifndef WQVGA
extern CODE BYTE COMP_YPbPr_480P_Reg[];
extern CODE BYTE COMP_YPbPr_576P_Reg[];
extern CODE BYTE COMP_YPbPr_1080I_Reg[];
extern CODE BYTE COMP_YPbPr_720P_Reg[];
#endif
#endif
#ifdef SUPPORT_GAMMA
extern CODE BYTE GammaRed[];
extern CODE BYTE GammaBlue[];
extern CODE BYTE GammaGreen[];
#endif
IDATA BYTE InputSelection;
// IDATA BYTE InputSelectionInx = 0;
/// bit PcDetectFlag = 1;
// bit PowerMode = ON;
IDATA WORD IVF;
IDATA DWORD IHF;
static IDATA BYTE VInputStd;
bit Range4Coarse=0;
BYTE VInputStdDetectMode;
static IDATA BYTE I2CAddressDeb;
BYTE CheckBuf;
CODE struct struct_IdName struct_InputSelection[]={
{ UNKNOWN , "" }, //don't remove or change this.
{ COMPOSITE , "CVBS" }, //don't remove or change this.
// you can change the order of the followings
#ifdef SUPPORT_SVIDEO
{ SVIDEO , "S-Video" },
#endif
#ifdef SUPPORT_COMPONENT
{ COMPONENT , "Component" },
#endif
#ifdef SUPPORT_DTV
{ DTV , "DTV-SOG" },
#endif
#ifdef SUPPORT_TV
{ TV , "TV" },
#endif
#ifdef SUPPORT_PC
{ PC , "PC-HV"},
#endif
#ifdef SUPPORT_DIGITALVGA
{ DIGITALVGA , "DVI" },
#endif
{0 , ""}, //don't remove or change this.
};
CODE struct struct_IdName struct_VInputStd[]={
{ UNKNOWN , "" }, //don't remove or change this.
{ NTSC, "NTSC"}, //don't remove or change this.
#ifdef SUPPORT_PAL
{ PAL, "PAL"},
#endif
#ifdef SUPPORT_SECAM
{ SECAM, "SECAM"},
#endif
#ifdef SUPPORT_PALM
{ PALM, "PALM"},
#endif
#ifdef SUPPORT_PALN
{ PALN, "PALN"},
#endif
#ifdef SUPPORT_PAL60
{ PAL60, "PAL60"},
#endif
#ifdef SUPPORT_NTSC4
{ NTSC4, "NTSC4.43"},
#endif
{0 , ""}, //don't remove or change this.
};
CODE BYTE PanelInfoStr[]={
#if (defined UXGA) // 1600 x 1200
"---> Panel: UXGA-1600*1200"
#elif (defined SXGA) // 1280 x 1024
"---> Panel: SXGA-1280*1024"
#elif (defined XGA) // 1024 x 768
"---> Panel: XGA-1024*768"
#elif (defined SVGA) // 800 x 600
"---> Panel: SVGA-800*600"
#elif (defined VGA) // 640 x 480
"---> Panel: VGA-640*480"
#elif (defined WXGA) // 1280 x 768 (15:9) // 1366 x 768 (16:9)
"---> Panel: WXGA-1280*768(15:9) or 1366*768(16:9)"
#elif (defined WSVGA) // 1024 x 600 *** only video mode
"---> Panel: WSVGA-1024*600"
#elif (defined WVGA) // 800 x 480
#ifdef AU_10INCH
"---> Panel: WVGA-800*480 -- TTL AU 10inch"
#elif (defined SAMSUNG_10INCH)
"---> Panel: WVGA-800*480 -- TTL SAMSUNG 10inch"
#elif (defined SAMSUNG_TICONLESS_10INCH)
"---> Panel: WVGA-800*480 -- TICONLESS SAMSUNG 10inch"
#elif (defined SHARP_TICONLESS_7INCH)
"---> Panel: WVGA-800*480 -- TICONLESS SHARP 7inch"
#elif (defined AU_TICONLESS_7INCH)
"---> Panel: WVGA-800*480 -- TICONLESS AU 7inch"
#elif (defined AU_TICONLESS_10INCH)
"---> Panel: WVGA-800*480 -- TICONLESS AU 10inch"
#elif defined HITACHI_T01
"---> Panel: WVGA-800*480 -- TICONLESS Hitachi TX18D24VM2BAA"
#elif defined HITACHI_TX23D12
"---> Panel: WVGA-800*480 -- TICONLESS Hitachi TX23D12"
#endif
#elif (defined HVGA) // 480 x 320
"---> Panel: HVGA-480*320"
#elif (defined QVGA) // 320 x 240 *** only video mode
"---> Panel: QVGA-320*240"
#elif (defined WQVGA) // 480 x 234 *** only video mode
#ifdef ANALOG_7INCH
"---> Panel: WQVGA-480*234 -- ANALOG TICONLESS AU 7inch"
#elif (defined SHARP_LQ043T3DX02)
"---> Panel: WQVGA-480*234 -- TTL SHARP LED 4.3inch panel"
#endif
#endif
};
#ifdef ADD_ANALOGPANEL // Added Analog panel(AU7") from default set panel(expect WQVGA) with DIP #1 switch.(DIP#1=L:ANALOG, H:DEFAULT)
CODE BYTE AddedAnalogPanelStr[]={
#ifdef ADD_ANALOG_7INCH
"---> Added Analog Panel(AU 7inch) with DIP SW1=Enabled"
#elif defined ADD_TMD_LTA05B352A
"---> Added Analog Panel(TMD 4inch) with DIP SW1=Enabled"
#endif
};
#endif
//===================== OSD ===================================================
PDATA WORD OSDLastKeyInTime; // in ms
//===================== Button Key ============================================
bit RepeatKey=0;
//===================== Timer =================================================
DATA WORD tm01=0;
DATA BYTE tic01=0; //, tic_pc;
DATA WORD tic_pc=0;
static DATA DWORD SystemClock; //00:00
static DATA DWORD LastBlockedTime; //00:00
#ifdef SUPPORT_TW88_CC_DECODER
static DATA DWORD LastCCTime; //ljy010904...CC_FIX_CLEAR_ON_TIME ( sec )
#endif
//static DATA WORD WakeupTime;
//static DATA BYTE WakeupPR;
static DATA WORD OffTime;
static DATA BYTE SleepTimer;
static DATA WORD SleepTime;
//===================== Serial ================================================
#ifdef SERIAL
#define BUF_MAX 4//6
static DATA BYTE RS_buf[BUF_MAX];
static PDATA BYTE RS_in, RS_out;
bit RS_Xbusy=0; // bit RS_Xbusy=0;
//================== Debug key input ==========================================
#ifdef DEBUG_TELETEXT
#define MaxBuf 30 // 1+sp+2+sp+2+sp+2+sp+2+sp+2+dum =17
#define MaxArg 10 // for vestel
#else
#define MaxBuf 14 // 1+sp+2+sp+2+sp+2+sp+2+sp+2+dum =17
#define MaxArg 6 // for vestel
#endif
static PDATA BYTE commdbuf[MaxBuf], commdptr, bptr;
static PDATA BYTE arg[MaxArg], argn;
static bit eol, cerror; // bit eol, cerror;
static bit indirect=0; // For indirect address access
#endif // SERIAL
//================== Remocon ==================================================
#ifdef REMO_RC5
static bit RemoPhase1, RemoPhase2;
IDATA BYTE RemoDataReady=0;
IDATA BYTE RemoSystemCode, RemoDataCode;
#elif defined REMO_NEC
static bit RemoPhase=0;
static PDATA BYTE RemoStep=0;
static PDATA BYTE RemoHcnt, RemoLcnt;
BYTE RemoData[4];
IDATA BYTE RemoDataReady=0;
static IDATA BYTE RemoNum, RemoBit;
IDATA BYTE RemoDataCode=0xff;
#endif
//================= Etc. ======================================================
#ifdef WIDE_SCREEN
PDATA BYTE WideScreenMode;
#endif
PDATA BYTE DebugLevel;
bit Flag4AutoPanelRegs = 0;
bit I2CAutoIncFlagOn = 0;
#ifdef SUPPORT_COMPONENT
PDATA BYTE ComponentMode;
PDATA WORD OLD_hpn;
#endif
extern IDATA BYTE PcMode;
//extern bit OnChangingValue;
extern PDATA BYTE TVInputSel;
#ifdef SUPPORT_DEBUG
extern bit Debug_On;
#endif
#ifdef CHIP_MANUAL_TEST
extern PDATA BYTE ManualFrequency;
extern bit OnChipTest;
#endif
#ifdef NO_INITIALIZE
bit NoInitAccess=0;
#endif
//#ifdef SUPPORT_CCD_VCHIP
//extern bit VchipWindow_On;
//#endif
//static bit TestStop=0; // RYU TEST
bit DisplayInputHold = 0;
/*****************************************************************************/
/* Ext Int 1 Interrupt */
/*****************************************************************************/
//_interrupt(2) void ext1_int (void)
INTERRUPT(2, ext1_int)
{
EX1 = 0;
}
//****************************************************************************/
// Timer 0 Interrupt
// If TL0 overflow,
// .Invoke this interrupt
// .TL0 <- TH0
// TL0 is incremented every machine cycle
// Every machine cycle is 12*Tosc(11.0592MHz)
//
// Every machine cycle = 1.085us
// Interrupt interval = 208us ( 1.085*(256-64(TH0)) )
// When tm001==48, it's 0.01sec. 48*208us
//
//****************************************************************************/
DATA BYTE tm001;
DATA BYTE keytic=0;
DATA BYTE Key=0;
bit KeyReady=0;
#define _ReadKey() ( ((~P4>>2)& 0x01) | (~P1 & 0xfc) )
////////////////////////////////
INTERRUPT(1, timer0_int)
{
/*
tm001++;
//---------- 0.01 sec timer ------------
#ifdef CLOCK_11M
if( tm001 > 48 )
{ // LJY001220 0.01sec
#elif defined CLOCK_22M
if( tm001 > 48*2 )
{ // LJY001220 0.01sec
#endif
tm001 = 0;
tic01++;
if( tic01==100 )
{ // 1 sec
SystemClock++;
tic01 = 0;
}
if( tic_pc!=0xffff )
tic_pc++;
if( _ReadKey() )
{
if( keytic==3 )
{
Key = _ReadKey();
RepeatKey = 0;
KeyReady = 1;
}
else if( keytic==100 )
{
Key = _ReadKey();
RepeatKey = 1;
KeyReady = 1;
keytic = 80;
}
keytic++;
}
else
keytic = 0;
}
}
*/
}
//=============================================================================
// Remocon
//=============================================================================
void EnableRemoconInt(void)
{
RemoDataReady = 0;
IE = IE | 0x01; // Enable Remocon (Enable Ext int0)
}
void DisableRemoconInt(void)
{
IE = IE & 0xfe; // Disable Remocon (Disable Ext int0)
}
#ifdef REMO_RC5
void InitForRemo(void)
{
WORD temp;
#if defined CLOCK_11M
#ifdef TECHWELL_REMOCON // DONGYANG
temp = 0x10000 - 193; // 209.62us = 1.085*193
#else
temp = 0x10000 - 204; // 221.34us = 1.085*204
#endif
#elif defined CLOCK_22M
#ifdef TECHWELL_REMOCON // DONGYANG
temp = 0x10000 - 193*2; // 209.62us = 1.085/2*193*2
#else
temp = 0x10000 - 204*2; // 221.34us = 1.085/2*204*2
#endif
#endif
RCAP2H = TH2 = temp>>8;
RCAP2L = TL2 = (BYTE)(temp & 0xff);
TR2 = 1;
tm01 = 4;
RemoPhase1 = 1;
RemoSystemCode= RemoDataCode=0;
TR2 = 1;
tm01 = 4;
RemoPhase1 = 1;
RemoSystemCode= RemoDataCode=0;
}
#elif defined REMO_NEC
void InitForRemo(void)
{
WORD temp;
#if defined CLOCK_11M
temp = 0x10000 - 173; // 187.71us = 1.085*173
#elif defined CLOCK_22M
temp = 0x10000 - 173*2;
#endif
RCAP2H = TH2 = temp>>8;
RCAP2L = TL2 = (BYTE)(temp & 0xff);
TR2 = 1;
tm01 = 0;
RemoStep = 0;
RemoPhase = 0;
RemoHcnt = 0;
RemoLcnt = 0;
}
#endif
void ClearRemoTimer(void)
{
TR2 = 0;
}
///****************************************************************************
///* Ext Int 0 Interrupt
///****************************************************************************
//_interrupt(0) void remocon_int (void)
INTERRUPT(0, remocon_int)
{
DisableRemoconInt();
InitForRemo();
}
//#endif //SUPPORT_REMO
//****************************************************************************/
// Timer 2 Interrupt
// If TH2 and TL2 are overflowed,
// .Invoke this interrupt
// .TH2 <- RCAP2H
// .TL2 <- RCAP2L
// TL2 is incremented every machine cycle
// Every machine cycle is 12*Tosc(11.0592MHz)
//
// Every machine cycle = 1.085us
// Interrupt interval
// 1) REMO_RC5
// 221.34us ( 1.085*204 ) // (256-52) (0x10000-0xff34)
//
// data length: 14bit (2sync bits, 1 control bit, 11 data bits) 24,889ms
//
// +----+
// 1 is coded: | |
// +----+
// T T
//
// +----+
// 0 is coded: | |
// +----+
// T T T = 889us
//
// *) DongYang
// 209.62 ( 1.085*193 ) // (256-63) (0x10000-0xff3f)
//-----------------------------------------------------------------------------
// 2) REMO_NEC
// 187.714us ( 1.085*173 ) // (256-83) (0x10000-0xff53)
//
//****************************************************************************/
INTERRUPT(5, timer2_int)
{
TF2 = 0; // clear overflow
tm01++;
#ifdef REMO_RC5
{
BYTE i;
i = tm01 & 0x07;
if( i>=1 && i<=2 )
RemoPhase1 = P3_2;
else if( i>=5 && i<=6 )
RemoPhase2 = P3_2;
else
;
if( i==0 )
{ //every 8 tm01
if( RemoPhase1==RemoPhase2 )
{ // error
ClearRemoTimer();
EnableRemoconInt();
return;
}
if( tm01<=(8*8) )
{ // start control system
RemoSystemCode <<=1;
if( RemoPhase1==1 && RemoPhase2==0 )
RemoSystemCode |=1;
}
else
{ // data
RemoDataCode <<=1;
if( RemoPhase1==1 && RemoPhase2==0 )
RemoDataCode |=1;
}
}
if( tm01 > (8*14) )
{
RemoDataReady++; //LJY051502 RemoDataReady = 1; // new key
ClearRemoTimer();
//RemoOver = 0;
}
}
#elif defined REMO_NEC
{
if( RemoDataReady ) return;
switch( RemoStep )
{
case 0:
if( P3_2==0 )
{
RemoLcnt++;
if( RemoLcnt==0xff ) goto RemoError;
}
else
{
RemoHcnt = 0;
RemoStep++;
}
break;
case 1:
if( P3_2==1 )
{
RemoHcnt++;
if( RemoHcnt==0xff ) goto RemoError;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -