标题:
大佬们帮忙看看这个红外模块的单片机程序对吗?
[打印本页]
作者:
51c_yang
时间:
2021-8-27 11:20
标题:
大佬们帮忙看看这个红外模块的单片机程序对吗?
这是hx1838红外处理程序,请问哪里有问题?
void ir_init(void)
{
IRIN = 1;//初始化红外接收头为1
INTCLkO = 0x10;//开启INT2为下降沿触发
EA = 1;
}
void EX2_ISR() interrupt 10//红外中断函数
{
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)//超时判断
return ;
}
cnt = 0;
//4.5ms
while(IRIN)
{
cnt++;
Delay10us();
if(cnt > 500)//超时等待
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();//延时600us判断是高电平还是电平
if(IRIN)
{
temp |= 1<<j;//数据是从低位开始传输
cnt = 0;
while(IRIN)
{
cnt++;
Delay10us();
if(cnt > 110)
return ;
}
}
}
ircode[ i] = temp;
temp = 0;
}
Delay600us();
if(ircode[2] != ~ircode[3])//判断命令码是不是接受正确
return;
}
作者:
51c_yang
时间:
2021-8-27 11:21
这里处理ircode[2]数据感觉没有接收到为什么
作者:
man1234567
时间:
2021-8-28 11:21
在中断里乱或多用延时或循环都是比较可怕的事。
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1