cpu.c
来自「显示屏驱动源代码」· C语言 代码 · 共 1,202 行 · 第 1/3 页
C
1,202 行
// Hans
if (cDelayCounter > 0)
cDelayCounter--;
}
}
void PowerDown( void )
{
// LCDPowerOFF();
// PowerLED(OFF);
// WriteTW88(TW88_OSDLOCKUPSEL, (ReadTW88(TW88_OSDLOCKUPSEL)|0x10)); // OSD All Off (TW8806B)
WriteTW88( MCU_STOP_MODE, (ReadTW88(MCU_STOP_MODE) | 0x80) ); // set bit7 to 1
PCON = PCON | 2; // enter stop mode
}
/*****************************************************************************/
/* Ext Int 3_n Interrupt : implements interrup service */
/*****************************************************************************/
WORD TW88IRQ = 0;
//INTERRUPT(9, ext3_int)
void ext3_int(void) interrupt 9 using 1
{
BYTE page;
EXIF = EXIF & 0xDF; // clear interrupt 3;
page = ReadTW88(0xff);
WriteTW88(REG_PAGE, 0);
TW88IRQ = ReadTW88( STATUS0 );
TW88IRQ <<= 8;
TW88IRQ += ReadTW88( STATUS1 );
WriteTW88( STATUS0, 0xff ); // clear change bits
WriteTW88( STATUS1, 0xff ); // clear change bits
WriteTW88(REG_PAGE, page);
//EIE &= 0xFD; // disable interrupts
}
/*****************************************************************************/
/* Ext Int 5_n Interrupt : Power Down sequence */
/*****************************************************************************/
//INTERRUPT(11, ext5_int)
void ext5_int(void) interrupt 11 using 1
{
WORD i;
EXIF = EXIF & 0x7F; // clear interrupt 5;
// EA = 0; // disable all interrupts
// EX5 = 0;
// P2 = 0xf0;
for ( i=0; i<0xFF0; i++ ) ; // wait for some time...
if ( POWER_DOWN == 1 ) {
PowerDown();
//PCON = PCON | 2; // enter stop mode
}
else {
// EA = 1;
}
}
//------------------------------------------------------------------
// void InitVars(void) - variable initialize
//------------------------------------------------------------------
void InitVars(void)
{
SystemClock=0; //00:00
LastBlockedTime=0xffffffff; //00:00 //ljy010904...CC_FIX_CLEAR_ON_TIME..oops! previous vchip clear error
OffTime=0xffff;
SleepTimer=0;
SleepTime=0xffff;
DebugLevel = 0;
RemoDataReady = 0;
}
//------------------------------------------------------------------
// void InitTechwell(void) - Techwell Decoder initialize
//------------------------------------------------------------------
void InitTechwell( void )
{
#ifdef NO_INITIALIZE
if( ReadKey()==MENUKEY ) {// No Initialize
NoInitAccess =1;
Printf("\r\n No-initialize Test going on with MENU KEY pressed ..: %d\n", (WORD)P0_3);
return;
}
#endif
LCDPowerOFF();
InitCCFL(); // Hans
ConfigPanel(); // Hans
ConfigTCON(); // Hans
Puts("\r\n\nDetect ");
switch( ReadTW88(0) ) {
case 0x21: Puts("TW8816"); break;
case 0x49: Puts("TW8817"); break;
default: Printf("Nothing --0x%02x\r\n", (WORD)ReadDecoder(0));
while(1) {
#ifdef SERIAL
if( RS_ready() ) break;
#endif
Printf("Check again --0x%02x\r\n", (WORD)ReadDecoder(0));
delay(99);
if( ReadTW88(0)==0 ) continue;
if( ReadTW88(0)==0xff ) continue;
break;
}
delay(99);
delay(99);
Printf("Last Check --0x%02x\r\n", (WORD)ReadDecoder(0));
break;
}
#ifdef ADD_ANALOGPANEL
if(IsAnalogOn())
Printf("%s \n", AddedAnalogPanelStr);
else
#endif
Printf("%s \n", PanelInfoStr);
CheckSpecialMode();
DebugLevel = 0xff;
main_init();
}
//=============================================================================
// Power LED ON / OFF
//=============================================================================
void PowerLED(BYTE flag)
{
#define GREEN_LED P1_7
#define RED_LED P1_6
if( flag==ON ) {
RED_LED = 0; // ON RED
GREEN_LED = 0; // ON GREEN
dPuts("\r\n(PowerLED)-ON");
}
else {
RED_LED = 0; // ON RED
GREEN_LED = 1; // OFF GREEN
dPuts("\r\n(PowerLED)-OFF");
}
}
#else
//=============================================================================
// Initialize WINBOND CPU
//=============================================================================
void InitCPU(void)
{
CHPENR = 0x87; // Enable AUX RAM in Winbond(W78E516B)
CHPENR = 0x59; //
CHPCON = 0x10; //
CHPENR = 0x00; // Write Disable
/*----- 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; // 0100 0000 mode 1 - 8 bit UART
// Enable serial reception
TMOD = 0x22; // 0010 0010 timer 0 - 8 bit auto reload
// 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
TH0 = TL0 = 64; // 64=4608 Hz at 11.0592MHz
PCON = 0x80; // 0000 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
//------------ Timer 2 for Remocon --------------------------------
T2CON = 0x00; // Timer2 Clear
TR2 = 0;
ET2 = 1;
//-----------------------------------------------------------------
P4=0x0f;
}
#define _ReadKey() ( ((~P4>>2)& 0x01) | (~P1 & 0xfc) )
////////////////////////////////
//INTERRUPT(1, timer0_int)
void timer0_int(void) interrupt 1 using 1 // interrupt number1, bank register 2
{
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;
///////////////////////////////////////////
// Hans
if (cDelayCounter > 0)
cDelayCounter--;
}
}
//------------------------------------------------------------------
// void InitVars(void) - variable initialize
//------------------------------------------------------------------
void InitVars(void)
{
SystemClock=0; //00:00
LastBlockedTime=0xffffffff; //00:00 //ljy010904...CC_FIX_CLEAR_ON_TIME..oops! previous vchip clear error
OffTime=0xffff;
SleepTimer=0;
SleepTime=0xffff;
SEL_DVI= 1; // disable Digital VGA
// ResetKey();
DebugLevel = 0;
RemoDataReady = 0;
P0_7 = 1;
delay(100);
PowerDown_XTAL(0);
TW88HWReset = 1; delay(1);
}
//------------------------------------------------------------------
// void InitTechwell(void) - Techwell Decoder initialize
//------------------------------------------------------------------
void InitTechwell( void )
{
#ifdef NO_INITIALIZE
if( P0_3==0 ) {// No Initialize
NoInitAccess =1;
Printf("\r\n No-initialize Test going on with DIP SW4 ..: %d\n", (WORD)P0_3);
return;
}
#endif
LCDPowerOFF();
InitCCFL(); // Hans
ConfigPanel(); // Hans
ConfigTCON(); // Hans
Puts("\r\n\nDetect ");
switch( ReadTW88(0) ) {
case 0x21: Puts("TW8816"); break;
case 0x49: Puts("TW8817"); break;
default: Printf("Nothing --0x%02x\r\n", (WORD)ReadDecoder(0));
while(1) {
#ifdef SERIAL
if( RS_ready() ) break;
#endif
Printf("Check again --0x%02x\r\n", (WORD)ReadDecoder(0));
delay(99);
if( ReadTW88(0)==0 ) continue;
if( ReadTW88(0)==0xff ) continue;
break;
}
delay(99);
delay(99);
Printf("Last Check --0x%02x\r\n", (WORD)ReadDecoder(0));
break;
}
#ifdef ADD_ANALOGPANEL
if(IsAnalogOn())
Printf("%s \n", AddedAnalogPanelStr);
else
#endif
Printf("%s \n", PanelInfoStr);
CheckSpecialMode();
main_init();
}
//=============================================================================
// Power LED ON / OFF
//=============================================================================
void PowerLED(BYTE flag)
{
#define GREEN_LED P0_4
#define RED_LED P0_5
if( flag==ON ) {
GREEN_LED = 0; // ON GREEN
RED_LED = 0; // ON RED
dPuts("\r\n(PowerLED)-ON");
}
else {
GREEN_LED = 1; // OFF FREEN
RED_LED = 0; // ON RED
dPuts("\r\n(PowerLED)-OFF");
}
}
#endif
//------------------------ common routines with interrupts --------------------
/*****************************************************************************/
/* Ext Int 1 Interrupt */
/*****************************************************************************/
//INTERRUPT(2, ext1_int)
void ext1_int(void) interrupt 2 using 1
{
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
//
//****************************************************************************/
#ifndef INTERNAL_MCU
#define _ReadKey() ( ((~P4>>2)& 0x01) | (~P1 & 0xfc) )
#endif
//=============================================================================
// Remocon
//=============================================================================
#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
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?