基于89S52用键盘调节1602液晶光标位置的的C程序哪错了,高手请进!
这是一个的用定时器计时的程序,为什么光标的位置调不了?高手请看下是程序的问题还是我液晶的问题,还请下载到自己的板子试试再回答,谢谢!!!#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit RS=P2^5;
sbit RW=P2^6;
sbit E=P2^7;
sbit s1=P3^2; //一个独立按键
uchar num,count,shi,fen,miao,s1num,flag;
uchar code table[]=" 2007-7-10 MOD" ;
uchar code table1[]=" 00:00:00 ";
void write_sfm(uchar ,uchar );
void delay(uchar del)//延期时
{
int i,j;
for(i=0; i<=del; i++)
for(j=0; j<=2; j++)
;
}
void write_com(uchar com) //液晶写命令
{
RS=0;
P0=com;
delay(5);
E=1;
delay(5);
E=0;
}
void write_date(uchar date) //液晶写数据
{
RS=1;
P0=date;
delay(5);
E=1;
delay(5);
E=0;
}
void init()
{
RW=0;
E=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
write_com(0x02);
for(num=0;num<15;num++)
{
write_date(table[num]);
delay(5);
}
write_com(0x80+0x40);
for(num=0;num<16;num++)
{
write_date(table1[num]);
delay(5);
}
TMOD=0x01; //定时器初始化
TH0=(65536-50000)%256;
TL0=(65536-50000)/256;
EA=1;
ET0=1;
TR0=1;
}
void time0() interrupt 1
{
TH0=(65536-50000)%256;
TL0=(65536-50000)/256;
count++;
}
void write_sfm(uchar add,uchar date ) //写入时分秒
{
uchar shi,ge;
shi=date/10;
ge=date%10;
write_com(0x80+0x40+add);
write_date(0x30+shi);
write_date(0x30+ge);
}
void keyscan() //键盘扫描程序
{
if(s1=0)
{
delay(5);
if(s1==0)
{
while(!s1);
s1num++;
if(s1num==1)
{
TR0=0;
write_com(0x80+0x40+10);
write_com(0x0f);
}
if(s1num==2)
{
write_com(0x80+0x40+7);
}
if(s1num==3)
{
write_com(0x80+0x40+4);
}
if(s1num==4)
{
TR0=1;
write_com(0x0c);
}
}
}
}
void main()
{
init();
while(1)
{
keyscan();
if(count==40)
{
count=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
shi=0;
write_sfm(2,shi);
}
write_sfm(6,fen);
}
}
write_sfm(9,miao);
}
}