单片机超声波测距设计书.docx

上传人:b****6 文档编号:8549429 上传时间:2023-01-31 格式:DOCX 页数:14 大小:303.95KB
下载 相关 举报
单片机超声波测距设计书.docx_第1页
第1页 / 共14页
单片机超声波测距设计书.docx_第2页
第2页 / 共14页
单片机超声波测距设计书.docx_第3页
第3页 / 共14页
单片机超声波测距设计书.docx_第4页
第4页 / 共14页
单片机超声波测距设计书.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

单片机超声波测距设计书.docx

《单片机超声波测距设计书.docx》由会员分享,可在线阅读,更多相关《单片机超声波测距设计书.docx(14页珍藏版)》请在冰豆网上搜索。

单片机超声波测距设计书.docx

单片机超声波测距设计书

单片机设计超声波测距仪设计书

1.概述……………………………2

2.超声波测距模块驱动………………

3.步进电机驱动模块……………

4.12864液晶显示模块………………

5.报警设置…………………………

6.程序…………………………

7.总结………………………………

 

1

1.概述

通过超声波发射装置发出超声波,根据接收器接到超声波时的时间差就可以知道距离了。

这与雷达测距原理相似。

超声波发射器向某一方向发射超声波,在发射时刻的同时开始计时,超声波在空气中传播,途中碰到障碍物就立即返回来,超声波接收器收到反射波就立即停止计时。

(超声波在空气中的传播速度为340m/s,根据计时器记录的时间t,就可以计算出发射点距障碍物的距离(s),即:

s=340t/2)

超声波指向性强,在介质中传播的距离较远,因而超声波经常用于距离的测量,如测距仪等都可以通过超声波来实现。

利用超声波检测往往比较迅速、方便、计算简单、易于做到实时控制,并且在测量精度方面能达到工业实用的要求,因此在移动机器人的研制上也得到了广泛的应用。

为了使移动机器人能自动避障行走,就必须装备测距系统,以使其及时获取距障碍物的距离信息(距离和方向)。

本文所介绍的三方向(前、左、右)超声波系统,就是为机器人了解其前方、左侧和右侧的环境而提供一个运动距离信息。

2超声波测距模块驱动

超声波模块驱动线路图

2

超声波模块控制时序图

超声波模块启动程序

voidStartModule()//启动模块

{

TX=1;//启动一次模块

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();3

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

TX=0;

}

超声波实物图

3、步进电机驱动模块

4

2相6线步进电机驱动方式

 

L298N步进电机驱动芯片

 

5

驱动芯片原理图

L298N实物图

步进电机实物图6

4、12864显示模块

读字节时序图

写字节时序图

12864显示实物图7

5声光报警系统

蜂鸣器、二极管实物图

 

8

6、程序

#include

#include

#defineuintunsignedint

#defineucharunsignedchar

#definepP3

uchardat[8]={0x01,0x05,0x04,0x06,0x02,0x0a,0x08,0x09};

ucharda[8]={0x01,0x09,0x08,0x0a,0x02,0x06,0x04,0x05};

sbitrs=P2^4;

sbitrw=P2^5;

sbite=P2^6;

sbitTX=P1^0;

sbitRX=P1^1;

sbitkey=P1^7;

sbitbeep=P2^1;

sbitdong=P2^0;

uchartable[]="0123456789";

uchartable1[]="--发现UFO--";9

uchartable2[]="距离:

CM";

uchars;

voiddelay50us(uintt)

{

uintj;

for(;t>0;t--)

for(j=19;j>0;j--);

}

delay(uintt)

{

while(t--);

}

voiddelay50ms(uintt)

{

uintj;

for(;t>0;t--)

for(j=6245;j>0;j--);

}

10

voidzl(ucharcom)

{

rs=0;

rw=0;

P0=com;

delay50us

(2);

e=1;

delay50us(10);

e=0;

delay50us

(2);

}

voidsj(ucharcom)

{

rs=1;

rw=0;

P0=com;

delay50us

(2);

e=1;

delay50us(10);

e=0;

delay50us

(2);11

}

voidinit()

{

delay50ms

(2);

zl(0x30);

delay50us(4);

zl(0x30);

delay50us(4);

zl(0x0c);

delay50us(4);

zl(0x01);

delay50us(240);

zl(0x06);

delay50us(10);

}

/********************************************************/

voidStartModule()//启动模块

{

TX=1;//启动一次模块12

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

TX=0;13

}

uchardisplay()

{

uinta,b,c,time;

time=TH0*256+TL0;

TH0=0;

TL0=0;

s=(time*1.7)/100;//算出来是CM

a=s/100;

b=s%100/10;

c=s%10;

zl(0x93);

delay50us

(1);

sj(table[a]);

delay50us

(2);

sj(table[b]);

delay50us

(2);

sj(table[c]);

delay50us

(2);

returns;

}14

 

voidbj()

{

beep=0;

delay(5);

dong=0;

beep=1;

delay(5);

beep=0;

delay(4);

beep=1;

delay(4);

beep=0;

delay(3);

beep=1;

delay(3);

beep=0;

delay

(2);

beep=1;

delay

(2);

beep=0;15

delay

(1);

beep=1;

delay

(1);

}

voidmain(void)

{

uintt;

init();

zl(0x90);

delay50us

(1);

for(t=0;t<8;t++)

{

sj(table2[t]);

delay50us

(2);

if(t==5)

zl(0x95);

}

while

(1)

{uintw,e;

for(w=50;w>0;w--)

{16

for(e=0;e<8;e++)

{

uintt;

TMOD=0x01;//设T0为方式1,GATE=1;

TH0=0;

TL0=0;

ET0=1;//允许T0中断

EA=1;

StartModule();

while(!

RX);//当RX为零时等待

TR0=1;//开启计数

while(RX);//当RX为1计数并等待

TR0=0;//关闭计数

display();

if(s<10)

{

zl(0x81);

for(t=0;t<12;t++)

{

sj(table1[t]);17

delay50us

(2);

}

while(key)

{

bj();

}

beep=1;

dong=1;

init();

zl(0x90);

delay50us

(1);

for(t=0;t<8;t++)

{

sj(table2[t]);

delay50us

(2);

if(t==5)

zl(0x95);

}

}

p=dat[e];

delay50ms

(1);18

}

}

for(w=50;w>0;w--)

{

for(e=0;e<8;e++)

{

uintt;

TMOD=0x01;//设T0为方式1,GATE=1;

TH0=0;

TL0=0;

ET0=1;//允许T0中断

EA=1;

StartModule();

while(!

RX);//当RX为零时等待

TR0=1;//开启计数

while(RX);//当RX为1计数并等待

TR0=0;//关闭计数

display();

if(s<10)

{

zl(0x81);

for(t=0;t<12;t++)19

{

sj(table1[t]);

delay50us

(2);

}

while(key)

{

bj();

}

beep=1;

dong=1;

init();

zl(0x90);

delay50us

(1);

for(t=0;t<8;t++)

{

sj(table2[t]);

delay50us

(2);

if(t==5)

zl(0x95);

}

}20

p=da[e];

delay50ms

(1);

}

}

}

}

 

21

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 其它模板

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1