我设置的1.5ms的高电平结果转动了120度,其他的信号脉冲宽度也与角度对不上
单片机源程序如下:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit reshui=P3^5;
sbit lengshui=P3^6;
sbit kaishi=P1^1;
sbit jieshu=P1^2;
uint a,c;
uchar b=0,d=0;
//舵机初始化
void delay(uint i)
{
for(;i>0;i--);
}
void duoji()
{
TMOD=0x22;
TH0=0x9C;TL0=0x9C;
TH1=0x9C;TL1=0x9C;
EA=1;
ET0=1;ET1=1;
}
void main(void)
{
duoji();
while(1)
{
if(kaishi==0)
{
delay(1000);
if(kaishi==0)
{
c=15;
TR1=1;
a=15;
TR0=1;
}
while(!kaishi);
}
if(jieshu==0)
{
delay(1000);
if(jieshu==0)
{
c=5;
TR1=1;
a=5;
TR0=1;
}
while(!jieshu);
}
else
TR1=0; TR0=0;
}
}
void timer_0(void) interrupt 1 using 0
{
b++;
if(b<a)
{
reshui=1;
}
if(b>a)
{
reshui=0;
}
if(b==200)
{
b=0;
}
TH0=0x9C;TL0=0x9C;
}
void timer_1(void) interrupt 3 using 0
{
d++;
if(d<c)
{
lengshui=1;
}
if(d>c)
{
lengshui=0;
}
if(d==200)
{
d=0;
}
TH1=0x9C;TL1=0x9C;
}
|