使用的是QX-MINI51开发板,想做个LCD显示时钟程序,但卡在了光标闪烁这里为什么会有三个在闪烁??我试过把指针改成其它地址,也是不行,按下按键,一直都是最后那三个在闪烁,改了也没有变化。
求各位大神指点指点,本人初学者。
以下是程序:
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit rs=P2^0;
sbit rw=P2^1;
sbit lcden=P2^2;
sbit k1=P3^2;
sbit k2=P3^3;
sbit k3=P3^4;
sbit k4=P3^5;
uchar code table[]=" 2017/02/07 TUE";
uchar code table1[]=" 00:00:00";
uchar count,shi,fen,miao,k1num;
void delay(uchar x)
{
uint y;
for(;x>0;x--)
for(y=100;y>0;y--);
}
void write_com(uchar com)
{
rs=0;
rw=0;
lcden=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_data(uchar dat)
{
rs=1;
rw=0;
lcden=0;
P0=dat;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_sfm(uchar add,uchar dat)
{
uchar shi,ge;
shi=miao/10;
ge=miao%10;
write_com(0x80+0x40+add);
write_data(0x30+shi);
write_data(0x30+ge);
}
void init()
{
uchar num;
shi=0;
fen=0;
miao=0;
lcden=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(num=0;num<15;num++)
{
write_data(table[num]);
delay(5);
}
write_com(0x80+0x40);
for(num=0;num<12;num++)
{
write_data(table1[num]);
delay(5);
}
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void keyscan()
{
if(k1==0)
{
delay(5);
if(k1==0)
{
while(!k1);
TR0=0;
write_com(0x80+11);
write_com(0x0f);
}
}
}
void main()
{
init();
while(1)
{
keyscan();
if(count==20)
{
count=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
shi=0;
write_sfm(4,shi);
}
write_sfm(7,fen);
}
}
write_sfm(10,miao);
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
}
|