|
void interrupt Timer0_Isr()//200us
{
TMR0=0; //初值
T0IF=0; //溢出中斷標(biāo)志位清零
if(IR_R)
{
F_H_first = 1;
R_H_count++; //高電平計時
if(R_H_count > 100)
{
R_H_count = 0;
F_L_start = 0;
F_H_start = 0;
F_rec_ok = 0;
R_rec_DATE = 0;
R_rec_countL = 0;
F_repeat_ok = 0;
}
if(F_L_first)
{
F_L_first = 0;
if(F_H_start == 0)
{
if((R_L_count > 40)&&(R_L_count < 50)) //低電平時間為9ms左右
{
F_L_start = 1; //低電平引導(dǎo)碼
}
}
R_L_count = 0;
}
}
else
{
F_L_first = 1;
R_L_count++; //低電平計時
if(R_L_count > 100) //計時大于50ms,干擾,清除所有標(biāo)志,不讀
{
R_L_count = 0;
F_L_start = 0;
F_H_start = 0;
F_rec_ok = 0;
R_rec_DATE = 0;
R_rec_countL = 0;
F_repeat_ok = 0;
}
if(F_H_first)
{
F_H_first = 0;
if(F_L_start)
{
if(F_H_start)
{
R_rec_countL++; //每變換一次電平計次一次
R_rec_DATE<<=1; //從最高位開始讀取
if(R_rec_countL > 16) //從第17位開始讀取數(shù)據(jù)
{
if((R_H_count > 6)&&(R_H_count < 11))
{
R_rec_DATE |= 0x01; //若高電平持續(xù)時間為1.72ms左右,讀為1,否則0
}
if(R_rec_countL >= 24) //24位讀完
{
R_rec_countL = 0;
R_real_date = R_rec_DATE;
F_L_start = 0;
F_H_start = 0;
F_rec_ok = 1; //數(shù)據(jù)讀取完畢
R_rec_DATE = 0;
}
}
}
else
{
if((R_H_count > 10)&&(R_H_count < 14)) //2.4ms左右
{
R_repeat_count++;
if(R_repeat_count > 1)
{
F_repeat_ok = 1; //重復(fù)碼標(biāo)志
}
}
else if((R_H_count > 20)&&(R_H_count < 25)) //高電平時間4.5ms左右
{
F_H_start = 1; //視為高電平引導(dǎo)碼
F_repeat_ok = 0;
R_repeat_count = 0;
}
else
{
F_L_start = 0;
F_repeat_ok = 0;
R_repeat_count = 0;
}
}
}
R_H_count = 0;
}
}
if(PBIF)
{
PBIF = 0; //清中斷標(biāo)志
PORTB=PORTB;
}
}
|
|