用串口调试助手可以测试路由器发的指令给单片机没有问题,用串口调试助手测试云台也没有问题唯独用路由器通过ttl给单片机控制云台就是不懂,求群友们帮忙解答一下如果有测试好的51单片机控制舵机云台程序发给小弟看看,小弟不胜感激!
小弟测试程序如下,请高人们指点一下!!!!
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uint i=0,j,URTAReceivedCount=0,n=1;
uchar flag=0;
uchar key_stime_counter,hight_votage=15,timeT_counter; //舵机的变量
bit key_stime_ok;
sbit control_signal=P2^0; //舵机控制信号
unsigned char flag,q,a;
sbit b =P1^0;
sbit c=P1^1;
sbit d=P1^2;
sbit e=P1^3;
uchar code table[]="I get";
void Delay_1ms(uint i)//1ms延时
{
uchar x,j;
for(j=0;j<i;j++)
for(x=0;x<=148;x++);
}
void init()
{
TMOD = 0x21;
PCON = 0x00;
SCON = 0x50;
TH1 = 0xFd; //设置波特率 9600
TL1 = 0xFd;
TR1 = 1; //启动定时器1
ES = 1; //开串口中断
EA = 1; //开总中断
IT0=0;
EX0=1;
}
void TimerInit()
{
control_signal=0;
TMOD|=0X01;
TH0 = 0xFF; //定时器装初值
TL0 = 0xA3;
EA=1; //开总中断
ET0=1; //定时器0中断允许
TR0=0;
}
void SteerEngineTurningUp()
{
// ET0=1;
TR0=1;
Delay_1ms(40);
hight_votage-=1;
if(hight_votage<5)
hight_votage=5;
b=~b;
if(hight_votage==5)
TR0=0;
}
void SteerEngineTurningDown()
{
//ET0=1;
TR0=1;
Delay_1ms(40);
hight_votage+=1;
if(hight_votage>25)
hight_votage=25;
c=~c;
if(hight_votage==25)
TR0=0;
}
void main()
{
init();
TimerInit();
while(1)
{
if(flag==1)
{
ES=0;
//for(table != '\0')
for(q=0;q<7;q++)
{
SBUF=table[q];
while(!TI);
TI=0;
}
SBUF=a;
while(!TI);
TI=0;
ES=1;
flag=0;
}
}
}
void ser() interrupt 4
{
RI=0;
a=SBUF;
flag=1;
switch(a)
{
case '1':
SteerEngineTurningUp();
break;
case '2': c=~c;
SteerEngineTurningDown();
break;
case '3': d=~d;
break;
case '4': e=~e;
break;
default: break;
}
}
void SteerEngine() interrupt 1 //0.1MS PER INTERRTUPT
{
TH0=0xFF;
TL0=0xA3;
if (key_stime_ok&&(++timeT_counter>=hight_votage))
{
key_stime_ok=0;
timeT_counter=0;
control_signal=0; // hight_votage*0.1ms到
}
if (++key_stime_counter>=200)
{
key_stime_counter=0;
control_signal=1;
key_stime_ok = 1; // 20ms到
timeT_counter=0;
}
}
|