📄 ksr810.c
字号:
/**************************************************/
void VideoFormat(void)
{
unsigned char readformat=0;
unsigned char signal_present=0;
ReadI2C(TW88, CSTATUS, &signal_present);
if((signal_present & 0x80) == 0)
{
ReadI2C(TW88, SDT,&readformat);
if(readformat!=format)
{
format = readformat;
if((format&0x70)==0)
NTSC_VGA_SHARP();
else
PAL_VGA_SHARP();
}
}
else
{
if(format != 0x0F)
{
NTSC_VGA_SHARP();
//PAL_VGA_SHARP();
}
format = 0x0F;
}
}
////////////////////////////////////////////////////
// Power functions //
////////////////////////////////////////////////////
/**************************************************/
/* CheckBattery */
/*function : Compare battery level with */
/* a reference voltage */
/*input : none */
/*output : unsigned char */
/**************************************************/
unsigned char CheckBattery(void)
{
unsigned char battery;
if(POWER_ON)
{
//initialize Analog module
//RA3 : Vref ->ADCON1=0x01
ADCON1 = 0x01;
battery = ReadAnalogInput(BATTERY_PIN);
if(battery<=BATTERY_REF)
{
battery_off = 1;
//VDD : Vref ->ADCON1=0x00
ADCON1 = 0x00;
return(1);
}
battery_off = 0;
//VDD : Vref ->ADCON1=0x00
ADCON1 = 0x00;
}
else
{
battery = ReadAnalogInput(BATTERY_PIN);
if(battery>BATTERY_ON_REF)
{
battery_off = 0;
return(1);
}
}
return(0);
}
/**************************************************/
/* InitLCDPower */
/*function : initialize LCD power timing */
/*input : none */
/*output : none */
/**************************************************/
void InitLCDPower(void)
{
WriteI2C(TW88, 0xb3, 0x01 ); // timer prescaler
WriteI2C(TW88, 0xb5, 0x11 ); // suspend->standby on->suspend
WriteI2C(TW88, 0xb6, 0x11 ); // off->standby(!) standby->off
WriteI2C(TW88, 0xb7, 0x11 ); // standby->suspend(*) suspend->on
}
/**************************************************/
/* PowerDown */
/*function : Request DVD player To Power Down */
/*input : none */
/*output : none */
/**************************************************/
void PowerDown(void)
{
LCDPowerOff(); //Power down LCD
}
/**************************************************/
/* WakeUp */
/*function : Wake up system (DVD, LCD) */
/*input : none */
/*output : none */
/**************************************************/
void WakeUp(void)
{
LCDPowerOn(); //wake up LCD
if(video==VIDEO1)
DisplayW2("AV1");
else
DisplayW2("AV2");
Delay_10ms(5);
VideoFormat();
switch_mode=1;
battery_off = 0;
SCREEN_ON=1;
}
/**************************************************/
/* DVDPowerOn */
/*function : Switch on DVD */
/*input : none */
/*output : none */
/**************************************************/
/*void DVDPowerOn(void)
{
DVDPOWER = 1; //wake up DVD
CSO = 1;
}*/
/**************************************************/
/* DVDPowerOff */
/*function : Switch off DVD */
/*input : none */
/*output : none */
/**************************************************/
/*void DVDPowerOff(void)
{
unsigned long int counter = 0;
CSO = 0;
while(1)
{
counter++;
if((counter>200000)||CSI)
break;
}
DVDPOWER = 0; //Power down DVD
}
*/
/**************************************************/
/* LCDPowerOn */
/*function : Switch on LCD */
/*input : none */
/*output : none */
/**************************************************/
void LCDPowerOn(void)
{
POWER_ON = 1;
ResetTW88();
InitTW88();
//WriteI2C(TW88,0x2F,0xe4); //no signal, black screen
RestoreLCDSetting();
WriteI2C(TW88, POWER_TW, TW_SB);
//Delay_10ms(20);
WriteI2C(TW88, POWER_TW, TW_SP);
//Delay_10ms(50);
WriteI2C(TW88, POWER_TW, TW_ON);
}
/**************************************************/
/* LCDPowerOff */
/*function : Switch off LCD */
/*input : none */
/*output : none */
/**************************************************/
void LCDPowerOff(void)
{
SCREEN_ON = 0;
SaveLCDSetting();
WriteI2C(TW88, POWER_TW, TW_SP);
//Delay(1);
WriteI2C(TW88, POWER_TW, TW_SB);
//Delay(1);
WriteI2C(TW88, POWER_TW, TW_OFF); //power down TW88
//Delay(1);
POWER_ON = 0;
}
/**************************************************/
/* SaveLCDSetting */
/*function : Save last LCD setting */
/*input : none */
/*output : none */
/**************************************************/
void SaveLCDSetting(void)
{
unsigned char buffer[6];
EEPOWER = 1; //EEPROM ON
Delay_10ms(1);
ReadI2C(TW88, BRIGHT, &bght);
ReadI2C(TW88, CONTRAST, &ctst);
ReadI2C(TW88, CHROMA, &color);
ReadI2C(TW88, INFORM, &video);
direction = INVERT;
buffer[0] = 0x88; //eeprom[0] 0:EEPROM empty
// 0x88:EEPROM save
buffer[1] = bght;
buffer[2] = ctst;
buffer[3] = color;
buffer[4] = video;
buffer[5] = direction;
/*if(direction)
buffer[5] = 1;
else
buffer[5] = 0 ;
WriteI2C(EEPROM, 0x01, 0x25);*/
MWriteI2C(EEPROM, 0x00, buffer, 6);
Delay_10ms(1);
EEPOWER = 0; //EEPROM OFF
change=0;
}
/**************************************************/
/* RestoreLCDSetting */
/*function : Save last LCD setting */
/*input : none */
/*output : none */
/**************************************************/
void RestoreLCDSetting(void)
{
unsigned char buffer = 0;
EEPOWER = 1; //EEPROM ON
Delay_10ms(1);
ReadI2C(EEPROM, 0x00, &buffer);
//eeprom[0] 0:EEPROM empty
// 0x88:EEPROM save
if(buffer==0x88)
{
ReadI2C(EEPROM, 0x01, &bght);
ReadI2C(EEPROM, 0x02, &ctst);
ReadI2C(EEPROM, 0x03, &color);
ReadI2C(EEPROM, 0x04, &video);
ReadI2C(EEPROM, 0x05, &buffer);
if(buffer==1)
direction = 1;
else
direction = 0 ;
}
WriteI2C(TW88, BRIGHT, bght);
WriteI2C(TW88, CONTRAST, ctst);
WriteI2C(TW88, CHROMA, color);
WriteI2C(TW88, CHROMA-1, color);
WriteI2C(TW88, INFORM, video);
INVERT = direction;
Delay_10ms(1);
EEPOWER = 0; //EEPROM OFF
}
////////////////////////////////////////////////////
// Mode functions //
////////////////////////////////////////////////////
/**************************************************/
/* QuitMode */
/*function : Quit option mode */
/*input : none */
/*output : none */
/**************************************************/
void QuitMode(void)
{
WriteI2C(TW88, WINDOW1, WIN1); //disable window1
WriteI2C(TW88, WINDOW4, WIN4);
chrono = 0;
// ResetTimer();
choix = 0;
if(change)
SaveLCDSetting(); //save eeprom
change=0;
}
/**************************************************/
/* ResetTimer */
/*function : initialize Timer for option mode */
/*input : none */
/*output : none */
/**************************************************/
/*void ResetTimer(void)
{
TMR1IE = 0; //timer1 interrupt disable
TMR1ON = 0; //stop Timer1
TMR1H = 0;
TMR1L = 0;
chrono = 0;
}
*/
/**************************************************/
/* DisplayMode */
/*function : Display chosen option on LCD */
/*input : none */
/*output : none */
/**************************************************/
void DisplayMode(void)
{
WriteI2C(TW88, WINDOW4, WIN4);
switch(choix)
{
case 1 : ReadI2C(TW88, BRIGHT, &bght);
DisplayW1("BRIGHT ");
break;
case 2 : ReadI2C(TW88, CONTRAST, &ctst);
DisplayW1("CONTRAST ");
break;
case 3 : ReadI2C(TW88, CHROMA, &color);
DisplayW1("COLOR ");
break;
case 4 : WriteI2C(TW88, WINDOW1, WIN1);
autofire = 0;
if(INVERT)
DisplayW4(" ON ");
else
DisplayW4(" OFF ");
key_free = 1;
break;
default: QuitMode();
break;
}
}
/**************************************************/
/* UpMode */
/*function : Up one unit the option chosen */
/*input : none */
/*output : none */
/**************************************************/
void UpMode(void)
{
switch(choix)
{
case 1 : if(bght!=107)
{
if((bght>128)&&(bght<208))
bght+=2;
else
bght+=5;
WriteI2C(TW88, BRIGHT, bght);
}
break;
case 2 : if(ctst<232) // ctst max=232
{ // ctst display = ctst max/4 + 5 = 63
if(ctst<108)
ctst+=3;
else
ctst+=4;
WriteI2C(TW88, CONTRAST, ctst);
}
break;
case 3 : if(color<253)
{
if(color<160)
color+=5;
else
color+=3;
WriteI2C(TW88, CHROMA, color);
WriteI2C(TW88, CHROMA-1, color);
}
break;
case 4 : INVERT = !INVERT;
default : break;
}
change=1;
}
/***************************************************/
/* DownMode */
/*function : Down one unit the option chosen */
/*input : none */
/*output : none */
/**************************************************/
void DownMode(void)
{
switch(choix)
{
case 1 : if(bght!=0x90)
{
if((bght>128)&&(bght<=208))
bght-=2;
else
bght-=5;
WriteI2C(TW88, BRIGHT, bght);
}
break;
case 2 : if(ctst>12) // ctst min=12
{ // ctst display = ctst min/3 - 4 = 0
if(ctst<=108)
ctst-=3;
else
ctst-=4;
WriteI2C(TW88, CONTRAST, ctst);
}
break;
case 3 : if(color>=5)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -