当前位置:网站首页>基于51单片机的超声波测距仪
基于51单片机的超声波测距仪
2022-07-04 12:51:00 【toyjis】
该项目是基于HC-SR04超声波传感器的测距仪,使用数码管显示距离。测距范围为2cm-400cm,使用定时器0中断设定传感器测量频率,每200ms刷新一次数据。
HC-SR04是常见的超声波传感器,常用于智能小车的测距,避障,盲人拐杖等领域;该模块直接集成了超声波发射器、接收器与控制电路,直接插上就可以直接工作,不需要再接入驱动电路。
HC-SR04基本工作原理:
1、使用单片机的一个引脚发送一个至少10us高电平的TTL脉冲信号到模块的Trig引脚,用于触发模块工作(代码中体现为开始测距函数)。
2、模块检测到触发信号之后,会自动发送8个40khz的方波,然后自动切换至监测模式,监测是否有信号返回。
3、如果有信号返回,通过模块的Echo引脚会输出一个高电平, 高电平持续的时间就是超声波从发射到返回的时间(代码中体现为获取距离函数)。
本次设计没有使用简单的延迟函数,而是使用定时器中断来控制测距的频率,这样可以保证传感器有足够时间接收数据、处理数据。
系统的仿真图如下:
依旧是绘制了PCB版图,本次绘制的是直插器件的PCB,以后会加入贴片器件版本,这样可以做成小型测距仪。
部分代码如下所示,代码按照HC-SR04的指令要求编写
int getdistance(void)
{
start();
while(!ECHO);
TR1=1;
while(ECHO);
TR1=0;
time=TH1*256+TL1;
TH1=0;
TL1=0;
s=(time*1.7)/100+1; //测得cm
if(flag==1||(s>700))
{
flag=0;
s=0;
return s;
}
return s;
}
void main()
{
init();
while(1)
{
display(distance);
}
}
**资源包括:keilC语言代码+Proteus仿真原理图+ad原理图PCB+产品说明书**
边栏推荐
- [R language data science]: cross validation and looking back
- 392. Judgement subsequence
- docker-compose公网部署redis哨兵模式
- MySQL 5 installation and modification free
- Ws2811 m is a special circuit for three channel LED drive and control, and the development of color light strip scheme
- IP 实验室月复盘 · 第 5 期
- Rich text editing: wangeditor tutorial
- Product identification of intelligent retail cabinet based on paddlex
- Introducing testfixture into unittest framework
- The mouse wheel of xshell/bash/zsh and other terminals is garbled (turn)
猜你喜欢
TestSuite and testrunner in unittest
软件测试之测试评估
Use the default route as the route to the Internet
Understand chisel language thoroughly 09. Chisel project construction, operation and testing (I) -- build and run chisel project with SBT
China Post technology rushes to the scientific innovation board: the annual revenue is 2.058 billion, and the postal group is the major shareholder
CVPR 2022 | greatly reduce the manual annotation required for zero sample learning, and propose category semantic embedding rich in visual information (source code download)
Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
Ruichengxin micro sprint technology innovation board: annual revenue of 367million, proposed to raise 1.3 billion, Datang Telecom is a shareholder
按照功能对Boost库进行分类
markdown 语法之字体标红
随机推荐
Idea shortcut keys
基于YOLOv1的口罩佩戴检测
China Post technology rushes to the scientific innovation board: the annual revenue is 2.058 billion, and the postal group is the major shareholder
小程序直播 + 电商,想做新零售电商就用它吧!
【FAQ】華為帳號服務報錯 907135701的常見原因總結和解决方法
Remove duplicate letters [greedy + monotonic stack (maintain monotonic sequence with array +len)]
LiveData
Yingshi Ruida rushes to the scientific and Technological Innovation Board: the annual revenue is 450million and the proposed fund-raising is 979million
gorm 之数据插入(转)
Supprimer les lettres dupliquées [avidité + pile monotone (maintenir la séquence monotone avec un tableau + Len)]
程序员的焦虑
2022游戏出海实用发行策略
QT how to detect whether the mouse is on a control
Common content type correspondence table
Product identification of intelligent retail cabinet based on paddlex
为什么图片传输要使用base64编码
Install and use MAC redis, connect to remote server redis
Unittest中的TestSuite和TestRunner
Learning projects are self-made, and growth opportunities are self created
R语言ggplot2可视化:gganimate包创建动态折线图动画(gif)、使用transition_reveal函数在动画中沿给定维度逐步显示数据