山西大学工程学院
基于单片机的超声波测距仪的设计
摘要
本设计介绍了基于单片机设计的超声波测距仪的原理:由STC89C51控制定时器产生
超声波脉冲并计时,计算超声波自发射至接收的往返时间,从而得到测量距离。并且在数据处理中设置了距离的高低限,用四位LED数码管显示距离,同时当超过限值时用蜂鸣器实现报警。此超声波测距系统是基于51单片机,由HC-SR04超声波测距模块,数码管,阻容元件,蜂鸣器等组成,系统带有距离报警功能,报警通过蜂鸣器和LED做出反应,并且系统报警距离可通过按键随时更改。超声波测距模块可提供2cm—400cm的非接触式感测功能,测距精度可达到3mm,模块包括超声波发射器,接收器以及控制电路。本作品成本低,可抗性相对较高,测得的距离能够清晰稳定的显示在四位数码管上,且小巧轻便,应用起来比较方便。
关键词:STC89C51;超声波;测距
I
山西大学工程学院
Ultrasonic rangefinder design based on single chip
microcomputer
Abstract
This design describes the chip design based on the principle of ultrasonic range finder:when STC89C51 controlled the timer that generates an ultrasonic pulse and timing ,calculated the round-trip time from the ultrasonic transmitter to the receiver , resulting in the measured distance. In the data processing and set high and low limit of distance, with four LED digital display distance, but when the limit is exceeded an alarm buzzer. This ultrasonic ranging system is based on 51 single, the HC-SR04 ultrasonic ranging module, LED, resistive and capacitive components, buzzer, etc., with distance alarm system, alarm buzzer and respond by LED, and the system can be changed at any time from the alarm by pressing a button. Ultrasonic Ranging Module provides 2cm-400cm non-contact sensing capabilities, ranging accuracy can reach 3mm, module comprises an ultrasonic transmitter, a receiver and a control circuit. The work of low cost, relatively high resistance, the measured distance can be displayed on a clear and stable four digital tube, and the compact and light weight, the application more convenient. Keywords: AT89C51; ultrasound; ranging
II
山西大学工程学院
目录
第一章 引言 ......................................................................................................... - 1 - 1.1 课题研究的背景 ...................................................................................... - 1 - 1.2 课题的提出及研究意义 .......................................................................... - 1 - 1.2.1 课题的提出 ..................................................................................... - 1 - 1.2.2 课题的研究意义 ............................................................................. - 2 - 第二章 超声波的介绍及超声波测距的原理 ..................................................... - 3 - 2.1 超声波的简介 .......................................................................................... - 3 - 2.1.1 什么是超声波 ................................................................................. - 3 - 2.1.2 超声波的特性及特点 ..................................................................... - 3 - 2.1.3 超声波的应用 ................................................................................. - 4 - 2.2 超声波测距的原理 .................................................................................. - 4 - 2.2.1 超声波发生器 ................................................................................. - 4 - 2.2.2 压电式超声波发生器的原理 ......................................................... - 5 - 2.2.3 超声波测距的原理 ......................................................................... - 5 - 第三章 方案设计及元件选型 ............................................................................. - 6 - 3.1设计方案 ................................................................................................... - 6 - 3.1.1 设计思路 ......................................................................................... - 6 - 3.1.2 系统最终方案 ................................................................................. - 6 - 3.2 STC89C51单片机的介绍 ........................................................................ - 6 - 3.2.1 STC89C51单片机的功能 ............................................................... - 7 - 3.2.2 STC89C51单片机的主要特性 ....................................................... - 7 -
III
山西大学工程学院
3.2.3 STC89C51的管脚说明 ................................................................... - 8 - 3.3 HC-SR04超声波发射接收模块 .............................................................. - 9 - 3.3.1超声波模块的特点 .......................................................................... - 9 - 3.3.2基本的工作原理 .............................................................................. - 9 - 3.3.3引脚介绍 ........................................................................................ - 10 - 3.3.4电气参数 ........................................................................................ - 10 - 第四章 硬件设计 ............................................................................................... - 11 - 4.1 系统结构设计 ........................................................................................ - 11 - 4.2 接收显示终端电路 ................................................................................ - 11 - 4.3 超声波发射电路 .................................................................................... - 12 - 4.4 超声波接收电路 .................................................................................... - 13 - 4.5 报警电路 ................................................................................................ - 14 - 4.6 电源电路 ................................................................................................ - 15 - 第五章 软件设计 ............................................................................................... - 16 - 5.1 软件总体设计 ........................................................................................ - 16 - 5.2 主程序设计 ............................................................................................ - 16 - 5.2.1 主程序设计思路 ........................................................................... - 16 - 5.2.2 主程序流程图 ............................................................................... - 17 - 5.2.3 主程序及程序说明 ....................................................................... - 17 - 5.3显示模块程序设计 ................................................................................. - 18 -
5.3.1 程序设计思路 ............................................................................... - 18 - 5.3.2 显示子程序及程序说明 ............................................................... - 18 -
IV