新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > 单片机超声波测距程序

单片机超声波测距程序

作者: 时间:2016-12-01 来源:网络 收藏
单片机超声模块说明(HC-SR04)





本文引用地址:https://www.eepw.com.cn/article/201612/324413.htm
P10,P11,P12为位选,采用共阳数码管显示。精确到CM级别。tring为发射控制,本程序定义为P20引脚。 echo接外部中断0.
#include
sbit wei_ge=P1^0;
sbit wei_shi=P1^1;
sbit wei_bai=P1^2;


sbit a=P2^3;
#define uchar unsigned char
#define uint unsigned int
int time;
int succeed_flag;
uchar timeL;
uchar timeH;
sbit Trig=P2^0;
sbit Echo=P3^2;
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void delay_20us()
{
uchar a ;
for(a=0;a<100;a++);
}
//显示数据转换程序
void display(uint temp)
{
uchar ge,shi,bai;
bai=temp/100;
shi=(temp%100)/10;
ge=temp%10;
P0=table[ge]; //送数字8到段码端口
wei_ge=0;
delay(5);

上一页 1 2 下一页

关键词: 单片机超声波测

评论


技术专区

关闭