舵机程序,不太稳定,大佬们看看问题出在哪里
#include<reg52.h>
unsigned char count;
sbit pwm1=P1^0;
sbit pwm2=P1^1;
sbit jia=P3^0;
sbit jan=P3^1;
sbit zuo=P3^2;
sbit you=P3^3;
unsigned char jd1,jd2,m1,m2;
void delay(unsigned int x)
{
unsigned char i,j;
for(i=x;i>0;i--)
for(j=125;j>0;j--);
}
void Timer0_Init()
{
TMOD=0x01;
IE=0x82;
TH0=0xff;
TL0=0x9c;
TR0=1;
}
void Timer0_Int() interrupt 1
{
TH0=0xff;
TL0=0x9c;
if(m1<jd1)
pwm1=1;
else
pwm1=0;
if(m2<jd2)
pwm2=1;
else
pwm2=0;
count++;
count%=200;
m1=count;
m2=count;
}
void keyscan()
{
if(jia==0)
{
delay(50);
if(jia==0)
{
jd1++;
if(jd1>=26)
jd1=25;
while(jia==0);
}
}
if(jan==0)
{
delay(50);
if(jan==0)
{
|