|
# include <reg52.h>
# define uchar unsigned char
# define uint unsigned int
sbit P_HC595_SER = P2^7; //pin 14 SER data input
sbit P_HC595_RCLK = P2^5; //pin 12 RCLk store (latch) clock
sbit P_HC595_SRCLK = P2^6; //pin 11 SRCLK Shift data clock
sbit lcden = P3^4;
sbit rs = P3^5;
sbit wr = P3^6;
sbit s5 = P3^0;
sbit s10 = P3^1;
sbit s15 = P3^2;
sbit s20 = P3^3;
uchar code dage[] = "2017-11-17 FRI";
uchar code dage1[] = " 23: 59: 39";
void init();
void delay(uint);
void write_com(uchar);
void write_date(uchar);
void Send_595(uchar);
void sfm(uchar, uchar);
void keyscan();
uchar i, miao, fen, shi, count, snum;
void main()
{
init();
for(i=0; i<16; i++)
{
write_date(dage[i]);
delay(5);
}
write_com(0x80+0x40);
for(i=0; i<13; i++)
{
write_date(dage1[i]);
delay(5);
}
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;
}
sfm(3, shi);
}
sfm(7, fen);
}
sfm(11, miao);
}
}
}
void init()
{
Send_595(0xff);
Send_595(0x00);
P_HC595_RCLK = 0;
P_HC595_RCLK = 1;
wr = 0;
lcden = 0;
shi = 23;
fen = 59;
miao = 39;
TMOD = 0x01;
TH0 = (65536-50000)/256;
TL0 = (65536-50000)%256;
EA = 1;
ET0 = 1;
TR0 = 1;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
}
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;
P0 = com;
delay(5);
lcden = 1;
delay(5);
lcden = 0;
}
void write_date(uchar date)
{
rs = 1;
P0 = date;
delay(5);
lcden = 1;
delay(5);
lcden = 0;
}
void Send_595(uchar dat)
{
uint i;
for(i=0; i<8; i++)
{
if(dat & 0x80) P_HC595_SER = 1;
else P_HC595_SER = 0;
P_HC595_SRCLK = 0;
P_HC595_SRCLK = 1;
dat = dat << 1;
}
}
void timer() interrupt 1
{
TH0 = (65536-50000)/256;
TL0 = (65536-50000)%256;
count++;
}
void 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(s5 == 0)
{
delay(5);
if(s5 == 0)
{
snum++;
while(!s5);
if(snum == 1)
{
TR0 = 0;
write_com(0x80+0x40+12);
write_com(0x0f);
}
if(snum == 2)
{
TR0 = 0;
write_com(0x80+0x40+8);
write_com(0x0f);
}
if(snum == 3)
{
TR0 = 0;
write_com(0x80+0x40+4);
write_com(0x0f);
}
if(snum == 4)
{
snum = 0;
write_com(0x0c);
TR0 = 1;
}
if(snum != 0)
{
if(s10 == 0)
{
delay(5);
if(s10 == 10)
{
while(!s10);
if(snum == 1)
{
miao++;
if(miao == 60)
miao = 0;
write_com(0x80+0x40+11);
sfm(11, miao);
}
}
}
}
}
}
}
|
|