📄 ksr810.c
字号:
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;
}
/***************************************************/
/* SwitchVideo */
/*function : switch video input source */
/*input : none */
/*output : none */
/**************************************************/
void SwitchVideo(void)
{
WriteI2C(TW88, WINDOW3, WIN3);
QuitMode();
QuitSwitch();
//switch s-video
if(video==VIDEO1)
{
DisplayW2("AV2");
video = VIDEO2;
}
else
{
DisplayW2("AV1");
video = VIDEO1;
}
WriteI2C(TW88, INFORM, video);
Delay_10ms(5);
VideoFormat();
battery_off = 0;
switch_mode = 1;
SaveLCDSetting();
}
/**************************************************/
/* QuitSwitch */
/*function : quit switch video mode */
/*input : none */
/*output : none */
/**************************************************/
void QuitSwitch(void)
{
switch_mode = 0;
win2_time = 0;
WriteI2C(TW88, WINDOW2, WIN2);
}
////////////////////////////////////////////////////
// key functions //
////////////////////////////////////////////////////
/**************************************************/
/* ClearKey */
/*function : Clear all key flag */
/*input : none */
/*output : none */
/**************************************************/
void ClearKey(void)
{
power = 0;
mode = 0;
up = 0;
down = 0;
}
/**************************************************/
/* GetKey */
/*function : Read which key is pressed */
/*input : none */
/*output : none */
/**************************************************/
void GetKey(void)
{
unsigned char key;
//unsigned char no_key;
//unsigned int counter = 0; //key pressed time counter
//monitor key
key = ReadAnalogInput(KEY_PIN);
CLRWDT();
if(key<POWER_REF)
{
INTE = 0;
power = 1;
key_pressed = 0;
autofire = 0;
mode_counter = 0;
}
else if((key>=40)&&(key<MODE_REF))
{
mode_counter++;
if(mode_counter == 600)
{
mode_counter = 0;
SwitchVideo();
key_free = 1;
}
}
else if((key>=120)&&(key<UP_REF))
{
up = 1;
key_pressed = 1;
}
else if((key>=190)&&(key<=DOWN_REF))
{
down = 1;
key_pressed = 1;
}
else if(mode_counter!=0)
{
mode = 1;
key_pressed = 0;
autofire = 0;
mode_counter = 0;
key_free = 1;
}
}
/**************************************************/
/* GetNoKey */
/*function : Wait no key pressed loop */
/*input : none */
/*output : none */
/**************************************************/
void GetNoKey(void)
{
if(ReadAnalogInput(KEY_PIN)>253)
{
CLRWDT();
key_free = 0;
key_pressed = 0;
autofire = 0;
//mode_counter = 0;
}
NOP();
}
/**************************************************/
/* AutoKey */
/*function : key pressed mode */
/*input : none */
/*output : none */
/**************************************************/
void AutoKey(void)
{
unsigned char key, no_key;
unsigned int counter = 0; //key pressed time counter
key = ReadAnalogInput(KEY_PIN);
CLRWDT();
if(!autofire)
{
while(1)
{
counter++;
if(counter>800)
{
autofire = 1;
break;
}
no_key = ReadAnalogInput(KEY_PIN);
CLRWDT();
if(no_key > DOWN_REF)
{
key_pressed = 0;
break;
}
}
}
else //autofire mode
{
while(1)
{
counter++;
if(counter>80)
break;
no_key = ReadAnalogInput(KEY_PIN);
CLRWDT();
if(no_key > DOWN_REF)
{
autofire = 0;
key_pressed = 0;
break;
}
}
if((key>MODE_REF) && (key<UP_REF))
up = 1;
else if(key<=DOWN_REF)
down = 1;
}
}
/**************************************************/
/* GetPower */
/*function : check power key pressed */
/*input : none */
/*output : none */
/**************************************************/
void GetPower(void)
{
unsigned char key;
//LCD key
key = ReadAnalogInput(KEY_PIN);
CLRWDT();
if(key<POWER_REF)
{
INTE = 0;
power = 1;
}
}
/**************************************************/
/* ReadAnalogInput */
/*function : Get the digital value from */
/* the AD conversion of an analog channel*/
/*input : unsigned char channel (0 to 4) */
/*output : unsigned char */
/**************************************************/
unsigned char ReadAnalogInput(unsigned char channel)
{
unsigned char result = 0; //Result of the AD conversion
//ADCON0 (p83) :
//ADCS1:ADCS0 = 0b10 : Tcon = 8us (Fosc/32)
//CHS2:CHS0 : Channel selection
//ADGO = 0
//ADON = 1
//=> ADCON0 = 0b10xxx001
//Channel selection :
//LSB => bit3 => CHS2:CHS0+1 <=> ADCON0+8
//channel 0 : bit5:bit3 = 0b000 => ADCON0 = 65
// +1 +8
//channel 1 : bit5:bit3 = 0b001 => ADCON0 = 73
ADCON0 = 129 + channel*8;
//min acq time = 11us (AD converter p21-6),
//between channel selected and ADGO : 22us
//no wait for acq time (add delay time if necessary)
SerialDelay();
SerialDelay();
SerialDelay();
ADGO = 1; //Start Conversion
while(ADGO);//wait for conversion to complete
result = ADRES; //Save AD result
ADIF = 0; //clear ADIF
return(result);
}
////////////////////////////////////////////////////
// Remocon functions //
// INT/RB0 : Remocon //
////////////////////////////////////////////////////
/**************************************************/
/* GetRemoCode */
/*function : Read remocon code */
/*input : none */
/*output : unsigned char */
/**************************************************/
unsigned char GetRemoCode(void)
{
unsigned char remocode=0;
unsigned char checkcode=0;
//read leader code
remocode = ReadLeader();
CLRWDT();
if(remocode == 0)
{
return(remokey);
}
if(remocode == 1)
{
// Read custom code
remocode = ReadRemo();
checkcode = ReadRemo();
if((remocode^checkcode)!=0xff) return(255);
// Read data code
remocode = ReadRemo();
checkcode = ReadRemo();
if((remocode^checkcode)!=0xff) return(255);
}
else if(remocode == 2)
{
if(choix!=4)
if((remokey == UP) || (remokey == DOWN))
remocode = remokey;
}
//remote key
switch(remocode)
{
case STANDBY : power = 1;
INTE = 0;
break;
case MODE : mode = 1;
break;
case UP : up = 1;
break;
case DOWN : down = 1;
default : break;
}
return(remocode);
}
/**************************************************/
/* ReadLeader */
/*function : Read Leader code : 0=9ms */
/* 1=4,5ms or 2,5ms */
/*input : none */
/*output : unsigned char */
/* 0:error 1:first pressed 2:key no released */
/**************************************************/
unsigned char ReadLeader(void)
{
OPTION = 0b10010101; // T TMR0 = 64us (p20)
CLRWDT();
TMR0=0;
while(!RB0 && (TMR0<156));
if((TMR0<125) || (TMR0>155)) //TMR0<8ms (125) or TMR0>9,9ms (155)
{ //=>9ms+-10%
return(0);
}
CLRWDT();
TMR0=0;
while(RB0 && (TMR0<78));
if((TMR0>32) && (TMR0<39))
return(2); //key pressed more than 108ms
else if((TMR0>63) && (TMR0<77)) //TMR0=4,5ms+-10%
return(1); //first pressed
CLRWDT();
return(0);
}
/**************************************************/
/* ReadRemo */
/*function : Read 1 Byte from the remo port (RB0) */
/*input : none */
/*output : unsigned char */
/**************************************************/
unsigned char ReadRemo(void)
{
unsigned char remo, mask, i;
OPTION = 0b10010011; // T TMR0 = 16us (p20)
remo = 0;
mask = 0b00000001;
for(i=0;i<8;i++)
{
CLRWDT();
TMR0 = 0;
while((!RB0) && (TMR0<40)); //TMR0<0,64ms
if(TMR0>39) //39=>0.624ms=0.56ms+10%
{
remo=0; //reception error
break;
}
CLRWDT();
TMR0 = 0;
while((RB0) && (TMR0<117)); //TMR0<1,872ms
if(TMR0>116) //116=>1,856ms=1,69ms+10%
{
remo=0; //reception error
break;
}
if(TMR0>95) //if 1.856ms>timer0>1,52ms
remo|=mask; //bit=1
mask<<=1;
}
return(remo);
}
////////////////////////////////////////////////////
// Serial Port functions //
// Registers : //
// Clock : RC6->SCL //
// data : RC5->SDA //
// SDA I/O control : TRISC5->CFSDA //
////////////////////////////////////////////////////
/**************************************************/
/* SerialDelay */
/*function : Delay for serial communication (10us)*/
/*input : none */
/*output : none */
/**************************************************/
void SerialDelay(void)
{
/* NOP();
NOP(); */
}
/**************************************************/
/* SerialStart */
/*function : Write serial start condition */
/*input : none */
/*output : none */
/**************************************************/
void SerialStart(void)
{
SDA = 1;
SerialDelay();
SCL = 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -