当前位置:网站首页>基于51单片机的三路超声波测距系统(定时器方式测距)
基于51单片机的三路超声波测距系统(定时器方式测距)
2022-04-23 06:14:00 【锦官城外w】
功能说明:
基于51单片机的三路(可更多)HCSR04、US100(io模式)超声波测距代码
注意事项:
处理器:STC89C51/STC89C52
显示屏:LCD1602
超声波:HCSR04、US100(io模式)
预留按键任务接口方便用户使用
相关引脚连线中文注释:
#include<reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
//---定义lcd1602使用的IO口---//
#define LCD_DATA P0
sbit RS=P2^7;
sbit RW=P2^6;
sbit EN=P2^5;
//---定义 按键 使用的IO口---//
sbit key1=P1^5;
sbit key2=P1^6;
sbit key3=P1^7;
//---定义 led 使用的IO口---//
sbit led=P2^1;
//HCSR04/US100超声波接口
sbit Trig1 = P2^0;
sbit Echo1 = P2^1;
sbit Trig2 = P2^2;
sbit Echo2 = P2^3;
sbit Trig3 = P3^7;
sbit Echo3 = P3^6;
主函数程序:
void
main()
{
lcd_init(); //1602初始化
Timer_Init(); //初始化定时器
while(1) //循环读取 并更新数据显示
{
key_scan(); //扫描按键(预留)
get_distance(1); //计算超声波1距离
dis_str(0,0,"US1:");dis_shu(4,0,distance1); //超声波1距离显示
get_distance(2); //计算超声波2距离
dis_str(0,1,"US2:");dis_shu(4,1,distance2); //超声波2距离显示
get_distance(3); //计算超声波3距离
dis_str(9,1,"US3:");dis_shu(13,1,distance3);//超声波3距离显示
}
}
全部资料链接见评论区,有问题请留言~
作者:amusen
时间:2022.4
祝好!
版权声明
本文为[锦官城外w]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_41740659/article/details/124329198
边栏推荐
- PyTorch 11.正则化
- [point cloud series] a rotation invariant framework for deep point cloud analysis
- 如何利用qemu搭建SOC protoype:80行代码实现一个Cortex M4 模拟器
- 【点云系列】Fully-Convolutional geometric features
- 直观理解 torch.nn.Unfold
- Write a wechat double open gadget to your girlfriend
- GIS实战应用案例100篇(三十四)-拼接2020globeland30
- PyTorch最佳实践和代码编写风格指南
- EMMC/SD学习小记
- Gee configuring local development environment
猜你喜欢
ARMCC/GCC下的stack protector
第2章 Pytorch基础1
【点云系列】DeepMapping: Unsupervised Map Estimation From Multiple Point Clouds
Systrace 解析
【点云系列】Relationship-based Point Cloud Completion
Chapter 2 pytoch foundation 2
Chapter 5 fundamentals of machine learning
WinForm scroll bar beautification
【51单片机交通灯仿真】
Raspberry Pie: two color LED lamp experiment
随机推荐
Pytorch模型保存与加载(示例)
PyTorch训练一个网络的基本流程5步法
PyTorch 10. 学习率
UEFI学习01-ARM AARCH64编译、ArmPlatformPriPeiCore(SEC)
【点云系列】PnP-3D: A Plug-and-Play for 3D Point Clouds
第2章 Pytorch基础2
【动态规划】三角形最小路径和
Chapter 5 fundamentals of machine learning
画 ArcFace 中的 margin 曲线
AUTOSAR从入门到精通100讲(八十一)-AUTOSAR基础篇之FiM
如何对多维矩阵进行标准化(基于numpy)
EasyUI combobox determines whether the input item exists in the drop-down list
[dynamic programming] triangle minimum path sum
直观理解 torch.nn.Unfold
图像分类白盒对抗攻击技术总结
AMBA协议学习小记
机器学习——PCA与LDA
pth 转 onnx 时出现的 gather、unsqueeze 等算子
【指标】Precision、Recall
如何利用qemu搭建SOC protoype:80行代码实现一个Cortex M4 模拟器