基于51单片机的超声波测距系统设计
- 格式:doc
- 大小:2.43 MB
- 文档页数:47
湖南人文科技学院毕业设计
I 摘 要:本文介绍了基于STC89C51系列单片机超声波测距系统,系统采用STC89C51单片机作为控制器,自动实现超声波的发射和接收控制。采用HC-SR04模块作为超声波的发射和接收模块,并且还利用DS18B20测量环境温度,考虑了环境温度对超声波传输速度的影响。通过单片机的定时器计数超声波往返所经历的时间,通过换算得到传感器与反射物之间的距离。系统的显示模块则是采用LCD1602液晶显示屏,能够显示测试距离和环境温度。该设计采用相关计数法的超声波测距原理所得到的实验结果验证了本系统具有成本低、精度高、电路简单和抗干扰性强的优势,因此可以广泛应用于一些中小规模的测量装置。
关键词:单片机;超声波测距;计数法
湖南人文科技学院毕业设计
II The design of ultrasonic distance measurement
system based on STC89C51
Abstract: This paper presents an ultrasonic distance measurement system based on STC89C51
single-chip microcontroller. This system uses STC89C51 as the controller to control ultrasonic’s
emission and receipt automatically. The design uses HC-SR04 module as the emission and receipt
module, and also applies DS18B20 to measure the temperature of current circumstance, taking the
influence of temperature into consideration. By counting the time that the ultrasonic go and come
back and then converts it as the distance between ultrasonic sensor and reflector. The display
module of this system is 1602 liquid crystal display, and it can display the circumstance
temperature and the distance. Because the system uses the correlated counting method, the
experimental result show that the advantage of this system are of low price, high accuracy and
simplicity. The proposed system can be widely used in the middle or small distance measurement
device.
Key words: single-chip controller;ultrasonic distance measurement;
counting method
湖南人文科技学院毕业设计
III
目 录
第1章 绪论 ............................................................................................................................. 1
1.1选题背景 ..................................................................................................................... 1
1.2国内外研究现状与发展趋势 ................................................................................... 1
1.3设计思路与结构 ........................................................................................................ 2
第2章 系统概述与硬件电路设计 ...................................................................................... 3
2.1系统整体框架 ............................................................................................................. 3
2.2 STC89C52单片机最小系统 ..................................................................................... 4
2.3 HC—SR04超声波测距模块 ...................................................................................... 6
2.4 DS18B20测温模块 .................................................................................................... 8
2.5 LCD1602显示模块 ..................................................................................................... 9
2.6按键模块 ................................................................................................................... 11
2.7蜂鸣器报警模块 ...................................................................................................... 13
第3章 系统软件设计 .......................................................................................................... 14
3.1软件设计总流程 ...................................................................................................... 14
3.2单片机驱动HC-SR04模块程序设计 .................................................................... 16
3.3单片机计算测试模块与障碍物距离算法设计 ................................................... 17
3.4单片机定时器计时程序设计 ................................................................................. 17
3.5 DS18B20驱动程序设计.......................................................................................... 19
3.6 LCD1602液晶驱动程序设计 ................................................................................. 23
3.7 按键模块程序设计 ................................................................................................. 26
3.8 蜂鸣器报警模块程序设计 .................................................................................... 29
第4章 系统调试及结果分析 ............................................................................................. 30
4.1系统测距试验结果 .................................................................................................. 30
4.2结果分析 ................................................................................................................... 30 湖南人文科技学院毕业设计
IV 4.3误差分析 ................................................................................................................... 31
致谢 .......................................................................................................................................... 32
参考文献 ................................................................................................................................. 33