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; } }
附錄Ⅲ. 距離計(jì)算子程序 當(dāng)前溫度和超聲波往返時(shí)間均測(cè)量出來(lái)后,用 C 語(yǔ)言根據(jù)公式計(jì)算距離來(lái)編程是比較簡(jiǎn)單的算法。 其實(shí)現(xiàn)程序算法如下: #include<math.h> void distance(void) { double radical,dist,t; radical=sqrt(1+(temnum+273)/273); dist=165.7*t*radical; return(dist); }
|