当前位置:网站首页>基于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+产品说明书**
边栏推荐
- 1200. Minimum absolute difference
- TestSuite and testrunner in unittest
- China Post technology rushes to the scientific innovation board: the annual revenue is 2.058 billion, and the postal group is the major shareholder
- 学内核之三:使用GDB跟踪内核调用链
- Unity shader learning (3) try to draw a circle
- 基于PaddleX的智能零售柜商品识别
- Install MySQL
- 吃透Chisel语言.04.Chisel基础(一)——信号类型和常量
- MySQL 5 installation and modification free
- golang fmt. Printf() (turn)
猜你喜欢

docker-compose公网部署redis哨兵模式
![[antd] how to set antd in form There is input in item Get input when gourp Value of each input of gourp](/img/eb/11e5da1c5e897c5f6a18d49125925f.png)
[antd] how to set antd in form There is input in item Get input when gourp Value of each input of gourp

JVM memory layout detailed, illustrated, well written!

Applet live + e-commerce, if you want to be a new retail e-commerce, use it!

vscode 常用插件汇总
![[FAQ] summary of common causes and solutions of Huawei account service error 907135701](/img/43/1a9786c89a5ab21d1fb8903cb7b77e.png)
[FAQ] summary of common causes and solutions of Huawei account service error 907135701

基于YOLOv1的口罩佩戴检测

MySQL version 8 installation Free Tutorial

392. 判断子序列

【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
随机推荐
xshell/bash/zsh 等终端鼠标滚轮乱码问题(转)
Basic mode of service mesh
[antd step pit] antd form cooperates with input Form The height occupied by item is incorrect
Understand chisel language thoroughly 07. Chisel Foundation (IV) - bundle and VEC
LifeCycle
go vendor 项目迁移到 mod 项目
Error in find command: paths must precede expression (turn)
吃透Chisel语言.10.Chisel项目构建、运行和测试(二)——Chisel中生成Verilog代码&Chisel开发流程
Incremental ternary subsequence [greedy training]
做事的真正意义和目的,真正想得到什么
sharding key type not supported
基于YOLOv1的口罩佩戴检测
2022 game going to sea practical release strategy
Why should Base64 encoding be used for image transmission
小程序直播 + 电商,想做新零售电商就用它吧!
Product identification of intelligent retail cabinet based on paddlex
[R language data science]: cross validation and looking back
Assertion of unittest framework
Rich text editing: wangeditor tutorial
Understand chisel language thoroughly 11. Chisel project construction, operation and test (III) -- scalatest of chisel test