汽车防撞系统设计材料.doc_第1页
汽车防撞系统设计材料.doc_第2页
汽车防撞系统设计材料.doc_第3页
汽车防撞系统设计材料.doc_第4页
汽车防撞系统设计材料.doc_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1.汽车防撞预警系统图2. protuse7.8软件仿真截图3.程序代码/*/hc-sr04 超声波测距模块 demo 程序/晶振:12mhz/接线:模块trig接 p1.2 ech0 接p1.1/数码管:共阳数码管p2接数据口,p0.3 p0.5 p0.7接选通数码管/*/ #include /器件配置文件#include #define proteus#define rx p3_0#define tx p3_1#define beep p1_7unsigned int k;bit flag_beep;#ifndef proteusunsigned int time=0;bit flag =0;#elseunsigned long time=0;unsigned char flag =0;#endifunsigned int timer=0;unsigned char posit=0;unsigned long s=0;unsigned char const discode = 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff/*-*/;unsigned char const positon3= 0xf7,0xdf,0x7f;/ 0x08,0x20,0x80;unsigned char disbuff4 = 0,0,0,0,;void delay(unsigned char i)while(i-);void didi() if(s=10) k=0; flag_beep=!flag_beep; else k+;if(s=100)&(s=20) k=0; flag_beep=!flag_beep; if(s=200)&(s=30) k=0; flag_beep=!flag_beep; if(s=300)&(s=40) k=0; flag_beep=!flag_beep; if(s=400)&(s=50) k=0; flag_beep=!flag_beep; if(flag_beep) beep=1;else beep=0;/*/void display(void) /扫描数码管/if(posit=0)/p2=(discodedisbuffposit)&0x7f;/else p2=discodedisbuffposit;p0=positonposit;if(+posit=3)posit=0;delay(100);/加这里是为了在proteus仿真p2=0xff; /加这里是为了在proteus仿真/*/void conut(void)#ifndef proteustime=th0*256+tl0;/不在proteus仿真th0=0;tl0=0;/time的单位是us /s=v(t/2)=340米/秒 * (time/2)* 秒 = 170*100cm/秒 * time *秒=(time*1.7)/100 cms=(time*1.7)/100; /算出来是cmif(s=700)|flag=1) /超出测量范围显示“-” flag=0;disbuff0=10; /“-”disbuff1=10; /“-”disbuff2=10; /“-”elsedisbuff0=s%1000/100;disbuff1=s%1000%100/10;disbuff2=s%1000%10 %10;#elsetime=th0*256+tl0;/在proteus下仿真用的,利用按钮作为超声波返回的信号th0=0;tl0=0;time = time+flag*65536;s=(time*1.7)/1000; /算出来是dm 分米if(s=700) /超出测量范围显示“-” flag=0;disbuff0=10; /“-”disbuff1=10; /“-”disbuff2=10; /“-”elseflag = 0;disbuff0=s%1000/100;disbuff1=s%1000%100/10;disbuff2=s%1000%10 %10;#endif/*/void zd0() interrupt 1 /t0中断用来计数器溢出,超过测距范围#ifndef proteus flag=1; /中断溢出标志#else flag+;#endif/*/void zd3() interrupt 3 /t1中断用来扫描数码管和计800ms启动模块th1=0xf8;tl1=0x30;display();didi();timer+;if(timer=400)timer=0;tx=1; /800ms 启动一次模块_nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();_nop_(); _nop_(); _nop_(); _nop_();tx=0; /*/void main( void ) tmod=0x11; /设t0为方式1,gate=1;th0=0;tl0=0; th1=0xf8; /2ms定时tl1=0x30;et0=1; /允许t0中断et1=1; /允许t1中断tr1=1; /开

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论