📄 remote_led.c
字号:
}
return (return_bit);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////InRemote_Philip function/////1.5 bit leader 5 bit control and 6 bit data//////////////
bit InRemote_Philip()/////////////////////////////////////////////////////////////////////PHILIP SAA3010
{ uchar Temp1,Temp2,i;////////////////the leader signed is low 1.12ms high 0.56ms low 0.84ms
bit bTemp;///////////////////////////////////the data is high(or low) 0.84ms low(or high) 0.84ms
Temp1=0x00;
for (;(bInRemote_T0)&&(Counter<7);) {;}// Display_Str();
if (!((!bInRemote_T0)&&(Counter>=4))) { bNoise_IR=LOW;return (LOW);}
{ TL0=Copy_TL0;
for (Counter=0;Counter<10;) {;}// Display_Str();
if (!bInRemote_T0)/////////////the 1ms delay include 0.84ms leader signed and 0.16ms data
{ Temp1=0x01;
for (Counter=0;(!bInRemote_T0)&&(Counter<8);) {;}// Display_Str();
if ((bInRemote_T0)&&(Counter>=6))/////////the remainder 0.68ms delay is last data
{ for (;Counter<16;) {;}}
else { bNoise_IR=LOW;return (LOW);}
}
else
{ for (Counter=0;((bInRemote_T0)&&(Counter<9));) {;} //Display_Str();
if ((!bInRemote_T0)&&(Counter>=6))
{ for (;Counter<16;) {;}}
else { bNoise_IR=LOW;return (LOW);}
}
for (i=0;i<5;i++)
{ Temp1<<=1;
bTemp=bInRemote_T0;
for (Counter=0;Counter<8;) {;} //Display_Str();
if (bInRemote_T0==bTemp) { bNoise_IR=LOW;return (LOW);}
if (bInRemote_T0) Temp1|=0x01;
for (Counter=0;Counter<8;) {;} //Display_Str();
}
Temp2=0x00;
for (i=0;i<6;i++)
{ Temp2<<=1;
bTemp=bInRemote_T0;
for (Counter=0;Counter<8;) {;} //Display_Str();
if (bInRemote_T0==bTemp) { bNoise_IR=LOW;return (LOW);}
if (bInRemote_T0) Temp2|=0x01;
for (Counter=0;Counter<8;) {;} //Display_Str();
}
UsercodeL=UsercodeH=Temp1; Keydata=Temp2;
if (DISP_CHIP_TYPE==NEC_PD6122G) {DISP_CHIP_TYPE=PHILIP_SAA3010; bCHIP_TYPE_STAU=HIGH;}
}//end of if (!((!bInRemote_T0)&&(Counter>=4)))
bNoise_IR=LOW;return (HIGH);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////InRemote_Nec function 8 bit usercode 8 bit keydata and it con-code////////////////////////
bit InRemote_Nec()///////////////////////////////////////////////////////////////////////////NEC PD6122G
{ uchar i,j;////////////////////////////////////////////////the leader is low 9ms high 4.5ms
uchar Temp[4];//////////////////////////////the data is low 0.56ms high 0.56ms("0") or 1.68ms("1")
TR0=HIGH;
for (Counter=0;(bInRemote_T0)&&(Counter<48);) {;} //Display_Str();
if ((!bInRemote_T0)&&(Counter>=19)&&(Counter<=24))
{
for (Counter=0;(!bInRemote_T0)&&(Counter<7);) {;}// Display_Str();
if ((bInRemote_T0)&&(Counter>=3)) { bNoise_IR=LOW;return (HIGH);}
bNoise_IR=LOW;return (LOW);
}
if (!((!bInRemote_T0)&&(Counter>=40))) { bNoise_IR=LOW;return (LOW);}
{ for (i=0;i<4;i++)
{ Temp[i]=0x00;
for (j=0;j<8;j++)
{ //TL0=Copy_TL0;
for (Counter=0;(!bInRemote_T0)&&(Counter<7);) {;}// Display_Str();//6
if (!((bInRemote_T0)&&(Counter>=3))) { bNoise_IR=LOW;return (LOW);}//ease error
//TL0=Copy_TL0; TH0=Copy_TH0;
for (Counter=0;(bInRemote_T0)&&(Counter<24);) {;}// Display_Str();
Temp[i]>>=1;
if (bInRemote_T0) { bNoise_IR=LOW;return (LOW);}
if (Counter>9) Temp[i]|=0x80;
}
}
if (!(Temp[2]==~Temp[3])) { bNoise_IR=LOW;return (LOW);}
else
{ UsercodeL=Temp[0];
if (Temp[0]==~Temp[1]) UsercodeH=Temp[0];
else UsercodeH=Temp[1];
Keydata=Temp[2];
}
}//end of if (!((!bInRemote_T0)&&(Counter>=40)))
if (DISP_CHIP_TYPE==PHILIP_SAA3010) {DISP_CHIP_TYPE=NEC_PD6122G; bCHIP_TYPE_STAU=HIGH;}
bNoise_IR=LOW;return (HIGH);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////Initial function////////////////////////////////////////////////////////////
void Initial()
// /////////initial the output port and initial other setup/////////////////////////////////////////////////
{ //////////////////////led output init///////////////////////////////////////////////////////////////
LED_OUT=0x00;
bLedCtrl_1=bLedCtrl_2=bLedCtrl_3=bLedCtrl_4=bLedCtrl_5=LOW;
//////////////////////bit var init//////////////////////////////////////////////////////////////////
bCHIP_TYPE_STAU=bDISP_DATA_TYPE=bInRemote_Flag=bDelay30s_Overflow=LOW;
bWait_LowToHigh=bInKey_Valid=bDelayFlag_PressKey=bNoise_IR=LOW;
CPU_CLK=CPU_12MHZ;DISP_CHIP_TYPE=PHILIP_SAA3010;
//CPU_CLK=CPU_24MHZ;
/////////////////////char var init//////////////////////////////////////////////////////////////////
Delay_DEC30s=0; DelayValue_PressKey=DELAY40ms;
////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////sfr init///////////////////////////////////////////////////////////////////////
TMOD=0x15;///T0 is counter while "bTorC_Flag=COUNT_T0" or timer while "bTorC_Flag=TIME_T0" for 100us
TL0=0xff; TH0=0xff; bTimerOrCounter_Flag=COUNT_T0;
if (CPU_CLK==CPU_12MHZ)////////////////////////////////////////////delay 1ms while T1 once overflow
{TL1=Copy_TL1=0x18; TH1=Copy_TH1=0xfc; Copy_TL0=0x9c; Copy_TH0=0x9c;}//9c////////CPU_CLK=12MHZ
else {TL1=Copy_TL1=0x30; TH1=Copy_TH1=0xf8; Copy_TL0=0x38; Copy_TH0=0x38;}//////////CPU_CLK=24MHZ
ET0=ET1=TR0=TR1=EA=HIGH;//////////////////////////////////////////////////allow interrupt for T0, T1
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////Display_Led function//////////////////////////////////////////////////////
void Display_Led(uchar Disp_Data,uchar position)
{
switch (position)
{
case 0: bLedCtrl_2=bLedCtrl_3=bLedCtrl_4=bLedCtrl_5=LOW;bLedCtrl_1=HIGH;break;
case 1: bLedCtrl_1=bLedCtrl_3=bLedCtrl_4=bLedCtrl_5=LOW;bLedCtrl_2=HIGH;break;
case 2: bLedCtrl_1=bLedCtrl_2=bLedCtrl_4=bLedCtrl_5=LOW;bLedCtrl_3=HIGH;break;
case 3: bLedCtrl_1=bLedCtrl_2=bLedCtrl_3=bLedCtrl_5=LOW;bLedCtrl_4=HIGH;break;
case 4: bLedCtrl_1=bLedCtrl_2=bLedCtrl_3=bLedCtrl_4=LOW;bLedCtrl_5=HIGH;break;
default : break;
}
LED_OUT=Disp_Data;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////Display_str function///////////////////////////////////////////////////////////////////
void Display_Str()
{ uchar i;
for (i=0;(i<5)&&((*disp_str)!=0x00);i++) { Display_Led(*disp_str,i); disp_str++;}
disp_str=disp_str-i;///////////////////////////////////////////////////////return the first position
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////Display_Message function////////////////////////////////////////////////////////
void Display_Message()/////////////////////////////////////////////////////display error or noise message
{ uint delay1s;
if (!bNoise_IR) disp_str=Disp_Error;
else disp_str=Disp_Noise;
TR0=LOW;
delay1s=Delay_DEC30s;
for (;(delay1s-Delay_DEC30s)<1000;) Display_Str();
Delay_DEC30s=DELAY30s;
TR0=HIGH;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// interrupt1 interrupt3 function/////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////InRemote_T0///function//////////////////////////////////////////////////////////////////////
void InRemote_T0() interrupt 1 using 1
{ if (bTimerOrCounter_Flag==COUNT_T0)
{ TR0=TR1=LOW; bInRemote_Flag=HIGH;
TMOD=0x02; TL0=Copy_TL0; TH0=Copy_TH0;Counter=0;
bTimerOrCounter_Flag=TIME_T0; TR0=HIGH;
}//the timer1 must stop while the remote signed recieve
else { Counter++;}
}
/////////////////InRemote_T1///function/////////////////////////////////////////////////////////////////////
void InRemote_T1() interrupt 3 using 3
{ TL1=Copy_TL1; TH1=Copy_TH1;
if (bDelayFlag_PressKey)
{ if ((--DelayValue_PressKey)==0)
{ if (((!InKey_Selc_UserOrKey_Code)&&(InKey_Selc_Other))||
((!InKey_Selc_Other)&&(InKey_Selc_UserOrKey_Code)))
bWait_LowToHigh=HIGH;
bDelayFlag_PressKey=LOW; DelayValue_PressKey=DELAY40ms;
}
}
else { if ((bWait_LowToHigh)&&(InKey_Selc_UserOrKey_Code)&&(InKey_Selc_Other))
{ bWait_LowToHigh=LOW;bInKey_Valid=HIGH;}
else { if (!bInKey_Valid)
{ if ((!InKey_Selc_UserOrKey_Code)&&(InKey_Selc_Other))
{ Key_Data=Display_MODE; bDelayFlag_PressKey=HIGH;}
if ((InKey_Selc_UserOrKey_Code)&&(!InKey_Selc_Other))
{ Key_Data=Reserv_MODE; bDelayFlag_PressKey=HIGH;}
}
}
}
if (Delay_DEC30s!=0)
{ if ((--Delay_DEC30s)==0) bDelay30s_Overflow=HIGH;}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////Remote_led.c//OVER////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -