cpu.c
来自「显示屏驱动源代码」· C语言 代码 · 共 1,202 行 · 第 1/3 页
C
1,202 行
/* CPU.c */
#include "config.h"
#include "typedefs.h"
#include "reg.h"
#include "regmap.h"
#include "cpu.h"
#include "main.h"
#include "I2C.h"
#include "TW88.h"
#include "Printf.h"
#include "KeyRemo.h"
#include "etc_eep.h"
#include "pc_eep.h"
#include "Audio.h"
#include "Measure.h"
#include "OSDBasic.h"
#include "OSDMenu.h"
#include "DispInfo.h"
#include "Monitor.h"
#ifdef SUPPORT_TV
#include "Tuner.h"
#endif
#define ClearRemoTimer() TR2 = 0
extern BYTE DebugLevel;
extern IDATA BYTE RemoDataReady,RemoSystemCode, RemoDataCode;
extern IDATA BYTE InputSelection;
extern BYTE VInputStdDetectMode;
extern IDATA BYTE PcMode;
extern bit AutoDetect;
extern bit NoInitAccess;
//===================== Timer =================================================
DATA BYTE keytic=0;
DATA BYTE Key=0;
bit KeyReady=0, RepeatKey = 0;
DATA BYTE tm001;
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
//static DATA WORD WakeupTime;
//static DATA BYTE WakeupPR;
static DATA WORD OffTime;
static DATA BYTE SleepTimer;
static DATA WORD SleepTime;
static DATA BYTE cDelayCounter; // Hans
#ifdef SERIAL //=======================================================================
#define BUF_MAX 4//6
static DATA BYTE RS_buf[BUF_MAX];
static DATA BYTE RS_in, RS_out;
bit RS_Xbusy=0; // bit RS_Xbusy=0;
#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 DATA BYTE RemoStep=0;
static DATA BYTE RemoHcnt, RemoLcnt;
DATA BYTE RemoData[4];
IDATA BYTE RemoDataReady=0;
static IDATA BYTE RemoNum, RemoBit;
IDATA BYTE RemoDataCode=0xff;
#endif //================== Remocon ======================
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"
#elif defined HITACHI_TX18D24
"---> Panel: WVGA-800*480 -- TICONLESS Hitachi TX18D24"
#else
"---> Panel: WVGA-800*480"
#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"
#else
"---> Panel: WQVGA-480*234 "
#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
//=============================================================================
// CheckSpecialMode
//=============================================================================
void CheckSpecialMode(void)
{
BYTE i;
i = GetKey(0);
switch( i ) {
case MENUKEY:
Puts("\r\n---- Menu Key is pressed -> Enter Special Mode( To Composite )");
SaveInputSelectionEE(COMPOSITE);
DebugLevel = 0;
/// PcDetectFlag = 0;
break;
}
}
//=============================================================================
// Main Initialize Routine
//=============================================================================
void main_init (void)
{
extern CODE BYTE *OutOfRangeStr[] ;
#ifdef SUPPORT_MSP_AUDIO
BYTE ikey;
#endif
WORD rev;
#ifdef SUPPORT_PC
BYTE i;
#endif
// WriteTW88(0xff, 0x10); // Disable I2C auto increase mode
WriteTW88(0xe0, 0x10); // Disable I2C auto increase mode
PowerLED(ON);
EnableRemoconInt();
#ifdef SUPPORT_MSP_AUDIO
ikey = ResetMSP();
if( ikey ) {
#ifdef DEBUG
dPrintf("\r\nError on resetting MSP:0x%02x", (WORD)ikey);
#endif
}
#else
ResetMSP();
#endif
rev = GetFWRevEE();
Printf("\r\n New Firmware Base On:%04x", rev);
if( GetFWRevEE()!=FWVER ) { // exist EEPROM
SaveFWRevEE(FWVER);
Printf("\r\nCurr.FW:%04x", GetFWRevEE());
}
//---------- if FW version is not matched, initialize EEPROM data -----------
if( GetFWRevEE()==FWVER ) { // exist EEPROM
if( rev != FWVER ) { //
SaveDebugLevelEE(DebugLevel);
Printf("\r\nNew DebugLevel:%02x", (WORD)DebugLevel);
SaveInputSelectionEE(COMPOSITE);
ClearBasicEE();
#ifdef SUPPORT_PC
ResetPanelAttributeValue();
SaveDefaultPCDataAllEE();
#endif
#ifdef SUPPORT_TV
ResetTVValue();
#endif
}
else {
DebugLevel = GetDebugLevelEE();
Printf("\r\nSaved DebugLevel:%02x", (WORD)DebugLevel);
}
#ifdef SUPPORT_PC
if( DebugLevel > 0 ) {
for(i=0; i<EE_PC_MAX+1; i++)
WriteEEP( EE_PCDATA + LEN_PCDATA*i, 0 );
}
#endif
}
#ifdef SUPPORT_GAMMA
DownLoadGamma();
#endif
VInputStdDetectMode = GetVInputStdDetectModeEE();
if( VInputStdDetectMode != AUTO )
SetVInputStd( VInputStdDetectMode );
else
SetVInputStd( NTSC );
SetPossibleAutoDetectStdEE();
//InputSelectionInx = 0;
InputSelection = UNKNOWN; //GetInputSelectionEE();
#ifdef SUPPORT_TV
InitTV();
#endif
ChangeInput( GetInputSelectionEE() );
#ifdef SUPPORT_KRS_OSDDEMO
DownloadUDFont_Only();
Change_OSDColorLookup_KRS();
DisplayKRSOSD();
LCDPowerON(0);
WriteTW88(0xb4, 0x02);
#else
DownloadUDFont();
DisplayLogo();
LCDPowerON(1); // Power on but free run
// DisplayInput();
#endif
AutoDetect = 1;
Puts("\n\rDone!!!");
Prompt();
//////////////////////////////////////////////////////////////////////////////////
// delay(100);
WaitDelay(100); // 100 * 10ms delay
WriteTW88( STATUS0, 0xff); // clear status
WriteTW88( STATUS1, 0xff); // clear status
ClearLogo();
}
// ************************ ifdef INTERNAL_MCU *******************************
#ifdef INTERNAL_MCU
BYTE xdata * data regTW88 = REG_START_ADDRESS;
//=============================================================================
// Initialize CPU
//=============================================================================
void InitCPU(void)
{
SPICONTROL = 0x08; // slow FLASH access mode
/* CLOCK_11M --------------------------------------------------------------------
T0HIGH = 1; // default is 144 but change it to 432 easily makes 0.01s
T0LOW = 176;
T1LOW = 144; // default is 144 for 11.0592MHz makes 4800BPS
---------------------------------------------------------------------------------*/
/* CLOCK_22M ---------------------------------------------------------------------
T0HIGH = 1; // ddefault is 144 but change it to 432 easily makes 0.01s
T0LOW = 176;
T1LOW = 144; // default is 144 for 22.1184MHz makes 9600BPS
---------------------------------------------------------------------------------*/
T0HIGH = 1; // default is 144 but change it to 432 easily makes 0.01s
T0LOW = 176;
T1LOW = 176; // default is 144 for 11.0592MHz but 176 for 27MHz makes 9600BPS
/*----- Initialize interrupt -------------*/
TH1 = 0xff; // SMOD = 0 SMOD =1
// 0ffh :57600 bps
// 0fdh : 9600 bps 0fdh :19200 bps
// 0fah : 4800 bps
// 0f4h : 2400 bps
// 0e8h : 1200 bps
SCON = 0x50; // 0101 0000 mode 1 - 8 bit UART
// Enable serial reception
// TMOD = 0x22; // 0010 0010 timer 0 - 8 bit auto reload
TMOD = 0x66; // 0110 0110 timer 0 - 8 bit auto reload //by yhbae for synopsys core
// timer 1 - baud rate generator
TCON = 0x55; // 0101 0001 timer 0,1 run
// int 0, edge triggered
// int 1, edge triggered
// TF1 TR1 TF0 TR0 EI1 IT1 EI0 IT0
//#if defined CLOCK_11M
// TH0 = 128;
//#elif defined CLOCK_22M
// TH0 = 128; // count 128
//#elif defined CLOCK_27M
TH0 = 131; // count 256 - 125 = 131
//#endif
PCON = PCON | 0x80; // 1000 0000 SMOD(double baud rate bit) = 1
IP = 0x02; // 0000 0000 interrupt priority
// - - PT2 PS PT1 PX1 PT0 PX0
#ifdef SERIAL
IE = 0x92; // 1001 0010 interrupt enable:Serial,TM0
// EA - ET2 ES ET1 EX1 ET0 EX0
TI = 1; // LJY000724 // For Starting Serial TX
ES = 1; // LJY000724
#else
IE = 0x82;
#endif // SERIAL
// EIE = 0x0A; // 0000 1010 : EX5=1, EX3=1;
// EIE = 0x02; // 0000 0010 : EX5=0, EX3=1;
EIE = 0x00; // disable all interrupts
//------------ Timer 2 for Remocon --------------------------------
T2CON = 0x00; // Timer2 Clear
TR2 = 0;
ET2 = 1;
C_T2 = 1; // timer source is external T2
InitForRemo();
//-----------------------------------------------------------------
}
//INTERRUPT(1, timer0_int)
void timer0_int(void) interrupt 1 using 1 // interrupt number1, bank register 2
{
#ifdef DEBUG_TIMER0
static BYTE test;
P2 = test++;
#endif
tm001++;
//---------- 0.01 sec timer ------------
// #ifdef CLOCK_11M
// if( tm001 > 2 ) { // BYH 0.01s with T0H 128, T0 divider by 144*3 = 432
// #elif defined CLOCK_22M
// if( tm001 > 4 ) { // BYH 0.01s with T0H 128, T0 divider by 432
// #elif defined CLOCK_27M
if( tm001 > 5 ) { // BYH 0.01s with T0H 125, T0 divider by 432
// #endif
tm001 = 0;
tic01++;
if( tic01==100 ) { // 1 sec
SystemClock++;
tic01 = 0;
}
if( tic_pc!=0xffff )
tic_pc++;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?