這是一款單片機(jī)超聲波測(cè)距原理圖,這款單片機(jī)超聲波測(cè)距板電路簡(jiǎn)單,制作容易,無(wú)需進(jìn)行調(diào)試,電路焊焊接好后,下裝程序后即可工作。
本文引用地址:http://butianyuan.cn/article/201611/321765.htm
#include
#define csboutP3_5//超聲波發(fā)送
#define csbintP3_7 //超聲波接收
#define csbc=0.034
#define bgP3_4
unsigned char csbds,opto,digit,buffer[3],xm1,xm2,xm0,key,jpjs,ki;//顯示標(biāo)識(shí)
unsigned char convert[10]={0x3F,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//0~9段碼
unsigned int s,t,i,sj1,sj2,sj3,mqs,sx1,sjtz,sja,sjb;
bit cl;
void csbcj();
void delay(i);//延時(shí)函數(shù)
void scanLED();//顯示函數(shù)
void showOnce();//顯示循環(huán)函數(shù)
void timeToBuffer();//顯示轉(zhuǎn)換函數(shù)
void offmsd();
void main()//主函數(shù)
{
EA=1;//開(kāi)中斷
TMOD=0x11; //設(shè)定時(shí)器0為計(jì)數(shù),設(shè)定時(shí)器1定時(shí)
ET0=1; //定時(shí)器0中斷允許
ET1=1; //定時(shí)器1中斷允許
TH0=0x00;
TL0=0x00;
TH1=0x9E;
TL1=0x57;
csbds=0;
csbint=1;
csbout=1;
cl=0;
opto=0xff;
sj1=40;
sj2=100;
sj3=150;
ki=0;
TR1=1; //設(shè)定時(shí)值1為20ms
while(1)
{
csbcj();//調(diào)用超聲波測(cè)距程序
if(s>sj3)//大于時(shí)顯示"CCC"
{
buffer[2]=0x39;
buffer[1]=0x39;
buffer[0]=0x39;
}
else if(s//小于時(shí)顯示"- - -"
{
buffer[2]=0x40;
buffer[1]=0x40;
buffer[0]=0x40;
}
else timeToBuffer();//調(diào)用轉(zhuǎn)換段碼功能模塊
offmsd();//調(diào)用判斷百位數(shù)為零模塊,百位為零時(shí)不顯示
scanLED();//調(diào)用顯示函數(shù)
}
}
評(píng)論