|
//将小车同侧的两个轮子用两个I/O口一起控制
//晶振11.0592
#include<reg51.h>
sbit left1 = P1^0;
sbit left2 = P1^1;
sbit right1 = P1^2;
sbit right2 = P1^3;
void forward(void)
{
left1 = 1;
left2 = 0;
right1 = 1;
right2 = 0;
}
void back(void)
{
left1 = 0;
left2 = 1;
right1 = 0;
right2 = 1;
}
void stop(void)
{
left1 = 0;
left2 = 0;
right1 = 0;
right2 = 0;
}
void turn_left1(void)//原地左转
{
left1 = 0;
left2 = 0;
right1 = 1;
right2 = 0;
}
void turn_right1(void)//原地左转
{
left1 = 1;
left2 = 0;
right1 = 0;
right2 = 0;
}
void turn_left2(void)
{
left1 = 0;
left2 = 1;
right1 = 1;
right2 = 0;
}
void turn_left2(void)
{
left1 = 1;
left2 = 0;
right1 = 0;
right2 = 1;
}
void delay1s(void) //误差 -0.00000000024us
{
unsigned char a,b,c;
for(c=95;c>0;c--)
for(b=26;b>0;b--)
for(a=185;a>0;a--);
}
void main(void)
{
while(1)
{
forward();
delay1s();
back();
delay1s();
turn_left1();
delay1s();
turn_right();
delay1s();
}
}
|
|