標(biāo)題:
基于51的US100串口測距+12864液晶顯示
[打印本頁]
作者:
D0pe
時(shí)間:
2017-6-4 11:19
標(biāo)題:
基于51的US100串口測距+12864液晶顯示
應(yīng)用US-100超聲波模塊實(shí)現(xiàn) 串口精確定位的超聲波測距
0.png
(74.8 KB, 下載次數(shù): 40)
下載附件
2017-6-4 17:13 上傳
單片機(jī)源程序如下:
#include"main.h"
#include"LCD.h"
#include"uart.h"
uchar pos;//LCD顯示器文字位置
uchar Glen[2];//兩個(gè)八位距離接受數(shù)據(jù)
uchar distHL[4];//兩個(gè)八位距離最終數(shù)據(jù)
unsigned long dist=0;//十六位距離
uchar code table1[]={"當(dāng)前距離:"};
uchar code table2[]={"毫米"};
uchar code table3[]={"角度:"};
uchar code table4[]={"度"};
uchar code table5[]={"狀態(tài):"};
uchar code table6[]={"安全。"};
uchar code table7[]={"警報(bào)。"};
uchar code table8[]={"超出測量范圍!"};
void dispose_dist(unsigned long dist);
void main()
{
LCD_init();
UART_init();
display();
}
void delay(uchar z)
{
uchar x,y;
for(x=110;x>0;x--)
for(y=z;y>0;y--);
}
void time0() interrupt 1
{
uchar num=0;
TH0=(65536-2500)/256;
TL0=(65536-2500)%256;
num++;
if(num==100)//每25毫秒發(fā)送一次數(shù)據(jù)
{
num=0;
dist_UART();
}
}
void UART_recv() interrupt 4
{
uchar k=0;
ES=0;
if(RI)
{
RI=0;
Glen[k]=SBUF;
k++;
if(k==2)
k=0;
}
ES=1;
dist=Glen[0]*256+Glen[1];//實(shí)際距離公式
}
void display()
{
uchar i=0;
uchar j=0;
uchar k=0;
uchar n=0;
uchar m=0;
uchar n1=0;
uchar n2=0;
uchar n3=0;
//LCD第一行文字設(shè)置
pos=LCD_pos(0,0);
LCDwrite_cmd(pos);
while(table1[i]!='\0')
{
LCDwrite_dat(table1[i]);
i++;
}
//第二行距離單位顯示
pos=LCD_pos(5,1);
LCDwrite_cmd(pos);
while(table2[m]!='\0')
{
LCDwrite_dat(table2[m]);
m++;
}
//第四行狀態(tài)顯示
pos=LCD_pos(0,3);
LCDwrite_cmd(pos);
while(table5[n3]!='\0')
{
LCDwrite_dat(table5[n3]);
n3++;
}
//LCD第二行距離顯示
if(dist>4500)
{
pos=LCD_pos(0,1);
LCDwrite_cmd(pos);
while(table8[j]!='\0')
{
LCDwrite_dat(table8[j]);
j++;
}
//狀態(tài)文字顯示:警報(bào)
pos=LCD_pos(3,3);
LCDwrite_cmd(pos);
while(table7[n1]!='\0')
{
LCDwrite_dat(table7[n1]);
n1++;
}
}
else if(dist<=1000)
{
pos=LCD_pos(0,1);
LCDwrite_cmd(pos);
dispose_dist(dist);
for(k=0;k<4;k++)
{
LCDwrite_dat(distHL[k]);
k++;
}
//狀態(tài)文字顯示:警報(bào)
pos=LCD_pos(3,3);
LCDwrite_cmd(pos);
while(table7[n1]!='\0')
{
LCDwrite_dat(table7[n1]);
n1++;
}
//報(bào)警器設(shè)置
}
else
{
pos=LCD_pos(0,1);
LCDwrite_cmd(pos);
dispose_dist(dist);
for(k=0;k<4;k++)
{
LCDwrite_dat(distHL[k]);
k++;
……………………
…………限于本文篇幅 余下代碼請從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
基于51的US100串口測距 12864液晶顯示.zip
(45.21 KB, 下載次數(shù): 38)
2017-6-4 11:18 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1