大神能帮我看看这个程序哪里有问题,写好后,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;//写指令/数据
sbit LCD_RW=P0^6;//读状态/写
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);//显示开,关光标
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延时函数 启动超声波模块时使用
{
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); //??????????????
}
}
|