那位大佬帮忙看看,这1602读数为啥不行啊,#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit RS=P2^6;
sbit RW=P2^5;
sbit EN=P2^7;
uchar t, i;
void delay(uint z)
{
uint x,y;
for(x = z; x > 0; x–)
for(y = 114; y > 0 ; y–);
}
//判断液晶忙不忙,忙则等待 、
void read_busy()
{
uchar busy;
P0=0xff; //给与高电位
RS=0; //1 数据 0命令
RW=1; //1 读 0写
do
{
EN=1; //使能
busy=P0;
EN=0;
}while(busy &0x80);
}
//1602命令
void write_cmd(uint cmd)
{
read_busy();
RS=0;
RW=0;
P0=cmd;
EN=1;
EN=0;
}
//1602 数据
void write_dat(uint dat)
{
read_busy();
RS=1;
RW=0;
P0=dat;
EN=1;
EN=0;
}
void timer_init()
{
TMOD|=0X01;//选择为定时器0模式,工作方式1,仅用TR0打开启动。
TH0=0XFC; //给定时器赋初值,定时1ms
TL0=0X68;
ET0=1;//打开定时器0中断允许
EA=1;//打开总中断
TR0=1;//打开定时器
}
void main()
{
timer_init();
write_cmd(0x38);//设置16*2显示
write_cmd(0x0f); //开显示
write_cmd(0x06); //指针地址右加一 0x04左
// write_cmd(0x01); //清屏
write_cmd(0x80|0x06 ); //显示地址
write_cmd(0x01); //清屏
while(1);
{
if(t<1000)
{
write_cmd(0x80 | 0x06);
write_dat(t/10+’0′);
//显示十位数字
write_cmd(0x80 | 0x07);
//显示个位数字
write_dat(t%10+’0′);
}
}
}
void Timer0() interrupt 1
{
TH0=0XFC; //给定时器赋初值,定时1ms
TL0=0X68;
i++;
if(i==1000)
{
i=0;
t++;
}
}