📄 lcd_main.c
字号:
#define __MAIN__
#include "reg52.h"
#include "intrins.h"
#include "MAIN_DEF.H"
#include "CONFIG.H"
#include "ACCESS.H"
#include "LCD_COEF.H"
#include "LCD_FUNC.H"
#include "LCD_AUTO.H"
#include "LCD_MSG.H"
#include "LCD_MAIN.H"
#include "LCD_OSD.H"
#include "FONT.H"
#if(MENU_TYPE == MENU_REL)
#include "OSD_REL.H"
#endif
#if(MENU_TYPE == MENU_KTC)
#include "OSD_KTC.H"
#endif
#include "MTV512.H"
#include "DevOS.h"
#include "Ksv.h"
/////////////////////////////////////////////////////////////
// Interrupt Service Routine for Timer0 (Fired every 20ms) //
/////////////////////////////////////////////////////////////
void IntProc_Timer0(void) interrupt 1
{
#if (IRPOLLING)
//static unsigned char ucIR_Seq = 0xff;
static unsigned char ucTimerCnt = 0x00;
TL0 = TIME0_COUNTER_LBYTE; // Reload Timer0 low-byte
TH0 = TIME0_COUNTER_HBYTE; // Reload Timer0 high-byte
if (ucIR_State)
{
if (bIR_GPIO)
{
ucIR_Seq = (ucIR_Seq << 1) | 0x01;
if ((0xff == ucIR_Seq) && (ucIR_State & 0xfe))
{
ucIR_State = 0; // Command timeout; Back to idle state
((unsigned int *)ucIR_Cmd)[0] = 0;
}
}
else
{
if (1 < ucIR_State)
{
if (ucIR_Seq & 0x01)
{
((unsigned int *)ucIR_Cmd)[0] = (((unsigned int *)ucIR_Cmd)[0] << 1)
| (0x07 != (ucIR_Seq & 0x07) ? 1 : 0);
if (23 == ++ucIR_State && CUSTOM_CODE != ((unsigned int *)ucIR_Cmd)[0])
{
ucIR_State = 0; // Customer code error; Back to idle state
((unsigned int *)ucIR_Cmd)[0] = 0;
}
else if (39 == ucIR_State)
{
ucIR_State = 0; // Command complete; Back to idle state
ucIR_Cmd[1] = 8; // Set command timer to 8 (7*20 = 140ms)
}
}
else if (0x00 == (ucIR_Seq & 0xfe))
{
ucIR_State = 0; // Command crashed; Back to idle state
((unsigned int *)ucIR_Cmd)[0] = 0;
}
}
else // ucIR_State is 1
{
if (0xff == ucIR_Seq)
{
ucIR_State = 0x07; // Start to decode new command and clear old command
((unsigned int *)ucIR_Cmd)[0] = 0;
}
else
{
ucIR_State = 0; // Fire repeat command and reset to idle
ucIR_Cmd[1] = ucIR_Cmd[0] ? 8 : 0;
}
}
ucIR_Seq = ucIR_Seq << 1;
}
}
else if (ucIR_Cmd[1] <= 1)
{
ucIR_Seq = (ucIR_Seq << 1) | bIR_GPIO;
if (0x07 == ucIR_Seq) ucIR_State = 1; // Leader code detected
}
if (54 <= ++ucTimerCnt) // 0.375ms*54 = 20.25ms passed
{
ucTimerCnt = 0;
bNotify_Timer0_Int = 1; // Post Timer0's timeout message
if (usOSD_Timer) usOSD_Timer -= 1; // For OSD Timeout
// Clear command after 144ms if not repeat code
if (0 == ucIR_State)
{
//if (ucIR_Cmd[1] && 0 == --ucIR_Cmd[1]) ucIR_Cmd[0] = 0;
if(ucIR_Cmd[1])
ucIR_Cmd[1] -= 1;
else
ucIR_Cmd[0] = 0;
}
}
#else
TL0 = TIME0_COUNTER_LBYTE; // Reload Timer0 low-byte
TH0 = TIME0_COUNTER_HBYTE; // Reload Timer0 high-byte
bNotify_Timer0_Int = 1; // Post Timer0's timeout message
if (usOSD_Timer) usOSD_Timer -= 1; // For OSD Timeout
#endif
}
///////////////////////////////////////////////////////////////////////
// Interrupt Service Routine for Timer1 (Fired in 1ms after restart) //
///////////////////////////////////////////////////////////////////////
void IntProc_Timer1(void) interrupt 3
{
TR1 = 0; // Stop Timer1
TL1 = TIME1_COUNTER_LBYTE; // Reload Timer1 low-byte
TH1 = TIME1_COUNTER_HBYTE;
// TH1 = (bAutoInProgress == 1) ? TIME1_COUNTER_HHBYTE : TIME1_COUNTER_HBYTE; // Reload Timer1 hifh-byte
bNotify_Timer1_Int = 1; // Post Timer1's timeout message
}
/////////////////////////////////////////////////////////////////////////////////
// Function Routines
/////////////////////////////////////////////////////////////////////////////////
void Delay_Xms(unsigned char x) // For delay 0 ~ 255 ms
{
if (x)
{
bNotify_Timer1_Int = 0; // Clear timer1's timeout message
TR1 = 1; // Start timer1
while (1)
{
if (bNotify_Timer1_Int)
{
TR1 = 0;
bNotify_Timer1_Int = 0; // Clear timer1's timeout message
if (--x) TR1 = 1; // Restart timer1 if not timeout
else return; // Timeout for X ms.
}
}
}
}
void PowerDown_ADC(void)
{
RTDSetByte(PLL1_CTRL_D6, 0xf2); // Power down PLL1
RTDSetByte(PLL2_CTRL_DA, 0x40); // Power down PLL2
RTDSetByte(ADC_CTRL_E6, 0x40); // Power down ADC
}
void PowerUp_ADC(void)
{
RTDSetByte(PLL1_CTRL_D6, 0xf3); // Power up PLL1
RTDSetByte(PLL2_CTRL_DA, 0x41); // Power up PLL2
RTDSetByte(ADC_CTRL_E6, 0x47); // Power up ADC
if(ucID_Code == 0x62)
RTDSetByte(PLL2_FILTER_DD, 0x5f);
else
RTDSetByte(PLL2_FILTER_DD, 0xdf);
}
void PowerDown_TMDS(void)
{
RTDSetByte(TMDS_OUTPUT_ENA_A0, 0x0F);
// Delay_Xms(10);
// RTDSetByte(ANG_PERFORMANCE2_A3, 0x26);
}
void PowerUp_TMDS(void)
{
RTDSetByte(TMDS_OUTPUT_ENA_A0, 0x8F);
// RTDSetByte(ANG_PERFORMANCE2_A3, 0x36);
}
void PowerDown_VDC(void)
{
#if (VIDEO_CHIP != VDC_NONE)
bVDC_PWR = VDC_OFF;
#endif
}
void PowerUp_VDC(void)
{
#if (VIDEO_CHIP != VDC_NONE)
bVDC_PWR = VDC_ON;
#endif
}
void PowerDown_LVDS(void)
{
#if (OUTPUT_BUS == LVDS_TYPE)
RTDCodeW(LVDS_POWERDOWN);
#endif
}
void PowerUp_LVDS(void)
{
#if (OUTPUT_BUS == LVDS_TYPE)
RTDCodeW(LVDS_POWERUP);
#endif
}
void MCU_Init(void)
{
#if(MCU_TYPE == MCU_WINBOND)
IE = 0x00; // Disable all interrupts
TMOD = 0x11; // Program Timer0 & Timer1 to Mode#1
TR0 = 0; // Stop Timer0
TF0 = 0; // Clear Timer0 Overflow Bit
TL0 = TIME0_COUNTER_LBYTE; // Load Timer0 low-byte (for 20ms)
TH0 = TIME0_COUNTER_HBYTE; // Load Timer0 high-byte (for 20ms)
TR1 = 0; // Stop Timer1
TF1 = 0; // Clear Timer1 Overflow Bit
TL1 = TIME1_COUNTER_LBYTE; // Load Timer1 low-byte (for 1ms)
TH1 = TIME1_COUNTER_HBYTE; // Load Timer1 hifh-byte (for 1ms)
IE = 0x8a; // Enable interrupts of Timer0 and Timer1
#else
IE = 0x00; // Disable all interrupts
TMOD = 0x11; // Program Timer0 & Timer1 to Mode#1
TR0 = 0; // Stop Timer0
TF0 = 0; // Clear Timer0 Overflow Bit
TL0 = TIME0_COUNTER_LBYTE; // Load Timer0 low-byte (for 20ms)
TH0 = TIME0_COUNTER_HBYTE; // Load Timer0 high-byte (for 20ms)
TR1 = 0; // Stop Timer1
TF1 = 0; // Clear Timer1 Overflow Bit
TL1 = TIME1_COUNTER_LBYTE; // Load Timer1 low-byte (for 1ms)
TH1 = TIME1_COUNTER_HBYTE; // Load Timer1 hifh-byte (for 1ms)
IE = 0x8a; // Enable interrupts of Timer0 and Timer1
M512_PadMode0=0x00; //p6 not use for ad
M512_PadMode1=0xff; //p5 not use for da
M512_PadMode2=0x80; //p3.01 iic , p5.67 normal
#if(KEY_MODE == KEY_NORMAL) //V226
M512_PadMode3=0x60; //p5.012347 input p5.56 output
#endif //#if(KEY_MODE == KEY_NORMAL) //V226
#if(KEY_MODE == KEY_MATRIX) //V226
M512_PadMode3=0x69; //p5.1247 input p5.0356 output
bPOWER_KEY = 1;
bRIGHT_KEY = 1;
#endif //#if(KEY_MODE == KEY_MATRIX) //V226
M512_PadMode4=0xbe; //p6.06 input p6.123457 output
M512_PadMode5=0x00; //p1 8051 standard IO
M512_PadMode6=0x00; //p7.6 not for clko
M512_PadMode7=0x00; //p7.6, p7.7 input
M512_Option1=0x00; //cpu runing at normal rate
#endif
}
void Firmware_Init(void)
{
bLIGHT_PWR = LIGHT_OFF;
bPANEL_PWR = PANEL_OFF;
MCU_Init();
RTDSetBit(HOSTCTRL_02,0xfb,0x00); // RTD turn on
bRTD_RST = 0;
Delay_Xms(10);
do
{
// Wait for reset complete
bRTD_RST = 1;
Delay_Xms(2);
}
while (!bRTD_RST);
RTDRead(ID_REG_00,1,N_INC);
ucID_Code = Data[0];
RTDCodeW(RTD_PWUP_INI);
#if(HDCP_ENABLE)
RTDCodeW(BKSV);
KEYCodeW(HDCP_KEY_A_Port);
#endif
RTDSetByte(HOSTCTRL_02, 0x40); // Wake RTD up
RTDSetByte(DPLL_CTRL_D0, 0x11); // Enable DPLL
RTDSetByte(VDIS_SIGINV_21, 0x00); // DHS, DVS, DEN, DCLK MUST NOT be inverted.
RTDSetBit(VDIS_CTRL_20, 0xfd, 0x21); // DHS, DVS, DEN, DCLK and data are clamped to 0
RTDSetBit(DIS_TIMING0_3A, 0xff, 0x20); // Force display timing enable
RTDSetBit(DIS_TIMING0_3A, 0xdf, 0x00); // Stop forcing
_nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();
RTDSetBit(VDIS_CTRL_20, 0xfe, 0x00); // Stop display timing
RTDSetByte(HOSTCTRL_02, 0x42); // Put RTD2020 back into power-saving mode
RTDSetByte(DPLL_CTRL_D0, 0x10); // Disable DPLL
RTDCodeW(RTD_DDC_TABLE);
RTDCodeW(RTD_IO_INI);
#if(!SOURCE_AUTO_SCAN)
PowerDown_VDC();
#endif
PowerDown_TMDS();
PowerDown_LVDS();
Delay_Xms(10);
// Check and initial EEPROM if necessary
Delay_Xms(10);
Check_EEPROM();
Delay_Xms(10);
// Turn timer0 on. Let's go ~~~
TR0 = 1;
}
void Power_Up_Init(void) // Do once when power up
{
RTDSetBit(HOSTCTRL_02,0xfb,0x00); // RTD turn on
Reset_RTD(); // Initial RTD3000 & OSD
if((ucID_Code == 0x62) && ADC_DEFFERENTIAL) //Set ADC to differential mode
RTDSetByte(ADC_REG_CUR_L_E7,0xe9);
bLIGHT_PWR = LIGHT_OFF;
bPANEL_PWR = PANEL_OFF;
#if(TUNE_APLL)
ucPE_Max = 0;
RTDSetByte(DV_TOTAL_STATUS_3D,0x40); //clear PE Max value
#endif
#if(!SOURCE_AUTO_SCAN)
PowerDown_VDC();
#endif
PowerDown_LVDS();
#if(TMDS_ENABLE)
RTDSetByte(ANG_PERFORMANCE2_A3, 0x26); //Go about the TMDS impedence match
RTDSetByte(ANG_PERFORMANCE2_A3, 0x36);
#endif
RTDSetBit(OVL_CTRL_6D, 0x3f, (stGUD1.FUNCTION & 0x10) ? 0x80 : 0x00);
#if (SPREAD_SPECTRUM)
RTDSetBit(DPLL_CTRL_D0, 0x01, 0x08);
RTDRead(DPLL_M_D1, 0x01, Y_INC);
if (0xd2 < Data[0])
Data[1] = 0x09;
else if (0x8d < Data[0])
Data[1] = 0x0a;
else if (0x6d < Data[0])
Data[1] = 0x0b;
else if (0x57 < Data[0])
Data[1] = 0x0c;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -