代码如下,仿真时可以运行两个舵机,到了普中开发板上就只有一个口能用?
求助求助
单片机源程序如下:
#include <reg51.h>
#include <stdio.h>
typedef unsigned char uchar;//0~255
typedef unsigned int uint;//0~65535
uchar Turn_angle=1;
sbit PWM_1 = P3^7;
sbit PWM_2 = P3^5;//
uchar kk =0;
uint control_pwm;
uint clfition;//·ÖÀà±äÁ¿
void delay_ms(uint c)
{
uint a,b;
for(;c>0;c--)
for(b=102;b>0;b--)
for(a=3;a>0;a--);
}
void Time0_Init()
{
TMOD=0x01;
EA=1;
ET0=1;
TH0=0xff;
TL0=0xa3;
TR0=1;
}
void main()
{
Time0_Init();
kk=0;
clfition=0;
while(1){
control_pwm=0;
switch(clfition)
{
case 0:{
Turn_angle=5;
delay_ms(2000);
control_pwm=1;
Turn_angle=20;
delay_ms(2000);
Turn_angle=5;
delay_ms(1000);
clfition=4;
break;}
case 1:{
Turn_angle=10;
delay_ms(2000);
control_pwm=1;
Turn_angle=20;
delay_ms(2000);
Turn_angle=5;
delay_ms(1000);
clfition=4;
break;}
case 2:{
Turn_angle=15;
delay_ms(2000);
control_pwm=1;
Turn_angle=20;
delay_ms(2000);
Turn_angle=5;
delay_ms(1000);
clfition=4;
break;}
case 3:{
Turn_angle=20;
delay_ms(2000);
control_pwm=1;
Turn_angle=20;
delay_ms(2000);
Turn_angle=5;
delay_ms(1000);
clfition=4;
break;}
default:break;
}
}}
void timer() interrupt 1
{
TR0=0;
TH0=0xff;
TL0=0xa3;
switch(control_pwm){
case 0:
{
if(kk<=Turn_angle)
PWM_1=1;
else
PWM_1=0;
if(kk==200)
kk=0;
kk++;
TR0=1;
break;}
case 1:
{if(kk<=Turn_angle)
PWM_2=1;
else
PWM_2=0;
if(kk==200)
kk=0;
kk++;
TR0=1;
break;}
}
}
|