资源描述:
《汽车防撞系统设计材料》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、1.汽车防撞预警系统图2.protuse7.8软件仿真截图3.程序代码/***********************************************************************************************************///hc-sr04超声波测距模块DEMO程序//晶振:12Mhz//接线:模块TRIG接P1.2ECH0接P1.1//数码管:共阳数码管P2接数据口,P0.3P0.5P0.7接选通数码管/**********************************************************
2、*************************************************/#include//器件配置文件#include#definePROTEUS#defineRXP3_0#defineTXP3_1#defineBEEPP1_7unsignedintk;bitflag_beep;#ifndefPROTEUSunsignedinttime=0;bitflag=0;#elseunsignedlongtime=0;unsignedcharflag=0;#endifunsignedinttimer=0;unsignedc
3、harposit=0;unsignedlongS=0;Unsignedcharconstdiscode[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xBF,0xff/*-*/};unsignedcharconstpositon[3]={0xf7,0xdf,0x7f};//{0x08,0x20,0x80};unsignedchardisbuff[4]={0,0,0,0,};voiddelay(unsignedchari){while(i--);}voidDIDI(){if(S<100){k++;if(k>=10){k=0;f
4、lag_beep=!flag_beep;}}else{k++;if((S>=100)&&(S<200))//1m~2m{if(k>=20){k=0;flag_beep=!flag_beep;}}if((S>=200)&&(S<300))//2m~3m{if(k>=30){k=0;flag_beep=!flag_beep;}}if((S>=300)&&(S<400))//3m~4m{if(k>=40){k=0;flag_beep=!flag_beep;}}if((S>=400)&&(S<=500))//4m~5m{if(k>=50){k=0;flag_beep=!flag_beep;}}
5、}if(flag_beep)BEEP=1;elseBEEP=0;}/********************************************************/voidDisplay(void)//扫描数码管{//if(posit==0)//{//P2=(discode[disbuff[posit]])&0x7f;//}//else{P2=discode[disbuff[posit]];}P0=positon[posit];if(++posit>=3)posit=0;delay(100);//加这里是为了在proteus仿真P2=0xff;//加这里是为了在pro
6、teus仿真}/********************************************************/voidConut(void){#ifndefPROTEUStime=TH0*256+TL0;//不在PROTEUS仿真TH0=0;TL0=0;//time的单位是us//s=v(t/2)=340米/秒*(time/2)*秒=170*100cm/秒*time*秒=(time*1.7)/100cmS=(time*1.7)/100;//算出来是cmif((S>=700)
7、
8、flag==1)//超出测量范围显示“-”{flag=0;disbuff[0]=10;//
9、“-”disbuff[1]=10;//“-”disbuff[2]=10;//“-”}else{disbuff[0]=S%1000/100;disbuff[1]=S%1000%100/10;disbuff[2]=S%1000%10%10;}#elsetime=TH0*256+TL0;//在proteus下仿真用的,利用按钮作为超声波返回的信号TH0=0;TL0=0;time=time+flag*65536;S=(time*1.7)/1000;//