最近在利用STM8 TIM4定时中断 做一个固定频率红外线信号 长短接收控制LED灯 程序,但是就是执行不了,大侠们帮我看看,问题出在哪了?
描述:1. 红外线(PWM方波)F=125HZ ,T=8ms , D=0.4;
2.单片机PC5口接收红外信号;
3. TIM4定时时间100 us;
3. 先是判断红外信号频率是否正确,然后根据接收信号时间的长短来控制不同LED灯亮灭。接收信号时间T_js:
1) 短接收:T_js>3s时,LED1亮;2)长接收:0.2s<T_js<3s时,LED3亮。3)T_js<0.2s 无效
程序如下:
#define PT_INPUT_HIGH_COUNTER_MAX 40 //4ms
#define PT_INPUT_LOW_COUNTER_MAX 520 //5.2ms
#define PT_TRACE_PEROID_LOW_THRESHOLD 70 //7ms
#define PT_TRACE_PEROID_HIGH_THRESHOLD 90 //9ms
#define IR_SENSE_SHORT_PRESS_THRESHOLD 2000 //200ms
#define IR_SENSE_LONG_PRESS_THRESHOLD 30000 //3s
void PT91_Recv_Handle(void)
{
static u8 flag = 0; //反转的标志
//PT_Level_Read_Temp=GPIO_ReadInputPin(PT91_PORT,PT91_PIN);
IR_Input_Level=GPIO_ReadInputPin(PT91_PORT,PT91_PIN);
// PT_PIN Trace follow start
if(IR_Input_Level==HIGH)//High
{
if(PT_Input_High_Counter<PT_INPUT_HIGH_COUNTER_MAX)// prevent to flow
{
PT_Input_High_Counter++;
}
else
{
PT_Input_High_Counter=0;
}
}
else//Low
{
if(PT_Input_Low_Counter<PT_INPUT_LOW_COUNTER_MAX)// prevent to flow
{
PT_Input_Low_Counter++;
}
else
{
PT_Input_Low_Counter=0;
}
}
// PT_PIN Trace follow end
// PT_PIN wave peroid judge start
PT_Trace_Peroid=PT_Input_Low_Counter+PT_Input_High_Counter;
PT_Input_PR=PT_Trace_Peroid;
if(PT_Trace_Peroid>PT_TRACE_PEROID_LOW_THRESHOLD && PT_Trace_Peroid<PT_TRACE_PEROID_HIGH_THRESHOLD) //trace success
{
PT_Trace_Success_Counter++;
if(PT_Trace_Success_Counter>IR_SENSE_LONG_PRESS_THRESHOLD)// long IR sensed
{
Short_IR_sense_judge_state=NO;
Long_IR_sense_judge_state=YES;
PT_Trace_Success_Counter=0;
// long IR sense handle
LED1_L;
}
else if(PT_Trace_Success_Counter>IR_SENSE_SHORT_PRESS_THRESHOLD)
{
if(flag)
{
Long_IR_sense_judge_state=YES;
}
Short_IR_sense_judge_state=YES;
PT_Trace_Success_Counter=0;
// short IR sense handle
LED3_L;
}
else
{
PT_Trace_Success_Counter++;
}
flag = !flag;
}
else //trace fail
{
PT_Trace_Success_Counter=0;
PT_Input_High_Counter=0;
PT_Input_Low_Counter=0;
Short_IR_sense_judge_state=NO;
Long_IR_sense_judge_state=NO;
}
// PT_PIN wave peroid judge end
}
INTERRUPT_HANDLER(TIM4_UPD_OVF_IRQHandler, 23)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
TIM4_ClearITPendingBit(TIM4_IT_UPDATE);//清除更新标志位
PT91_Recv_Handle();
} |