//遙控解碼子程序,LC7461,,用戶碼為11C
//external interrupt0
void isr_4()
{
unsigned char r_count;//定義解碼的個數(shù)
unsigned long use_data=0;//定義16位的用戶碼,只用到13位
unsigned long use_code=0;//定義16位的用戶反碼,,只用到13位
unsigned long data=0;//定義16位數(shù)據(jù)碼,包括8位數(shù)據(jù)碼和反碼
unsigned char data_h=0;//數(shù)據(jù)反碼
unsigned char data_l=0;//數(shù)據(jù)碼
_clrwdt();
// _delay(7000);//7461解碼,,延時7000
// _delay(7000);//7461解碼,,延時7000
//_delay(7000);//7461解碼,延時7000
if(remote==1)
goto error;
while(remote==0);//wait to high
//_delay(9744);
count_delay=0;
while(count_delay<143);
if(remote==1)
goto error;
/////用戶碼解碼use_data//////////add//////////////////////////
for(r_count=13;r_count>0;r_count--)
{
while(remote==0);//wait to high
count_delay=0;
while(count_delay<24);//_delay(1680);
_c=remote;
if(_c==1)
{
_lrrc(&use_data);
count_delay=0;
while(count_delay<32);//_delay(2200);//wait to low
}
else
_lrrc(&use_data);
}
_nop();
//if(remote==1)
//_delay(1680);//wait to low while(remote==1);//wait to low
_nop();
////////用戶碼解碼finish/////////add/////////add////////
/////用戶碼反碼解碼use_code//////////add//////////////////////////
for(r_count=13;r_count>0;r_count--)
{
while(remote==0);//wait to high
count_delay=0;
while(count_delay<24);//_delay(1680);
_c=remote;
if(_c==1)
{
_lrrc(&use_code);
count_delay=0;
while(count_delay<32);//_delay(2200);//wait to low
}
else
_lrrc(&use_code);
}
_nop();
//if(remote==1)
// _delay(1680);//wait to low while(remote==1);//wait to low
_nop();
////////用戶碼反碼解碼finish/////////add/////////add////////
////數(shù)據(jù)碼解碼開始////data_l為用戶碼,,data_h為數(shù)據(jù)碼反碼////////////
for(r_count=16;r_count>0;r_count--)
{
while(remote==0);//wait to high
count_delay=0;
while(count_delay<24);//_delay(1680);
_c=remote;
if(_c==1)
{
_lrrc(&data);
count_delay=0;
while(count_delay<32);//_delay(2200);//wait to low
}
else
_lrrc(&data);
}
////數(shù)據(jù)碼解碼結(jié)束////////////////////////////////////////////////
data_l=data;
data_h=data>>8;
///用戶碼//////
use_data>>=3;
use_code>>=3;
use_code=~use_code;
////////
////如果用戶碼等與0x11c并且數(shù)據(jù)碼和數(shù)據(jù)反碼都校驗(yàn)一致,,解碼成功
//if((~data_h==data_l)&&use_data==0x11c)//使用用戶碼
//跳過用戶碼
if(~data_h==data_l)//如果數(shù)據(jù)碼和數(shù)據(jù)反碼(取反后)相等,解碼正確
{
_nop();
r_data=data_l;//r_data為解出的最終數(shù)據(jù)碼
}
//否則解碼不成功
_nop();
_nop();
error: //r_data=nocode;
_nop();
_nop();
_nop();
}