完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
最近在利用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 #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++; } else { PT_Input_High_Counter=0; } } else//Low { if(PT_Input_Low_Counter 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_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(); } |
|
相关推荐
1个回答
|
|
自己顶一下,看来周末大家都很少逛帖子。
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
409 浏览 0 评论
【xG24 Matter开发套件试用体验】10-Bluetooth示例1
469 浏览 0 评论
697 浏览 0 评论
【xG24 Matter开发套件试用体验】power specification电源规格参数配置
512 浏览 0 评论
475 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
10813 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-8-22 17:47 , Processed in 0.661036 second(s), Total 72, Slave 55 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191