大神能幫我看看這個程序哪里有問題,寫好后,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;//用于存放定時器時間值
unsigned long S=0;//用于存放距離的值
bit flag =0; //量程溢出標志位
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)光標
LCD_wcmd(0x06);//寫入一個字符,地址加1
LCD_wcmd(0x01);
}
void LCD_wstr(uchar *str)
{
while(*str)
{
LCD_wdat(*str);
delay(1);
str++;
}
}
void Delay10us(unsigned char i) //10us延時函數(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); //??????????????
}
}
|