使用NEC协议做的遥控器,遥控码正常,但是会出现以下问题:被物体挡住后,物体挪开,再去按遥控器,定时器计数值发生错误,可如图所示,需要按好久才恢复正常计数值。这是什么现象?
- void PT2222_Recv_Handle(void)
- {
- u16 It_tim=0;
- switch(PT2222_Status)
- {
- case 0:
- {
- PT2222_Status=1;
- TIM1_Cmd(ENABLE);//开定时器
- TIM1_SetCounter(0);
- }break;
- case 1:
- {
- TIM1_Cmd(DISABLE);
- It_tim=TIM1_GetCounter();
- TIM1_SetCounter(0);
- TIM1_Cmd(ENABLE);//开定时器
- if(It_tim>=2500 && It_tim<=4500)//起始码 14.40ms
- {
- PT2222_Status=2;
- //LED_STBY_R;//测试
- }
- else if(It_tim>=10250 && It_tim<=12250)//重复码 12.00ms
- {
- IR_Long=1;
- PT2222_Recv_OK=1;
- PT2222_Status=0;
- PT2222_Recv_Count=0;
- //LED_STBY_R;//测试
- }
- else
- {
- PT2222_Status=0;
- IR_Val=0;
- PT2222_Recv_Count=0;
- LED_STBY_R;//测试
- }
- }break;
- case 2://用户码、数据码
- {
- TIM1_Cmd(DISABLE);
- It_tim=TIM1_GetCounter();
- TIM1_SetCounter(0);
- TIM1_Cmd(ENABLE);//开定时器
- if(It_tim>=1000 && It_tim<=1300) //0
- {
- IR_Val=IR_Val<<1;
- PT2222_Recv_Count++;
- }
- else if(It_tim>=2000 && It_tim<=2600) //1
- {
- IR_Val=IR_Val<<1;
- IR_Val=IR_Val+1;
- PT2222_Recv_Count++;
- }
- else
- {
- PT2222_Status=0;
- IR_Val=0;
- PT2222_Recv_Count=0;
- //LED_STBY_R;//测试
- }
- if(PT2222_Recv_Count>=32)
- {
- PT2222_Recv_OK=1;
- PT2222_Status=0;
- PT2222_Recv_Count=0;
- }
- }break;
- default:
- {
- PT2222_Status=0;
- }break;
- }
- }
[color=rgb(51, 102, 153) !important]复制代码
[color=rgb(51, 102, 153) !important]
|