資源描述:
《汽車防撞系統(tǒng)設(shè)計材料》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、1.汽車防撞預(yù)警系統(tǒng)圖2.protuse7.8軟件仿真截圖3.程序代碼/***********************************************************************************************************///hc-sr04超聲波測距模塊DEMO程序//晶振:12Mhz//接線:模塊TRIG接P1.2ECH0接P1.1//數(shù)碼管:共陽數(shù)碼管P2接數(shù)據(jù)口,P0.3P0.5P0.7接選通數(shù)碼管/**********************
2、*************************************************************************************/#include//器件配置文件#include#definePROTEUS#defineRXP3_0#defineTXP3_1#defineBEEPP1_7unsignedintk;bitflag_beep;#ifndefPROTEUSunsignedinttime=0;bitflag=0;#else
3、unsignedlongtime=0;unsignedcharflag=0;#endifunsignedinttimer=0;unsignedcharposit=0;unsignedlongS=0;Unsignedcharconstdiscode[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xBF,0xff/*-*/};unsignedcharconstpositon[3]={0xf7,0xdf,0x7f};//{0x08,0x20,0x80};uns
4、ignedchardisbuff[4]={0,0,0,0,};voiddelay(unsignedchari){while(i--);}voidDIDI(){if(S<100){k++;if(k>=10){k=0;flag_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=!f
5、lag_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;}}}if(flag_beep)BEEP=1;elseBEEP=0;}/********************************************************/voidDisplay(void)//掃描數(shù)碼管{
6、//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;//加這里是為了在proteus仿真}/********************************************************/voidConut(void)
7、{#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)
8、
9、flag==1)//超出測量范圍顯示“-”{flag=0;disbuff[0]=10;//“-”disbuff[1]=10;//“-”disbuff[2]=10;//“-”}el
10、se{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;//