#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]="Hello! Baby!";
uchar table1[]="0123456789" ;
uint sec,min,hour,tt,num;
sbit RS=P3^1;
sbit LE=P3^0;
sbit k1=P3^4;
sbit k2=P3^5;
void delay(uint i)
{
while(i--);
}
void write_com(uchar com)
{
RS=0;
P0=com;
delay(50);
LE=1;
delay(50);
LE=0;
}
void write_data(uchar date)
{
RS=1;
P0=date;
delay(50);
LE=1;
delay(50);
LE=0;
}
void init()
{
LE=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
sec=00;
min=00;
hour=00;
}
void init1()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void diaplay()
{
write_com(0x80+2);
for(num=0;num<13;num++)
{
write_data(table[num]);
}
}
void diaplay1()
{
uchar i;
for(i=0;i<8;i++)
{
if(sec==60)
{
sec=0;
min++;
if(min==60)
{
min=0;
hour++;
if(hour==24)
{
hour=0;
}
}
}
}
write_com(0xc0+10);
write_data(table1[sec/10]);
write_com(0xc0+11);
write_data(table1[sec%10]);
write_com(0xc0+8);
write_data(':');
write_com(0xc0+6);
write_data(table1[min/10]);
write_data(table1[min%10]);
write_com(0xc0+4);
write_data(':');
write_com(0xc0+2);
write_data(table1[hour/10]);
write_data(table1[hour%10]);
}
void keyscan()
{
if(k1==0)
{
sce=0;
delay(10);
if(k1==0)
{
while(!k1);
min++;
if(min==60)
{
min=0;
}
}
}
if(k2==0)
{ sce=0;
delay(10);
if(k2==0)
{
while(!k2);
hour++;
if(hour==24)
{
hour=0;
}
}
}
}
void main()
{
init();
init1();
while(1)
{
diaplay();
diaplay1();
keyscan();
}
}
void time() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
tt++;
if(tt==20)
{
tt=0;
sec++;
}
}
|