基于c51的sg90舵机问题

sg90舵机执行一次后就不再执行了。比如以下代码中,

void rou () interrupt 3
{
    
    TH1 = 0xfe;
    TL1 = 0x0c;
    if(round1 == 1){sg90 = 1;}//在这里给出高电平
    if(round1 == round){sg90 = 0;}//当达到指定时间时设为低电平。第一次round为5。第二次为3,但是第二次的时候舵机只响不转
    round1 ++;
        if(round1 == 40)//完成一个pvm波
    {
        round1 =0;
        led=0;      
        round2 ++;
    }
        if(round2 ==4)//当输出4个pvm波以后把round设为3。但是舵机只响不转
        {
      round=3;
      round1=0;
      round2=0;
      TR1=0;
      delay(3000);
      TR1=1;
      }
}

这是全部的代码

#include "reg52.h"
sbit sg90 = P0^2;
sbit led = P0^6;
static unsigned int round = 5;
static unsigned int round1 = 0;
static unsigned int round2 = 0;

void delay(int length)
{
    int i = 0;
    int j = 0; 
    for(;i<125;i++)
    {for(;jTMOD = 0X11;
    TH1 = 0XFE;
    TL1 = 0X0C;
    EA = 1;
    ET1 = 1;
    TR1 = 1;
    while(1);
    
}

void rou () interrupt 3
{
    
    TH1 = 0xfe;
    TL1 = 0x0c;
    if(round1 == 1){sg90 = 1;}
    if(round1 == round){sg90 = 0;}
    round1 ++;

    if(round1 == 40)
        {
            round1 =0;
            led=0;      
            round2 ++;
        }
if(round2 ==4){
    round=3;
    round1=0;
    round2=0;
    TR1=0;
    delay(3000);
    TR1=1;
}

}

谢邀。
舵机的控制信号不是单周期的,而是需要持续不断的保持一个固定占空比的信号,直至舵机转到指定位置后才能改变,不然就会抖动。另外,楼主控制间隔为0.5ms,可选的旋转角度非常有限。建议参考我的博客: