#include<reg52.h>
#include<intrins.h>
#include<stdio.h>
typedef unsigned int u8;
typedef unsigned char u16;
#define uchar unsigned char
#define uint unsigned int
#define SECOND 2000
uint count;
struct time{
uchar hour;
uchar min;
uchar sec;
};
struct time clocktime;
uchar dg[8]={0,0,16,0,0,16,0,0};
u8 code SEG[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x40};
void delay()
{
uint i;
for(i=0;i<500;i++);
}
void update(struct time dtime)
{
dg[0]=dtime.hour/10;
dg[1]=dtime.hour%10;
dg[3]=dtime.min/10;
dg[4]=dtime.min%10;
dg[6]=dtime.sec/10;
dg[7]=dtime.sec%10;
}
void timer0()interrupt 1 using 2
{
if(++count==SECOND)
{
count=0;
update(clocktime);
if(++clocktime.sec==60)
{
clocktime.sec=0;
if(++clocktime.min==60)
{
clocktime.min=0;
if(++clocktime.hour==24)
{
clocktime.hour=1;
}
}
}
}
|