#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit en=P3^4;
sbit rs=P3^5;
sbit rd=P3^7;
sbit s4=P3^6;
uchar fen,miao,s4num,count,mm;
uchar code table[]=" 00:00:00 ";
void delay(uint z)//ÑÓʱº¯Êý
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(uchar com)
{
rs=0;
en=0;
P0=com;
delay(1);
en=1;
delay(1);
en=0;
}
void write_data(uchar date)
{
rs=1;
en=0;
P0=date;
delay(1);
en=1;
delay(1);
en=0;
}
void init()//³õʼ»¯
{
uchar num;
fen=00;
miao=00;
mm=00;
write_com(0x38);
delay(1);
write_com(0x38);
delay(1);
write_com(0x0c);
write_com(0x06);
write_com(0x80+0x40);
for(num=0;num<12;num++)
{
write_data(table[num]);
delay(1);
}
TMOD=0x10;
TH1=(65536-10000)/256;
TL1=(65536-10000)%256;
EA=1;
ET1=1;
TR1=0;
}
void write_jishi(uchar add,uchar date)
{
uchar shi,ge;
shi=date/10;
ge=date%10;
write_com(0x80+0x40+add);
write_data(0x30+shi);
write_data(0x30+ge);
}
void keyscan()
{
rd=0;
if(s4==0)
{
delay(1);
if(s4==0)
{
s4num++;
while(!s4);
if(s4num==1)
{
TR1=1;
mm++;
if(mm==100)
{
mm=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
TR1=0;
}
write_jishi(4,fen);
write_com(0x80+0x40+5);
}
write_jishi(7,miao);
write_com(0x80+0x40+8);
}
write_jishi(10,mm);
write_com(0x80+0x40+11);
}
if(s4num==2)
{
TR1=0;
}
if(s4num==3)
{
s4num=0;
write_com(0x0c);
init();
}
}
}
}
void main()
{
init();
while(1)
{
keyscan();
}
}
void timer0() interrupt 3
{
TH1=(65536-10000)/256;
TL1=(65536-10000)%256;
count++;
if(count!=0)
{
mm++;
if(mm==100)
{
mm=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
TR1=0;
}
write_jishi(4,fen);
}
write_jishi(7,miao);
}
write_jishi(10,mm);
}
}
|