/定时器T0初始化/
void Timer0_Init()
{
TMOD &= 0x00;
TMOD |= 0x01; //定时器T0设置成方式1
TH0 = 0xff; //定时常数 0.1ms 晶振为11.0592MHz
TL0 = 0xa4;
ET0 = 1;
TR0 = 1;
EA=1;
}
void Time0_Init() interrupt 1
{
TR0 = 0;
TH0 = 0xff; // 0.1ms
TL0 = 0xa4;
count++;
if (count >= 200) //T = 20ms清零
{
count = 0;
}
TR0 = 1;
}
void main()
{
Timer0_Init();
while(1)
{
if(count<=timer[0])
{
PWM1 = 1;
}
else
{
PWM1 = 0;
}
if(count<=timer[1])
{
PWM2 = 1;
}
else
{
PWM2 = 0;
}
if(count<=timer[2])
{
PWM3 = 1;
}
else
{
PWM3 = 0;
}
...........
}
}
控制六个舵机以上,中断的时间就已经超过while循环的时间是否可以解决问题