#include "reg52.h"
#include "intrins.h"
sbit RightCtrlA = P3^2;
sbit RightCtrlB = P3^3;
sbit LeftCtrlA = P3^4;
sbit LeftCtrlB = P3^5;
void Delay1000ms() //@11.0592MHz
{
unsigned char i, j, k;
_nop_();
i = 8;
j = 1;
k = 243;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void goForward(){
LeftCtrlA = 0;
LeftCtrlB = 1;
RightCtrlA = 0;
RightCtrlB = 1;
}
void goLeft(){
LeftCtrlA = 0;
LeftCtrlB = 0;
RightCtrlA = 0;
RightCtrlB = 1;
}
void goRight(){
LeftCtrlA = 0;
LeftCtrlB = 1;
RightCtrlA = 0;
RightCtrlB = 0;
}
void goBack(){
LeftCtrlA = 1;
LeftCtrlB = 0;
RightCtrlA = 1;
RightCtrlB = 0;
}
void main(){
while(1){
goForward();
Delay1000ms();
Delay1000ms();
goBack();
Delay1000ms();
Delay1000ms();
goLeft();
Delay1000ms();
Delay1000ms();
goRight();
Delay1000ms();
Delay1000ms();
}
}
若出现项目中找不到某个c文件,解决办法:
代码(20./03. 串口控制小车)
#include "motor.h"
#include "delay.h"
#include "uart.h"
void main(){
UartInit();
while(1){
stop();
}
}