当前位置:网站首页>基于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+产品说明书**
边栏推荐
- 英视睿达冲刺科创板:年营收4.5亿 拟募资9.79亿
- Huahao Zhongtian rushes to the scientific and Technological Innovation Board: the annual loss is 280million, and it is proposed to raise 1.5 billion. Beida pharmaceutical is a shareholder
- 基于YOLOv1的口罩佩戴检测
- 1200. 最小绝对差
- Whether the loyalty agreement has legal effect
- 测试流程整理(2)
- 吃透Chisel语言.05.Chisel基础(二)——组合电路与运算符
- [matlab] summary of conv, filter, conv2, Filter2 and imfilter convolution functions
- Can mortgage with housing exclude compulsory execution
- Fs4059c is a 5V input boost charging 12.6v1.2a. Inputting a small current to three lithium battery charging chips will not pull it dead. The temperature is 60 ° and 1000-1100ma is recommended
猜你喜欢

sharding key type not supported
![[matlab] summary of conv, filter, conv2, Filter2 and imfilter convolution functions](/img/7a/9b559313b407f9a12cbaed7bebd4dc.png)
[matlab] summary of conv, filter, conv2, Filter2 and imfilter convolution functions

中邮科技冲刺科创板:年营收20.58亿 邮政集团是大股东

Vscode common plug-ins summary

自主工业软件的创新与发展

使用默认路由作为指向Internet的路由

MySQL 5 installation and modification free

Yingshi Ruida rushes to the scientific and Technological Innovation Board: the annual revenue is 450million and the proposed fund-raising is 979million
![递增的三元子序列[贪心训练]](/img/92/7efd1883c21c0e804ffccfb2231602.png)
递增的三元子序列[贪心训练]
![[FAQ] Huawei Account Service Error Report 907135701 Common reasons Summary and Solutions](/img/43/1a9786c89a5ab21d1fb8903cb7b77e.png)
[FAQ] Huawei Account Service Error Report 907135701 Common reasons Summary and Solutions
随机推荐
Mask wearing detection based on yolov1
華昊中天沖刺科創板:年虧2.8億擬募資15億 貝達藥業是股東
富文本编辑:wangEditor使用教程
Understand chisel language thoroughly 06. Chisel Foundation (III) -- registers and counters
The mouse wheel of xshell/bash/zsh and other terminals is garbled (turn)
测试流程整理(3)
Mongodb commonly used 28 query statements (forward)
常见 content-type对应表
docker-compose公网部署redis哨兵模式
ARouter的使用
qt 怎么检测鼠标在不在某个控件上
How to operate and invest games on behalf of others at sea
92.(cesium篇)cesium楼栋分层
Unity shader learning (3) try to draw a circle
[matlab] summary of conv, filter, conv2, Filter2 and imfilter convolution functions
MySQL5免安装修改
10.(地图数据篇)离线地形数据处理(供Cesium使用)
R语言使用dplyr包的group_by函数和summarise函数基于分组变量计算目标变量的均值、标准差
做事的真正意义和目的,真正想得到什么
[C question set] of VII