藍牙控制舵機,為什么輸入控制信號舵機不轉?
單片機源程序如下:
#include<reg52.h>
sbit SG_PWM=P3^7;
sbit led1=P1^0;
sbit led2=P1^1;
unsigned char count=0;
unsigned char PWM_count,tmp;
void Timer_Init()
{
TMOD=0X01;
TH0=0Xfe;
TL0=0X33;
ET0=1;
TR0=1;
TR1= 1;
REN= 1;
SM0= 0;
SM1= 1;
ES= 1;
EA=1;
}
void Timer() interrupt 1 using 1
{
SCON=0X50; //éèÖÃ1¤×÷·½ê½Îa1,8λêy¾Y,¿é±ä2¨ìØÂê
TR0=0;
TH0=0Xfe;
TL0=0X33;
if(count<PWM_count)
{
SG_PWM=1;
}
else
{
SG_PWM=0;
}
count++;
if(count>=40)
{
count=0;
}
TR0=1;
}
void main()
{
Timer_Init();
while(1)
{
switch(tmp)
{
case(0x01):
{
PWM_count=2;
led1=0;
break;
}
case(0x02):
{
PWM_count=4;
led2=0;
break;
}
}
}
}
void chuan_rx() interrupt 4 using 2
{
RI=0;
tmp=SBUF;
}
大佬們看一下
|