📄 mcu.c
字号:
#include "stdio.h"
#include "8051.H"
#include "RAM.H"
#include "MCU.H"
#include "MyDef.H"
#include "IIC.H"
#include "F63REG.H"
#include "UserAdj.H"
#include "Scaler.H"
#include "AutoAdj.H"
#include "OSD.H"
#include "ModeHandle.H"
#include "sRGB.H"
#include "TUNER.H"
unsigned char IRCode,lrflag;
unsigned char DecodeDelay;
bit zw,MenuFlag;
unsigned char x1,DataSbuf[3];
unsigned char SelVideoMenu;
code unsigned char KeyTab[]={
0x00,0x20,0x40,0x60,0x7f
};
code unsigned int IR_Tab[]={
/* 0x20df,0x807f,0xb24d,0x8877,0xb847,0x9867,0x18e7,0xc03f,0x10ef,0xe817, //menu,+,-,CH+,CH-,POWER,PC/AV,SEARCH,MUTE,/
0xd02f,0x609f,0x708f,0x6897,0x7887,0x40bf,0x50af,0x48b7,0x58a7,0xe01f, //0,1,2,3,4,5,6,7,8,9
*/
// 0x807f,0xe01f,0x20df,0x40bf,0x609f,0xf807,0x50af,0xf00f,0x38c7,0x10ef, //menu,+,-,CH+,CH-,POWER,PC/AV,SEARCH,MUTE,/
// 0x30cf,0x18e7,0x58a7,0xd827,0x28d7,0x6897,0xe817,0x08f7,0x48b7,0xc837, //0,1,2,3,4,5,6,7,8,9
// 0x28d7,0x38c7,0xf00f,0xf807,0xc837,0x08f7 // L/R,U/D,AUTOADJUST,SEARCH1,GAME/PC,Display
// 0x6897,0x48b7,0x08f7,0xb04f,0xa857,0x40bf,0x50af,0xf00f,0xA05F,0x5FA0, //menu,+,-,CH+,CH-,POWER,PC/AV,SEARCH,MUTE,/
// 0xcf30,0xe718,0xa758,0xd827,0xd728,0x9768,0x17e8,0xf708,0xb748,0x37c8, //0,1,2,3,4,5,6,7,8,9
0x6897,0x48b7,0x08f7,0xb04f,0xa857,0x40bf,0x50af,0xa05f,0x807f,0x5FA0, //menu,+,-,CH+,CH-,POWER,PC/AV,SEARCH,MUTE,/
0xcf30,0xe718,0xa758,0xd827,0xd728,0x9768,0x17e8,0xf708,0xb748,0x37c8, //0,1,2,3,4,5,6,7,8,9
};
code unsigned char IR_KeyTab[]={
0x77,0x44,0x33,0x55,0x66,0x11,0x22,0x1c,0x0d,0x0b, //menu,+,-,CH+,CH-,POWER,PC/AV,SEARCH,MUTE,/
0x0a,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09, //0,1,2,3,4,5,6,7,8,9
// 0x2a,0x2b,0x2c,0x2d,0x2e,0x3a // L/R,U/D,AUTOADJUST,SEARCH1,GAME/PC,Display
};
void CheckIRKey(void)
{
unsigned int n;
unsigned char m;
unsigned long value;
if(!IRDATA)
{
IR_Timer = 0;
while(!IRDATA)
{
if(lrflag==1)
{
if(IR_Timer>30 && IR_Timer<48)
IRCode=0x33;
}
else if(lrflag==2)
{ if(IR_Timer>30 && IR_Timer<48)
IRCode=0x44;
}
if(IR_Timer > 48) //> 12 ms
return;
}
n = IR_Timer;
IR_Timer = 0;
if(n < 24) // < 6 ms
return;
while(IRDATA)
{
if(IR_Timer > 20) // > 5 ms
return;
}
n = IR_Timer;
IR_Timer = 0;
if((n > 16)&&(n < 20)) //4ms~5ms
{
for(m=0; m<32; m++)
{
while(!IRDATA)
{
if(IR_Timer > 4) //> 1ms
return;
}
n = IR_Timer;
IR_Timer = 0;
while(IRDATA)
{
if(IR_Timer > 8) //> 2ms
return;
}
n = IR_Timer;
IR_Timer = 0;
value = value << 1;
if(n > 4) // > 1ms
value |= 0x01;
}
// n = (unsigned int)(value >> 16);
// if(n == 0x01fe) //user code(0x7f)
// {
if((value & 0xffff) != 0) lrflag=0;
for(m=0; m<26; m++)
{
if(IR_Tab[m] == (unsigned int)(value & 0xffff))
{
IRCode = IR_KeyTab[m];
if(IRCode==0x33) {lrflag=1;}
else if(IRCode==0x44) {lrflag=2;}
else
{ lrflag=0; }
IR_Repeat = m;
RepeatTimer = KeyHoldTime;
IR_RepeatTimer = KeyHoldTime;
}
}
// }
}
else
{
if((n > 8)&&(n < 10))
{
while(!IRDATA)
{
if(IR_Timer > 4) // > 1 ms
return;
}
n = IR_Timer;
IR_Timer = 0;
if((n > 1)&&(IR_Repeat > 19)&&(IR_Repeat < 24))
{
if((IR_RepeatTimer != 0)&&((OSD_Type == 2)||(OSD_Type == 3)))
{
IR_RepeatTimer = 20;
IRCode = IR_KeyTab[IR_Repeat];
}
}
}
}
}
}
code unsigned char SystemRegTab[]={
0xf8, // PortA,0xf1
0xff, // PortB
#if PanelPowerActive == High
0x6c, // PortC
#else
0xee, // PortC
#endif
0x7e, // PortD,0x6e
0x55, // CLRWDT
0x98, // ADC_CON
0x00, // ADC0_REG
0x00, // ADC1_REG
0x00, // ADC2_REG
0x00, // ADC3_REG
0x00, // PWM0 Enable,ENPWM_LB
0x88, // PWM15 Enable,ENPWM_HB
0x00, // PWM0
0x00, // PWM1
0x00, // PWM2
0x00, // PWM3
0x00, // PWM4
0x00, // PWM5
0x00, // PWM6
0x00, // PWM7
0x00, // PWM8
0x00, // PWM9
0x00, // PWM10
0x00, // PWM11 Volume
0x00, // PWM12
0x00, // PWM13
0x00, // PWM14
0x00, // PWM15 Brightness
0x8A, // DDC_CTRL
0x00, // DDC_REG
0x40, // DDC_ADDR
0xFF, // INTIIC0_FLG/CLR
0x1F, // INTIIC0_EN
NOVATEK_Addr, // IIC0_ADDR
0xFF, // IIC0_TXDAT
0x00, // IIC0_CON
0xF0, // IIC0_CLK
0xFF, // INTIIC1_FLG/CLR
0x00, // INTIIC1_EN
0x00, // IIC1_ADDR
0xFF, // IIC1_TXDAT
0x00, // IIC1_CON
0xF3, // IIC1_CLK
0x00, // INT_SRC
0x00, // INTEXT_FLG/CLR
0x00, // INTEXT_EN
0x00, // INTHV_FLG/CLR
0x00, // INTHV_EN
0x60, // SYNC_REG
0x08, // HVO_REG
0xE0, // HVI_REG
0x00, // HPW_REG
0x00, // HFLT_REG
0x0E, // CLMP_REG
0x20, // PAT_LT
0x20, // PAT_RT
0x20, // PAT_UP
0x20, // PAT_DN
0x0f, // HVCNT_CTRL
0x00, // HCNT_LB
0x00, // HCNT_HB
0x00, // VCNT_LB
0x00, // VCNT_HB
0xc8, // DCNT_LB
0x00, // DCNT_HB --> 12M/60KHz = 0x00c8
0x20, // LCNT_LB
0x03, // LCNT_HB --> 60KHz/75Hz = 0x0320
0x40, // MUTE_CTRL
0x00, // ISP_REG
0xFF, // FLASH_BUF
0x00, // RDPA_REG
0xff, // RDPB_REG
0x44, // RDPC_REG
0x64, // RDPD_REG
};
void InitMCU(void)
{
unsigned char *p;
unsigned char i;
p = &PortA;
for(i=0; i<0x4A; i++){
*p = SystemRegTab[i];
p++;
}
CLRWDT = 0x55;
CmdTxPtr1 = 0;
CmdTxPtr2 = 0;
CmdRxPtr1 = 0;
CmdRxPtr2 = 0;
T0_INT_CNT = 0;
rwbuf = 0;
abuf = 0;
dbuf = 0;
if((PortC & BIT_6) == 0){
INTEXT_EN = 0x11;
KeyTemp2 = 0;
}
INTEXT_EN |= 0x22;
TMOD=0x22;TL1=0xf3;TH1=0xf3;TR1=1;
PCON=0x80;SCON=0x50;ES=1;
TL0 = -250;TH0 = -250;TR0=1;ET0=1;EA=1;
#ifdef Debug
flag3 = 4;
#else
flag3 = 0;
#endif
//Sleep(50);
PowerStatus = 0xff;
IIC_BaudRate = 0x01;
LoadDDCData(1);
}
void Timer0(void) interrupt 1 using 2
{
if(IR_Timer != 0xff)
IR_Timer++;
if(++T0_INT_CNT >= 4)
{
T0_INT_CNT = 0;
if(Timer1 != 0) // 1ms
Timer1--;
if(++Timer10ms >= 10) // 10ms
{
CLRWDT = 0x55;
Timer10ms = 0;
if(DecodeDelay != 0)
DecodeDelay--;
if(Timer2 != 0)
Timer2--;
if(Timer3 != 0)
Timer3--;
if(Timer4 != 0)
Timer4--;
if(RepeatTimer != 0)
RepeatTimer--;
if(PoSvTimer != 0)
PoSvTimer--;
if(IR_RepeatTimer != 0){
IR_RepeatTimer--;
}
}
}
}
void Sbuf(void) interrupt 4
{
RI=0;
if(zw)
{ DataSbuf[x1]=SBUF;
x1++;
if(x1>=3)
{ zw=0;x1=0;
if(DataSbuf[2]==0xfe)
{ IRCode=DataSbuf[1];}
}
}
if(SBUF==0xf0) {zw=1;x1=1;}
}
void Sleep(unsigned short time)
{
Timer1 = time; /* timeout n ms */
while(Timer1 != 0){
}
}
void WaitSetup(unsigned short time)
{
Timer1 = time; /* timeout n ms */
while(Timer1 != 0){
CheckModeChange();
}
}
void ScanKeyPad(void)
{
unsigned char i,j,k;
Timer1 = 0;
do{
while((ADC_REG[3] & BIT_7) == 0){};
KeyPad1 = ADC_REG[0] & 0x7f;
KeyPad2 = ADC_REG[1] & 0x7f;
if((ADC_REG[2] & 0x7f) < 0x38){
flag1 |= BIT_7;
return;
}
ADC_CON = 0x17; //Channel; // Start AD Convert
ADC_CON = 0x97; //Channel; // Start AD Convert
//check adc0
if(KeyPad1 > KeyTemp1){
if((KeyPad1 - KeyTemp1 ) > 5){
KeyTemp1 = KeyPad1;
flag1 |= BIT_2;
Timer1 = KeyStabTime;
}
}
else{
if((KeyTemp1 - KeyPad1 ) > 5){
KeyTemp1 = KeyPad1;
flag1 |= BIT_2;
Timer1 = KeyStabTime;
}
}
//check adc1
if(KeyPad2 > KeyTemp2){
if((KeyPad2 - KeyTemp2 ) > 5){
KeyTemp2 = KeyPad2;
flag1 |= BIT_2;
Timer1 = KeyStabTime;
}
}
else{
if((KeyTemp2 - KeyPad2 ) > 5){
KeyTemp2 = KeyPad2;
flag1 |= BIT_2;
Timer1 = KeyStabTime;
}
}
//check power key
if(((PortC & BIT_6) == 0)&&((flag3 & BIT_5) != 0)){
flag3 &= ~BIT_5;
flag1 |= BIT_2;
Timer1 = KeyStabTime;
}
if(((PortC & BIT_6) != 0)&&((flag3 & BIT_5) == 0)){
flag3 |= BIT_5;
flag1 |= BIT_2;
Timer1 = KeyStabTime;
}
}while(Timer1 != 0);
//change key
if((flag1 & BIT_2) != 0x00){
flag1 &= ~BIT_2;
if((flag3 & BIT_2) != 0x00){
printf("KEY1 = %x\r\n",(unsigned short)KeyTemp1);
printf("KEY2 = %x\r\n",(unsigned short)KeyTemp2);
}
for(i=0; i<5; i++){
if(KeyTemp1 > KeyTab[i])
j = KeyTemp1 - KeyTab[i];
else
j = KeyTab[i] - KeyTemp1;
if(j < 16){
j = i;
break;
}
}
for(i=0; i<5; i++){
if(KeyTemp2 > KeyTab[i])
k = KeyTemp2 - KeyTab[i];
else
k = KeyTab[i] - KeyTemp2;
if(k < 16){
k = i;
break;
}
}
KeyBuffer = k << 4;
KeyBuffer |= j;
if((flag3 & BIT_5) == 0){
if(KeyBuffer == DownKey){
flag3 |= BIT_0;
flag2 &= ~BIT_5;
Write24C16(0xcd,0x01);
if((flag3 & BIT_2) != 0x00)
printf("Entry Factory mode\r\n");
}
else{
flag3 &= ~BIT_0;
k = Read24C16(0xe1);
k = ColorTab[k];
if(k == 0)
flag2 &= ~BIT_5;
else
flag2 |= BIT_5;
Write24C16(0xcd,0x00);
if((flag3 & BIT_2) != 0x00)
printf("Release Factory mode\r\n");
}
flag2 &= 0xf3; //clear display flag
KeyBuffer = PowerKey;
}
if((flag3 & BIT_2) != 0x00)
printf("KeyBuffer = %x\r\n",(unsigned short)KeyBuffer);
// set repeat timer
Repeat = KeyBuffer;
RepeatTimer = KeyHoldTime;
}
else{
if((RepeatTimer == 0)&&((OSD_Type > 0x00)||(OSD_Type < 0x04))){
switch(Repeat){
case LeftKey:
KeyBuffer = Repeat;
RepeatTimer = KeyRepeatTime;
break;
case RightKey:
KeyBuffer = Repeat;
RepeatTimer = KeyRepeatTime;
break;
}
}
}
}
void CheckKey(void)
{
ScanKeyPad();
if((PowerStatus & BIT_7) == 0)
{
if(KeyBuffer == RightKey){
ModePoint++;
}
if(KeyBuffer == LeftKey){
ModePoint--;
}
if(KeyBuffer != PowerKey){
KeyBuffer = 0xff;
}
}
switch(KeyBuffer){
case PowerKey: //POWER
KeyBuffer = 0xff;
if((PowerStatus & BIT_7) == 0)
{
PowerStatus |= BIT_7; //normal
Write24C16(0xcc,PowerStatus);
flag1 &= ~BIT_0;
if((flag1 & BIT_3) == 0)
{
flag1 |= BIT_3;
ForceToBackground(0); //Set fource to background
PoSvTimer = 500;
}
if(ModePoint == 0xfc)
{
InitEEPROM();
LoadModeIndependentSettings();
LoadADC_Gain();
SetBrightness();
sRGB();
SetSharpness();
}
ScalerPowerUp();
DVI_On();
SourceSelect();
LED_RedOff();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -