|
发表于 2015-11-15 16:08:44
|
显示全部楼层
- /********************************************************************
- * 功能 : 舵机PWM中断, //舵机控制函数 周期为20ms 一个循环20MS = 8*2.5ms
- ***********************************************************************/
- void SteeringGear() interrupt 1
- {
- TH0=0Xff;
- TL0=0X9c;
- t++;
- if(t<zkb1)
- {
- pwm1=1;
- } //当zkbl大于t输出高电平,否则为低电平
- else
- {
- pwm1=0;
- }
- if(t<zkb2)
- {
- pwm2=1;
- }//当zkbr大于t输出高电平,否则为低电平
- else
- {
- pwm2=0;}//因此占空比就为zkbl/10
- //
- if(t==10)
- {
- t=0;
- }
- switch(pwm_flag)
- {
- case 1: servo0=1; TH0=-pwm[0]>>8; TL0=-pwm[0]; break;
- case 2: servo0=0; TH0=-(ms2_5Con-pwm[0])>>8; TL0=-(ms2_5Con-pwm[0]); break;
- case 3: servo1=1; TH0=-pwm[1]>>8; TL0=-pwm[1]; break;
- case 4: servo1=0; TH0=-(ms2_5Con-pwm[1])>>8; TL0=-(ms2_5Con-pwm[1]); break;
- case 5: servo2=1; TH0=-pwm[2]>>8; TL0=-pwm[2]; break;
- case 6: servo2=0; TH0=-(ms2_5Con-pwm[2])>>8; TL0=-(ms2_5Con-pwm[2]); break;
- case 7: servo3=1; TH0=-pwm[3]>>8; TL0=-pwm[3]; break;
- case 8: servo3=0; TH0=-(ms2_5Con-pwm[3])>>8; TL0=-(ms2_5Con-pwm[3]); break;
- case 9: servo4=1; TH0=-pwm[4]>>8; TL0=-pwm[4]; break;
- case 10: servo4=0; TH0=-(ms2_5Con-pwm[4])>>8; TL0=-(ms2_5Con-pwm[4]); break;
- case 11: servo5=1; TH0=-pwm[5]>>8; TL0=-pwm[5]; break;
- case 12: servo5=0; TH0=-(ms2_5Con-pwm[5])>>8; TL0=-(ms2_5Con-pwm[5]); break;
- case 13: servo6=1;TH0=-pwm[6]>>8; TL0=-pwm[6]; break;
- case 14: servo6=0;TH0=-(ms2_5Con-pwm[6])>>8; TL0=-(ms2_5Con-pwm[6]); break;
- case 15: servo7=1;TH0=-pwm[7]>>8; TL0=-pwm[7]; break;
- case 16: servo7=0;TH0=-(ms2_5Con-pwm[7])>>8; TL0=-(ms2_5Con-pwm[7]); break;
- default: TH0=0xff; TL0=0x80; pwm_flag=0;
- }
- pwm_flag++;
-
- }代码中我又写了两路PWM,为什么直接死机了,应该怎么改,这两路是控制运行电机的。
复制代码 |
|