跨届大侠
  
- 积分
- 8268


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