直接上代码
main.c
#include "motor.h"
#include "delay.h"
#include "uart.h"
void main()
{
UartInit(); //串口初始化
while(1){
}
}
motor.c
#include "reg52.h"
sbit RightCon1A = P3^2;
sbit RightCon1B = P3^3;
sbit LeftCon1A = P3^4;
sbit LeftCon1B = P3^5;
void goForWard(){ //小车前转
LeftCon1A = 1;
LeftCon1B = 0;
RightCon1A = 1;
RightCon1B = 0;
}
void goBack(){ //小车后转
LeftCon1A = 0;
LeftCon1B = 1;
RightCon1A = 0;
RightCon1B = 1;
}
void goLeft(){ //小车左转
LeftCon1A = 0;
LeftCon1B = 0;
RightCon1A = 1;
RightCon1B = 0;
}
void goRight(){ //小车右转
LeftCon1A = 1;
LeftCon1B = 0;
RightCon1A = 0;
RightCon1B = 0;
}
void stop(){ //小车停止
LeftCon1A = 0;
LeftCon1B = 0;
RightCon1A = 0;
Right