- 1、本文档共4页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
超声波数码管显示_脉宽测量
数码管接线方式原理图:
超声波数码管显示 脉宽测量:
/***********************************************************************************************************/
//DYP-ME007 超声波测距模块 DEMO 程序
//晶振:11。0592
//接线:模块TRIG接 P0.2 ECH0 接P0.1
//数码管:共阳数码管P1接数据口,P2.5 P2.4 P2.3接选通数码管
/***********************************************************************************************************/
#include AT89x51.H //器件配置文件
#include intrins.h
#define RX P0_1
#define TX P0_2
unsigned int time=0;
unsigned int timer=0;
unsigned char posit=0;
unsigned long S=0;
bit flag =0;
unsigned char const discode[] ={ 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xBF,0xff/*-*/};
unsigned char const positon[3]={ 0xdf,0xef,0xf7};
unsigned char disbuff[4] ={ 0,0,0,0,};
/********************************************************/
void Display(void) //扫描数码管
{
if(posit==0)
{P1=(discode[disbuff[posit]])0x7f;}
else
{P1=discode[disbuff[posit]];}
P2=positon[posit];
if(++posit=3)
posit=0;
}
/********************************************************/
void Conut(void)
{
time=TH0*256+TL0;
TH0=0;
TL0=0;
S=(time*1.7)/100; //算出来是CM
if((S=700)||flag==1) //超出测量范围显示“-”
{
flag=0;
disbuff[0]=10; //“-”
disbuff[1]=10; //“-”
disbuff[2]=10; //“-”
}
else
{
disbuff[0]=S%1000/100;
disbuff[1]=S%1000%100/10;
disbuff[2]=S%1000%10 %10;
}
}
/********************************************************/
void zd0() interrupt 1 //T0中断用来计数器溢出,超过测距范围
{
flag=1; //中断溢出标志
}
/********************************************************/
void zd3() interrupt 3 //T1中断用来扫描数码管和计800MS启动模块
{
TH1=0xf8;
TL1=0x30;
Display();
timer++;
if(timer=400)
{
timer=0;
TX=1; //800MS 启动一次模块
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_
文档评论(0)