基于单片机AT89S52的超声波设计更新啦.docx

上传人:b****5 文档编号:11540559 上传时间:2023-03-19 格式:DOCX 页数:5 大小:24.75KB
下载 相关 举报
基于单片机AT89S52的超声波设计更新啦.docx_第1页
第1页 / 共5页
基于单片机AT89S52的超声波设计更新啦.docx_第2页
第2页 / 共5页
基于单片机AT89S52的超声波设计更新啦.docx_第3页
第3页 / 共5页
基于单片机AT89S52的超声波设计更新啦.docx_第4页
第4页 / 共5页
基于单片机AT89S52的超声波设计更新啦.docx_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

基于单片机AT89S52的超声波设计更新啦.docx

《基于单片机AT89S52的超声波设计更新啦.docx》由会员分享,可在线阅读,更多相关《基于单片机AT89S52的超声波设计更新啦.docx(5页珍藏版)》请在冰豆网上搜索。

基于单片机AT89S52的超声波设计更新啦.docx

基于单片机AT89S52的超声波设计更新啦

基于单片机AT89S52的超声波设计更新啦

2009年08月13日星期四10:

40

最近在做辆智能小车而其中有超声波测距这一模块,调了几天了还不行啊!

就是收不到啊

哪位有经验的大哥给我指点指点啊

没人帮忙也要解决啊

哈哈成功啦

下面是超声波模块程序

#include

#include

#defineucharunsignedchar

#defineuintunsignedint

#defineulongunsignedlong

uintc=340;

ulongl,time;

chari=1,j=1,k=80,aa;

chart,tp=10,ts,tg,lb,ls,lg,lsf,fh,cb,cs,cg;

sbitRW=P2^1;

sbitRS=P2^0;

sbitE=P2^2;

sbitrece=P3^3;

sbitk2=P1^1;

sbitk1=P1^0;

sbitk3=P1^2;

sbitk4=P1^3;

sbitsg=P3^7;

sbitctl=P3^5;

voiddelay(uinti)

{while(i--);

}

voidwritercom(ucharq)

{E=1;

RS=0;

RW=0;

P0=q;

E=0;

delay(20);

}

voidwriterdata(ucharo)

{

E=1;

RS=1;

RW=0;

P0=o;

E=0;

delay(20);

}

voidwriter_d(uchar*u)

{while(*u)

writerdata(*u++);

}

voidxsinit(void)

{writercom(0x01);

writercom(0x38);

writercom(0x0c);

writercom(0x06);

}

voidinptt()

{while

(1)

{if(k2==0){tp++;if(tp>=99)tp=99;}

delay(7000);

if(k1==0){tp--;if(tp<=(-30))tp=(-30);}

delay(7000);

t=tp;

if(t<0){fh=0x2d;t=~t+1;}

else{fh=0x20;}

ts=t/10;

tg=t%10;

writercom(0x80);

writer_d("   T:

");

writerdata(fh);

writerdata(ts+0x30);

writerdata(tg+0x30);

writerdata(0xdf);

writer_d("C");

writercom(0xba);

writer_d("PressK4finish");

if(k4==0)break;

}

}

voidsen()   

{uchartimes=0;

TMOD=0x12;  

IE=0x84;

TH0=244;

TL0=244;

TR0=1;

TR1=1;       

while

(1)

{while(TF0==0);

sg=~sg;

times++;   

TF0=0;  

if(times==20)break;}

TR0=0;

times=0;

}

rec()interrupt2using2

{TR1=0;           

ctl=0;

time=TH1*256+TL1;

l=time*c/2;

TH1=0;

TL1=0;

}

voiddataxs()

{if(tp>=10)c=338+(tp-10)*0.6;

elsec=338+(10-tp)*0.6;

cb=c/100;

cs=c%100/10;

cg=c%100%10;

lb=l/1000000;

ls=l%1000000/100000;

lg=l%1000000%100000/10000;

/******显示********/

writercom(0x80);

if(l<=360000)writer_d("toonear!

      ");

elseif(TH1>=93)writer_d("toolong!

      ");

else{writer_d("L=");

      writerdata('.');

      writerdata(ls+0x30);

      writerdata(lg+0x30);

      writer_d("m");     

      writer_d("c=");

      writerdata(cb+0x30);

      writerdata(cs+0x30);

      writerdata(cg+0x30);

      writer_d("m/s");

      }

}

voidunauto()

{while(i)

{while(k--)

{writercom(0xba);

  writer_d("PressK4measure");

  if(k4==0||k3==0){i=0;break;}

  delay(2000);}

  k=20;

while(k--)

{writercom(0xba);

  writer_d("               ");

  if(k4==0||k3==0){i=0;break;}

  delay(2000);}

  k=20;

}

i=1;

ctl=0;

sen();

delay(200);

ctl=1;

}

voidaut()

{writercom(0xba);

writer_d("realtimemeasur");

ctl=0;

sen();

delay(200);

ctl=1;

}

ztxz()

{while(k3==0&&aa==0)

{while

(1)

{if(k3==1)break;}

aa=1;

}

while(k3==0&&aa==1)

{while

(1)

{if(k3==1)break;}

aa=0;

}

}

main()

{xsinit();

inptt();

while

(1)

{while(!

aa)

{unauto();

  break;

}

while(aa)

{aut();

  break;

}

while(k--)

  delay(2000);

  }

  k=20;

dataxs();

}

}

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1