#include <AT89X52.H>
#include "UART.h"
#include "timer0.h"
typedef unsigned int uint;
typedef unsigned char uchar;
uint Su_Ju = 0;
sbit Moter_1=P0^1;
sbit Moter_2=P0^2;
sbit Moter_3=P0^3;
sbit Moter_4=P0^4;
sbit XunJi_1=P1^0;
sbit XunJi_2=P1^1;
unsigned char counter_1,shudu_1,shudu_2,behind_1,behind_2;
void main()
{
unsigned char Mo_Shi=0;
UART_Init();
Timer0_Init();
while(1)
{
if (Su_Ju==0x35 ||Su_Ju==0x36)//遥控模式
{
Mo_Shi= Su_Ju;
}
if (Mo_Shi==0x35)//遥控模式
{
if (Su_Ju==0x30)//向左
{
behind_1=1;
behind_2=0;
shudu_1=100;
shudu_2=50;
}
if (Su_Ju==0x31)//向右
{
behind_1=1;
behind_2=0;
shudu_1=40;
shudu_2=90;
}
if (Su_Ju==0x32)//向后
{
behind_1=1;
behind_2=0;
shudu_1=100;
shudu_2=90;
}
if (Su_Ju==0x33)//向前
{
behind_1=0;
behind_2=1;
shudu_1=100;
shudu_2=90;
}
if (Su_Ju==0x34)//停止
{
behind_1=0;
behind_2=0;
}
}
if (Mo_Shi==0x36)//循迹模式
{
behind_1=1;
behind_2=0;
if (XunJi_1==0&&XunJi_2==0)
{
shudu_1=20;
shudu_2=20;
}
if (XunJi_1==0&&XunJi_2==1)//左
{
shudu_1=60;
shudu_2=0;
}
if (XunJi_1==1&&XunJi_2==0)//右
{
shudu_1=0;
shudu_2=60;
}
}
}
}
void TIMER_Interrupt()interrupt 1
{
TL0= 0x9C; //设置定时初值
TH0 = 0xFF; //设置定时初值
counter_1++;
counter_1%=100;
if (counter_1<shudu_1)
{
Moter_1=behind_1;
Moter_2=behind_2;
}
else
{
Moter_1=0;
Moter_2=0;
}
if (counter_1<shudu_2)
{
Moter_3=behind_1;
Moter_4=behind_2;
}
else
{
Moter_3=0;
Moter_4=0;
}
}
void UART_Interrupt() interrupt 4
{
Su_Ju=SBUF;
RI=0;
SBUF = Su_Ju; //手机和蓝牙模块通讯时,我们可以打开电脑串口调试工具查看我们的发送值)
while(!TI);
TI = 0;
}