標題: 基于51單片機的超聲波液位檢測設計 [打印本頁]
作者: 高字揚 時間: 2018-5-19 11:09
標題: 基于51單片機的超聲波液位檢測設計
sbit send=P1^0;
void timer0(void)interrupt 1
{ send=!send;
TH0=0x1f;
TL0=0xf4;
}
超聲波接收(外部中斷 1)程序: void int1(void)interrupt 2
{ if(TH1!=0x00&&TH0!=0x00)
{ b=1;
TR1=0;
TR0=0;
t=TH1*256+TL1;
t=t/1000000;
TH0=0x1f;
TL0=0xf4;
TH1=0x00;
TL1=0x00;
}
else
{ b=0;
TR1=0;
TR0=0;
TH0=0x1f;
TL0=0xf4;
TH1=0x00;
TL1=0x00;
} }
附錄Ⅲ. 距離計算子程序
當前溫度和超聲波往返時間均測量出來后,用 C 語言根據公式計算距離來編程是比較簡單的算法。
其實現程序算法如下: #include<math.h> void distance(void)
{
double radical,dist,t; radical=sqrt(1+(temnum+273)/273); dist=165.7*t*radical; return(dist);
}
| 歡迎光臨 (http://www.raoushi.com/bbs/) |
Powered by Discuz! X3.1 |