|
這是hx1838紅外處理程序,請問哪里有問題?
void ir_init(void)
{
IRIN = 1;//初始化紅外接收頭為1
INTCLkO = 0x10;//開啟INT2為下降沿觸發(fā)
EA = 1;
}
void EX2_ISR() interrupt 10//紅外中斷函數(shù)
{
unsigned char i;
unsigned char j;
unsigned int cnt;
unsigned char temp = 0;
if(IRIN == 0)
{
//判斷9ms的高電平
cnt = 0;
while(IRIN == 0)
{
cnt++;
Delay10us();
if(cnt > 1000)//超時(shí)判斷
return ;
}
cnt = 0;
//4.5ms
while(IRIN)
{
cnt++;
Delay10us();
if(cnt > 500)//超時(shí)等待
return ;
}
//開始接受紅外信號
for( i = 0; i<4; i++)
{
for( j = 0; j<8;j++)
{
cnt = 0;
while(IRIN == 0)//560us
{
cnt++;
Delay10us();
if(cnt > 60)
return ;
}
Delay600us();//延時(shí)600us判斷是高電平還是電平
if(IRIN)
{
temp |= 1<<j;//數(shù)據(jù)是從低位開始傳輸
cnt = 0;
while(IRIN)
{
cnt++;
Delay10us();
if(cnt > 110)
return ;
}
}
}
ircode[ i] = temp;
temp = 0;
}
Delay600us();
if(ircode[2] != ~ircode[3])//判斷命令碼是不是接受正確
return;
}
|
|