基于单片机的超声波测距系统设计实验报告 - 重(19)

发布时间:2021-06-11

基于单片机的超声波测距系统设计实验报告,课程设计

附录二:系统软件源代码

/*

*************************************************** *课设名称:基于51单片机的超声波测距系统设计 *硬件平台: 超声波模块+51最小系统 *显示模块:4个数码管 *输入模块:3个按键

*实现的功能:用超声波模块把距离测量出来,用数码管显示,可通过按键设置要报警的距离,低于设置

* 的值则自动报警,一直按住调值的键会越加越快,超出量程(3.8m)则显示888 *接口说明:数码管位P3^4 P3^5 P3^6 P3^7 * 超声波发射=>P3^2 * 超声波接收=>P3^3 按键用的接口是P2口 *待改进的地方:温度补偿,提高精度 *当前的缺陷: 不能测出4m的距离 *测量单位:米(m)

****************************************************/

#include <reg52.h> #include <intrins.h> #include <string.h> #include <eepom52.h>

#define uchar unsigned char #define uint unsigned int

//数码管段选定义 设 0 1 2 3 4 5 6 7 8 9 uchar code smg_duan[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};

//数码管位选

uchar dis_smg[4] ={0,1,2,3};

sbit smg_we1 = P3^4; //数码管位选端口 sbit smg_we2 = P3^5; sbit smg_we3 = P3^6; sbit smg_we4 = P3^7; sbit c_send = P3^1; //超声波发射 sbit c_recive = P3^0; //超声波接收 uchar flag_hc_value; //超声波中间变量

sbit beep = P2^3; //蜂鸣器IO口定义

精彩图片

热门精选

大家正在看