基本信息
源码名称:超声波测距(LCD1602显示)
源码大小:2.44KB
文件格式:.c
开发语言:C/C++
更新时间:2019-08-05
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
include<reg51.h> #include<intrins.h> #include"lcd.h" sbit Trig = P2^1; sbit Echo = P2^0; unsigned char PuZh[]=" Pechin Science "; unsigned char code ASCII[15] = {'0','1','2','3','4','5','6','7','8','9','.','-','M'}; static unsigned char DisNum = 0; //显示用指针 unsigned int time=0; unsigned long S=0; bit flag =0; unsigned char disbuff[4] ={ 0,0,0,0,}; /******************************************************************************* * 函 数 名 : main * 函数功能 : 主函数 * 输 入 : 无 * 输 出 : 无 *******************************************************************************/ void Conut(void) { time=TH0*256 TL0; TH0=0; TL0=0; S=(time*1.7)/100; //算出来是CM if((S>=700)||flag==1) //超出测量范围显示“-” { flag=0; DisplayOneChar(0, 1, ASCII[11]); DisplayOneChar(1, 1, ASCII[10]); //显示点 DisplayOneChar(2, 1, ASCII[11]); DisplayOneChar(3, 1, ASCII[11]); DisplayOneChar(4, 1, ASCII[12]); //显示M } else { disbuff[0]=S%1000/100; disbuff[1]=S%1000%100/10; disbuff[2]=S%1000%10 %10; DisplayOneChar(0, 1, ASCII[disbuff[0]]); DisplayOneChar(1, 1, ASCII[10]); //显示点 DisplayOneChar(2, 1, ASCII[disbuff[1]]); DisplayOneChar(3, 1, ASCII[disbuff[2]]); DisplayOneChar(4, 1, ASCII[12]); //显示M } } void zd0() interrupt 1 //T0中断用来计数器溢出,超过测距范围 { flag=1; //中断溢出标志 }