資源描述:
《超聲波測距源程序》由會員上傳分享,免費在線閱讀,更多相關內(nèi)容在工程資料-天天文庫。
1、超聲波測距源程序Yourbuffer[]isanarray,soyouusePl=^buffertomeanthepointertothisarrayIfyouwanttosenddatafrombuffertoPl.,thatshouldbethecasePl=^buffer[0]://====//Thefollowingisyoursourceprogram//////===========////at89c2051producedultrasonicrangingsourcettincludettdefineKIP34#definecsbou
2、tP3_5//ultrasonictransmission#definecsbintP37//ultrasonicreceiver#definecsbc=0.034ttdefineBGP3_3Unsignedcharcsbds,opto,digit,buffer[3],xml,XM2,xmO,key,jpjs;//displayidentificationUnsigned,char,convert[10]={0x3F,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f},//0、9segmentcodeUnsigned,int,s,
3、t,I,XX,J,SJ1,sj2,SX1,SJ3,mqs;Bitcl;Void,csbcj();Voiddelay(J);//delayfunctionVoid(scanLED);//displayfunctionVoid(timeToBuffer);//displayconversionfunctionVoid,keyscan();Void,klcl0;Void,K2C10;Void,k3cl0;Void,k4cl0;Void,offmsd();Void(main)/mainfunctionEA二1;//openinterruptTM0D二0x11;//setthet
4、imer0count,setthetimer1timerETO二1;//timer0interruptenableET1二1;//timer1interruptenableTHO二0x00;TLO二0x00;TH1二0x9E;TL1二0x57;Csbds二0;Csbint二1;Csbout二1;Cl二0;Opto二Oxff;Jpjs=O;Sjl二45;Sj2=200;Sj3=400;K4cl();TRI二1;While(1){Keyscan();If(jpjssj3){Buffer[2]=0x76;Buffer[l]=0x76;Buff
5、er[0]=0x76;Elseif(s6、enumberPl=^buffer;//displaydatadeliveryportPlDelay(20);//delayprocessingPl二Oxff;//Plporthigh(off)If((P3&0xl0)=0//3)tojudgewhethertodisplay.Key=0;Digit>>=l;//rotateright1Void(timeToBuffer)//codeconversionfunctionmoduleXmO二s/100;Xml二(s-100*xni0)/IO;Xm2二sT00*xin0-10*xml;Buffer[2]=convert[xm
7、2];Buffer[l]=convert[xml];Buffer[0]=convert[xmO];}Voiddelay(I){Wh訂e(—i);}Voidtimerlint(void)interrupt3using2THl=0x9E;TLl=0x57;Csbds++;If(csbds>=40){Csbds二0;Cl=l;}Void,csbcj(){If(cl=l){TR1=O;THO二0x00;TL0=0x00;1=10;Wh訂e(1—)Csbout二!Csbout;}TRO二1;I二mqs;//blindWh訂e(i—){}I二0;Wh