当前位置:网站首页>基于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
边栏推荐
猜你喜欢

imx6ull-qemu 裸机教程2:USDHC SD卡
![[3D shape reconstruction series] implicit functions in feature space for 3D shape reconstruction and completion](/img/4d/6d5821759766a6bf1d77ad51b69e24.png)
[3D shape reconstruction series] implicit functions in feature space for 3D shape reconstruction and completion

Pymysql connection database

【51单片机交通灯仿真】

【点云系列】Neural Opacity Point Cloud(NOPC)

免费使用OriginPro学习版
![[point cloud series] sg-gan: advantageous self attention GCN for point cloud topological parts generation](/img/1d/92aa044130d8bd86b9ea6c57dc8305.png)
[point cloud series] sg-gan: advantageous self attention GCN for point cloud topological parts generation

MySQL installation and configuration - detailed tutorial

Device Tree 详解

MySQL的安装与配置——详细教程
随机推荐
Pytorch trains the basic process of a network in five steps
【点云系列】点云隐式表达相关论文概要
PyTorch中的一些常见数据类型转换方法,与list和np.ndarray的转换方法
Paddleocr image text extraction
. net encountered failed to decode downloaded font while loading font:
torch_geometric学习一,MessagePassing
scons 搭建嵌入式arm编译
[3D shape reconstruction series] implicit functions in feature space for 3D shape reconstruction and completion
Keras如何保存、加载Keras模型
AUTOSAR从入门到精通100讲(五十二)-诊断和通信管理功能单元
画 ArcFace 中的 margin 曲线
PyTorch 18. torch.backends.cudnn
Device Tree 详解
第4章 Pytorch数据处理工具箱
【動態規劃】不同路徑2
【点云系列】SG-GAN: Adversarial Self-Attention GCN for Point Cloud Topological Parts Generation
PyMySQL连接数据库
机器学习——模型优化
F.pad 的妙用
ArcGIS license server administrator cannot start the workaround