中级会员
 
- 积分
- 259

- 威望
- 211
- 贡献
- 42
- 兑换币
- 18
- 注册时间
- 2008-3-3
- 在线时间
- 3 小时
|
Re:跪求一定时中断程序
< >用主定时器,好像用定时器的通道不行!</P><P>跳不出中断程序,主定时器就可以。以下是定时启动,定时停止,和测速程序段。</P><P>unsigned int main_cnt=0; //主定时器延时0.6s</P><P>/***********主定时器中断服务程序(实现0.6s的延时,测速)********/<BR>#pragma CODE_SEG NON_BANKED<BR>void interrupt int_timeroverflow(void){<BR> if(main_cnt%100==0)<BR> {<BR> //main_cnt=0;<BR> //speed_data0=speed_data1; //保存最近两次速度值(原来有问题)<BR> //speed_data1=speed_cnt;<BR> speed_data0=speed_cnt;<BR> speed_cnt=0;<BR> PORTB=0x00;<BR> }<BR> <BR> if(main_cnt==610) //610*65535=8M*5 实现5秒定时<BR> {<BR> speed(45); //速度太慢不能行走<BR> PWMDTY01=motor_middle; //给通道0,1设置duty值(舵机正中)<BR> go=1; <BR> }<BR> if(main_cnt==6100) //610*65535=8M*50 实现50秒定时<BR> {<BR> speed(0); //速度太慢不能行走<BR> PWMDTY01=motor_middle; //给通道0,1设置duty值(舵机正中)<BR> go=0; <BR> }<BR> main_cnt++;<BR> TFLG2_TOF = 1; //clear timer overflow flag<BR>} </P><P>/**********通道5捕捉中断(测速)*******************************/<BR>#pragma CODE_SEG NON_BANKED<BR>interrupt void timerinput5(void){<BR> speed_cnt++;<BR> TFLG1_C5F=1; <BR>}<BR>/************************************************************/</P><P> </P><P> </P> |
|