再次写了一段关于1602LCD显示的程序,和上次一样仿真用的是lm016l,这次加了个定时器,让LCD显示时钟,不知道为什么又出问题,显示的时候有一段时间,比如从开始走到差不多40s的时候就出问题了,显示位数一位一位的少最后没了,心里那个郁闷啊,还有就是过了一段时间又恢复正常显示了,再过一段时间又消失了,如此反复,真气人,就是找不出病症,请各位帮帮忙看看吧!帮我指出问题所在,非常感谢了!以下是源程序。
#include<at89x51.h>
#include<intrins.h>
#define my_data P1
#define nop _nop_()
sbit E=P3^0;
sbit RW=P3^1;
sbit RS=P3^2;
void init(void);
void write(unsigned char command);
void writeDDR(unsigned char dat);
void check_busy(void);
void delay(unsigned int N);
unsigned int timecount,dispcount,second=0,minute=0,hour=12;
unsigned char dispbuf[6]={0x31,0x32,0x30,0x30,0x30,0x30};
void delay(unsigned int N)
{
unsigned int i;
for(i=0;i<N;i++)nop;
}
void init(void)
{
RS=0;
RW=0;
E=1;
write(0x38);
delay(1000);
write(0x38);
delay(1000);
write(0x38);
write(0x0c);
write(0x01);
write(0x0f);
write(0x06);
write(0x01);
delay(200);
}
void write(unsigned char tempdata)
{
my_data=tempdata;
RS=0;
RW=0;
E=0;
nop;
E=1;
nop;
E=0;
delay(100);
}
void writeDDR(unsigned char tempdata)
{
my_data=tempdata;
RS=1;
RW=0;
E=0;
nop;
E=1;
nop;
E=0;
delay(10);
}
void check_busy(void)
{
unsigned char temp;
my_data=0xff;
RW=1;
RS=0;
E=0;
nop;
E=1;
nop;
E=0;
do
{
nop;
temp=my_data;
}while((temp&0x80)==0x80);
RW=0;
}
void disp(void)
{
unsigned char i;
init();
write(0x84);
writeDDR(dispbuf[0]);
write(0x85);
writeDDR(dispbuf[1]);
write(0x86);
writeDDR(':');
write(0x87);
writeDDR(dispbuf[2]);
write(0x88);
writeDDR(dispbuf[3]);
write(0x89);
writeDDR(':');
write(0x8a);
writeDDR(dispbuf[4]);
write(0x8b);
writeDDR(dispbuf[5]);
delay(10);
}
void main(void)
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
ET0=EA=1;
TR0=1;
init();
while(1)disp();
}
void t0(void) interrupt 1 using 0
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
timecount++;
if(timecount==20)
{
timecount=0;
second++;
if(second==60)
{
second=0;
minute++;
if(minute==60)
{
minute=0;
hour++;
if(hour==24)hour=0;
}
}
}
dispbuf[0]=hour/10+0x30;
dispbuf[1]=hour%10+0x30;
dispbuf[2]=minute/10+0x30;
dispbuf[3]=minute%10+0x30;
dispbuf[4]=second/10+0x30;
dispbuf[5]=second%10+0x30;
} |