atmega64用两个中断接收两组红外冲突
atmega64用INT4和INT5接收红外遥控器编码冲突,INT4接收很不灵敏,请问有解决方案吗static uchar IR_end = 0; //红外
static uchar IR_count = 0;
static uchar IR_data = {0};
static uchar IR_data_sp = 0;
static uchar IR_code = {0};
static uchar F_Front_Int5 = 0;
static uchar F_Back_Int4= 0;
static uchar IR_end_int4 = 0; //红外
static uchar IR_count_int4 = 0;
static uchar IR_data_int4 = {0};
static uchar IR_int4_sp = 0;
static uchar IR_code_int4 = {0};
//static uchar F_Front_Int5 = 0;
//static uchar F_Back_Int4= 0;
// 解码函数
//先发低位
uchar ir_to_char(uchar *ptr)
{
uchar i;
uchar data = 0;
for(i=0;i<8;i++)
{
if(ptr > 16)
data |= (1<<(i));
else
data &= (~(1<<(i)));
}
return data;
}
void timer0(void) //定时器0初始化10K Hz
{
SREG |=0X80;
TCCR0 =0x00; //stop
ASSR =0x00; //set async mode
TCNT0|=0x38; //set count
OCR0 |=0xC8;
TCCR0|=0x02; //start timer
TIMSK|=BIT(TOIE0); //溢出中断时能
}
#pragma interrupt_handler timer0_ovf_isr:17
void timer0_ovf_isr(void)
{
TCNT0 = 0x38; //reload counter value
// IR_count_int4 = 0x38;
IR_count++;
// IR_count_int4++;
if(IR_count >= 0xfe)
{
IR_count = 0xfc;
}
// if(IR_count_int4 >= 0xfe)
//{
// IR_count_int4 = 0xfc;
//}
}
void int4_init(void) //外部中断初始化
{
DDRE&= ~BIT(PE4); //此处必须把int4引脚设置为输入带上拉
PORTE |= BIT(PE4);
DDRE&= ~BIT(PE5); //此处必须把int5引脚设置为输入带上拉
PORTE |= BIT(PE5);
//SREG|= 0X80;
CLI();
MCUCR= 0x00;
EICRA= 0x00; //extended ext ints
// EICRB|= 0x02; //extended ext ints
// EICRB|= 0x0a; //extended ext ints
EICRB= 0x0a; //extended ext ints
//EIMSK|= 0x30;
EIMSK=0x30;
TIMSK= 0x00; //timer interrupt sources
ETIMSK = 0x00; //extended timer interrupt sources
SEI(); //re-enable interrupts
}
void CLR_RX_int5(void)
{
uchar i;
for(i=0; i<40; i++)
{
IR_data = 0x00;
}
}
void CLR_RX_int4(void)
{
uchar i;
for(i=0; i<40; i++)
{
IR_data_int4 = 0x00;
}
}
//红外的解析 前胸接收
void ir_body_receive(void)
{
uchar i; //清空红外接收缓冲区
if(IR_end == 1)
{
IR_end = 0;
if((IR_count > 0xf0)&&(IR_count <= 0xff)) //重复吗
{
IR_count = 0;
IR_data_sp = 0; //数据开始
}
else if((IR_count > 0x25)&&(IR_count < 0x35))//判断引导码
{
IR_count = 0;
IR_data_sp = 0;
}
else
{
IR_data = IR_count;
IR_count = 0;
if(IR_data_sp >= 32)
{
IR_data_sp = 0;
IR_code = ir_to_char(&IR_data);
IR_code = ir_to_char(&IR_data);
IR_code = ir_to_char(&IR_data);
IR_code = ir_to_char(&IR_data);
// if(( IR_code == 0x44)&&(IR_code == 0x9b)&&(IR_code==(~IR_code)) )
if(( IR_code == 137) && (IR_code == 54) && (IR_code == (~IR_code)) )
{
setmotr_2;
system.FGmotor_cnts = 150; //电机振动时间
remote_control(); //遥控器数据处理
// CLR_RX_int5();
}
}
}
}
}
//红外的解析 后背接收
void ir_receive_int4(void)
{
uchar i; //清空红外接收缓冲区
if(IR_end_int4 == 1)
{
IR_end_int4 = 0;
if((IR_count_int4 > 0xf0)&&(IR_count_int4 <= 0xff)) //重复吗
{
IR_count_int4 = 0;
IR_int4_sp = 0; //数据开始
}
else if((IR_count_int4 > 0x25)&&(IR_count_int4 < 0x35))//判断引导码
{
IR_count_int4 = 0;
IR_int4_sp = 0;
}
else
{
IR_data_int4 = IR_count_int4;
IR_count_int4 = 0;
if(IR_int4_sp >= 32)
{
IR_int4_sp = 0;
IR_code_int4 = ir_to_char(&IR_data_int4);
IR_code_int4 = ir_to_char(&IR_data_int4);
IR_code_int4 = ir_to_char(&IR_data_int4);
IR_code_int4 = ir_to_char(&IR_data_int4);
// if(( IR_code == 0x44)&&(IR_code == 0x9b)&&(IR_code==(~IR_code)) )
if(( IR_code_int4 == 137) && (IR_code_int4 == 54) && (IR_code_int4 == (~IR_code_int4)) )
{
setmotr_1;
system.FGmotor_cnts = 150; //电机振动时间
remote_control(); //遥控器数据处理
// CLR_RX_int4();
}
}
}
}
}
//中断4 后背
#pragma interrupt_handler int0_isr:6
void int0_isr(void)
{
IR_end_int4 = 1;
}
//中断5 前胸
#pragma interrupt_handler int5_isr:7
void int5_isr(void)
{
IR_end= 1;
}
页:
[1]