完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
|
相关推荐
4个回答
|
|
直接把内容发上来看看
|
|
|
|
#include #include #define Delay4us(){_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();} #define uint unsigned int //无符号16位 #define ulong unsigned long //无符号32位 #define uchar unsigned char //无符号8位 float soundspeed=340; void HCSR04_Install(); ***it PUL=P3^0; ***it DIR=P3^1; ***it ENA=P0^7; ***it flagled=P1^3; ***it S0=P3^5; // 上升按键 ***it S1=P3^3; // 下降按键 ***it S2=P3^2; // 超声解除 ***it S3=P3^6; // 上限位开关 ***it S4=P3^7; // 下限位开关 ***it trig1=P1^4;//超声波输入1 ***it echo1=P1^5;//超声波输出1 .......... ***it trig2=P1^6;//超声输入2 ***it echo2=P1^7; //超声输出2 ***it rs=P0^4; ***it rw=P0^3; ***it e=P0^2; sfr T2MOD=0xC9; uchar busyc,line,count,count1; uint value1,value2 ,q; uchar code table1[16]={"qwlinjianfen "}; uchar code table2[16]={"qwhello wd "}; uchar xdata DistanceText[]="Range1: ";//测量超模1#结果字符串 uchar xdata DistanceText2[]="Range2: ";//测量超模2#结果字符串 void DisplayDistanceValue(uint value); void Writecom(uchar dictate); void Writedata(uchar y); void Writeaddress(uchar x) ; void delayms(uint x); void delayus(uint m); uchar code Prompts[][16]; float xdata distancevalue1; float xdata diatancevalue2; float distance2(); float distance1() ; void write(uchar i ); void writedata(uchar i ); extern void LCD_1602install(); float measuredistance1(); float measuredistance2(); extern void lcd_displaystring(uchar *,uchar); uchar xdata stringBuf[6]; uchar xdata stringBuf1[6]; void LCD_Display_String(uchar *str, uchar LineNo); //UnsigedIntToString(value); uchar UnsigedIntToString(uint value); void time0() interrupt 0 /*外部中断0用于接下降按钮*/ { if(value1>=60) {delayms(240); count=count+1;} if(value1<60) {while(S0==0)q++; while(S0==1)q=0;} } void time1() interrupt 1 /*定时器0用于产生驱动脉冲*/ {TR0=0; TH0=(65536-1000)/256; TL0=(65536-1000)%256; TR0=1; PUL=~PUL; } void dingshi1()interrupt 3/*定时器1中断,用于超声测距*/ { } void time2() interrupt 5 { TF2=0; TR2=0; TH0=(65536-5000)/256; TL0=(65536-5000)%256; TR2=1; PUL=~PUL;} //1602显示部分// void delayms(uint x) {uint i,j; for(i=0;i } void delayus(uint m)/*us级延时*/ { uint i=0; while(m--) {i++; } } void delay(uchar n) { uchar x,y; for(x=n;x>0;x--) for(y=10;y>0;y--); } void busy(uchar busyc) { rs=0; rw=1; e=1; delay(10); busyc=P2^7; e=0; } void write_command(uchar command) { while(busyc); //判断LCD是否忙碌 rs=0; rw=0; e=1; P2=command; delay(10); e=0; } void write_date(uchar date) { while(busyc); //判断LCD是否忙碌 rs=1; rw=0; e=1; P2=date; delay(10); e=0; } void init() { count=0; e=0; write_command(0x38); delay(15); write_command(0x0c); delay(15); write_command(0x06); delay(15); write_command(0x01); } //将无符号的整数转成字符串,返回字符串长度 uchar UnsigedIntToString(uint value) { uchar i=0,t,length; //从个位开始转换 do { stringBuf[i]='0'+value%10; value=value/10; i++; }while(value!=0); length=i; //将字符串颠倒顺序 for(i=0;i<(length/2);i++) { t=stringBuf[i]; stringBuf[i]=stringBuf[length-i-1]; stringBuf[length-i-1]=t; } stringBuf[length]=' |