標(biāo)題:
超聲波測(cè)距用LED12864顯示
[打印本頁(yè)]
作者:
mmmjjjkk
時(shí)間:
2017-7-22 14:49
標(biāo)題:
超聲波測(cè)距用LED12864顯示
大神能幫我看看這個(gè)程序哪里有問(wèn)題,寫好后,12864不顯示.........
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit trig = P1^0;
sbit echo = P1^1;
sbit LCD_RS=P0^7;//寫指令/數(shù)據(jù)
sbit LCD_RW=P0^6;//讀狀態(tài)/寫
sbit LCD_EN=P0^5;//使能端
sbit LCD_PSB=P0^4;//串/并輸入
unsigned char disbuff[4]={0,0,0,0};//用于分別存放距離的值0.1mm、mm、cm和m的值
unsigned char code ASCII[13] = "0123456789.-M";
unsigned int time=0;//用于存放定時(shí)器時(shí)間值
unsigned long S=0;//用于存放距離的值
bit flag =0; //量程溢出標(biāo)志位
void delay(int i)
{
uchar j;
while(i--)
for(j=110;j>0;j--);
}
void LCD_busy()
{
LCD_RS=0;
LCD_RW=1;
LCD_EN=1;
P0=0xff;
while((P0&0x80)==0x80);
LCD_EN=0;
}
void LCD_wcmd(uchar cmd)
{
LCD_busy();
LCD_RS=0;
LCD_RW=0;
LCD_EN=1;
P0=cmd;
LCD_EN=0;
}
void LCD_wdat(uchar _data)
{
LCD_busy();
LCD_RS=1;
LCD_RW=0;
LCD_EN=1;
P0=_data;
/* delay(1); */
LCD_EN=0;
/* delay(1); */
}
void init()
{
LCD_RW=0;
LCD_PSB=1;//選擇為并行輸入
LCD_wcmd(0x30);//基本指令操作
LCD_wcmd(0x0c);//顯示開,關(guān)光標(biāo)
LCD_wcmd(0x06);//寫入一個(gè)字符,地址加1
LCD_wcmd(0x01);
}
void LCD_wstr(uchar *str)
{
while(*str)
{
LCD_wdat(*str);
delay(1);
str++;
}
}
void Delay10us(unsigned char i) //10us延時(shí)函數(shù) 啟動(dòng)超聲波模塊時(shí)使用
{
unsigned char j;
do{
j = 10;
do{
_nop_();
}while(--j);
}while(--i);
}
void StartModule() //???????
{
trig=1; //??????
Delay10us(2);
trig=0;
}
void Conut(void)
{
time=TH1*256+TL1;
TH1=0;
TL1=0;
S=time*0.17+10;
disbuff[0]=S%10;
disbuff[1]=S/10%10;
disbuff[2]=S/100%10;
disbuff[3]=S/1000;
LCD_wcmd(0x80);
LCD_wdat(ASCII[disbuff[3]]);
LCD_wdat(ASCII[disbuff[2]]);
LCD_wdat(ASCII[disbuff[1]]);
LCD_wdat(ASCII[10]);
LCD_wdat(ASCII[disbuff[0]]);
if(S<200)
{
LCD_wcmd(0x90);
LCD_wstr("低水位");
}
if(S<100)
{
LCD_wcmd(0x88);
LCD_wstr("高水位");
}
}
void Timer_Count(void)
{
TR1=1; //????
while(echo); //?RX?1?????
TR1=0; //????
Conut(); //??
}
void main()
{
init();
TMOD=TMOD|0x10;
EA=1; //?????
TH1=0;
TL1=0;
ET1=1; //??T0??
while(1)
{
echo=0;
StartModule(); //????
if(echo==1) Timer_Count();
//delay(500); //??????????????
}
}
作者:
cjjcjj1
時(shí)間:
2017-7-22 20:28
提示:
作者被禁止或刪除 內(nèi)容自動(dòng)屏蔽
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1