#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit P1_O=P1^0;
sbit P1_1=P1^1;
sbit P1_2=P1^2;
sbit P1_3=P1^3;
sbit P0_2=P0^1;
sbit P0_3=P0^2;
void delaym1(uint z)
{
uint i;
for(i=0;i<z;i++);
}
void main(void)
{
while(1);
{
TRIG=1;
delay(1);
TRIG=0;
while(ECHO==0);
while(ECHO==1) a++; //a每次加1,所时间约21us
delay(30);
a=((340*a*21)/1000)/2;
display();
scan();
z=a;
a=0;
delay(200);}
void zhiliudianji1()
{
uint i,j;
P0=0X00;
//走直线
for(i=0;i<200;i++)
{ for(i=0;i<500;i++)
{
P0_O=1;
P0_1=0;
delaym1(280);
P0_O=0;
P0_1=0;
P0_2=1;
P0_3=0;
delaym1(420);
P0_2=0;
P0_3=0;
}
P0=0X00;
delaym1(30000);
delaym1(30000);}
//右转弯
void zhiliudianji2()
{for(j=0;j<300;j++)
{ P0_O=1;
P0_1=0;
delaym1(300);
P0_O=0;
P0_1=0;
P0_2=1;
P0_3=0;
delaym1(160);
P0_2=0;
P0_3=0;
}
P0=0X00;
delaym1(30000);
delaym1(30000);
//左转弯
void zhiliudianji3()
{for(i=0;i<600;i++)
{
P0_O=1;
P0_1=0;
delaym1(155);
P0_O=0;
P0_1=0;
P0_2=1;
P0_3=0;
delaym1(650);
P0_2=0;
P0_3=0;
}
P0=0X00;
delaym1(30000);
delaym1(30000);}
P0=0x00;
while(1);
}
}
void main(void)
{
while(1)
{
TRIG=1;
delay(1);
TRIG=0;
while(ECHO==0);
while(ECHO==1) a++; //a每次加1,所时间约21us
delay(30);
a=((340*a*21)/1000)/2;
if(a==50)
esle
{ void zhiliudianji3();}
delay(200);
void zhiliudianji1();
z=a;
a=0;
delay(200);
}
急求基于AT89C51单片机的循迹避障小车电路原理图和主程序(避障模块是超 ...
include <reg51.h> defineuchar unsigned char define uint unsigned int sbit P1_O=P1^0;sbit P1_1=P1^1;sbit P1_2=P1^2;sbit P1_3=P1^3;sbit P0_2=P0^1;sbit P0_3=P0^2;void delaym1(uint z){ uint i;for(i=0;i<z;i++);} void main(void){ while(1);{ TRIG=1;de...
求51单片机超声波避障程序
这是一个超声波避障小车的源程序,可以参考下,用的89C52单片机,舵机控制转角避障。#include<AT89x51.H>#include <intrins.h> #define Sevro_moto_pwm P2_7 \/\/接舵机信号端输入PWM信号调节速度 #define ECHO P2_4 \/\/超声波接口定义#define TRIG P2_5 \/\/超声波接口定义 #define Left_moto_go {P1_0=1,P...
谁有单片机的小车论文
论文关键字:AT89C51单片机 直流电机 红外线遥控 循迹 L298 一、设计任务和要求 以AT98C51单片机为核心,制作一款红外遥控小车,小车具有自动驾驶,手动驾驶和循迹前进等功能。自动驾驶时,前进过程中可以避障。手动驾驶时,遥控控制小车前进、后退、左转、右转、加速等操作。寻迹前进时小车还可以按照预先...