|
#include<AT89x51.H>
#define A_left_moto_go {P2_0 = 1,P2_1 = 0;} //左前轮向前
#define A_left_moto_back {P2_0 = 0,P2_1 = 1;} //左前轮向后
#define A_left_moto_stop {P2_0 = 0,P2_1 = 0;} //左前轮停止
#define B_left_moto_go {P2_2 = 1,P2_3 = 0;} //
#define B_left_moto_back {P2_2 = 0,P2_3 = 1;} //
#define B_left_moto_stop {P2_2 = 0,P2_3 = 0;} //
#define A_right_moto_go {P1_0 = 1,P1_1 = 0;} //右前轮向前
#define A_right_moto_back {P1_0 = 0,P1_1 = 1;} //右前轮向后
#define A_right_moto_stop {P1_0 = 0,P1_1 = 0;}
#define B_right_moto_go {P1_2 = 1,P1_3 = 0;} //
#define B_right_moto_back {P1_2 = 0,P1_3 = 1;}
#define B_right_moto_stop {P1_2 = 0,P1_3 = 0;}
#define uint unsigned int //??????????
#define uchar unsigned char //??????????
sbit BZ=P3^7;
a=0;
void delay(uchar z)//??????????
{
int i,j;//??????
for(i=10;i>0;i--)
for(j=z;j>0;j--);//???z???j
}
void uart_init()
{
TMOD = 0x20;
PCON = 0x00;
SCON = 0x50;
TH1 = 0xFd; //????? 9600
TL1 = 0xFd;
TR1 = 1; //?????1
ES = 1; //?????
EA = 1; //????
BZ=1;
}
/************************************************************************/
void run()
{
A_left_moto_go;
A_right_moto_go;
B_left_moto_go;
B_right_moto_go;
}
void back_run()
{
A_left_moto_back;
A_right_moto_back;
B_left_moto_back;
B_right_moto_back;
}
void stop_run()
{
A_left_moto_stop;
A_right_moto_stop;
B_left_moto_stop;
B_right_moto_stop;
}
void left_run()
{
A_left_moto_back;
A_right_moto_go;
B_left_moto_back;
B_right_moto_go;
}
void right_run()
{
A_left_moto_go;
A_right_moto_back;
B_left_moto_go;
B_right_moto_back;
}
void uart() interrupt 4
{
if(RI==1)
RI=0;
a=SBUF;
}
void main()
{
//P0=0XFF;
uart_init();
while(1)
{
if(BZ==0) stop_run();
if(a==0x00) stop_run();
if(a==0x3f) run();
if(a==0x4f) back_run();
if(a==0x1f) left_run();
if(a==0x2f) right_run();
if(a==0x5f) left_run();
if(a==0x6f) right_run();
if(a==0x7f) left_run();
if(a==0x8f) right_run();
}
}
|
|