基于AT89C51的電子時鐘
#include
#include
#define uchar unsigned char
#define uint unsigned int
sbit MG=P1^0;
sbit MS=P1^1;
sbit MM=P1^2;
sbit HG=P1^3;
sbit HS=P1^4;
sbit SD=P1^5;
bit shan;
code uchar NUM[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar sec,min,hour;
uchar hour1;
void delay(uint a)
{
while(a--);
}
void init0 ()
{
TMOD=0x01;
TL0=0xb0;
TH0=0x3c;
TR0=1;
EA=1;
ET0=1;
}
void display_time()
{
P0=NUM[min%10];
MG=1;
delay(300);
P1=0x00;
#include
#define uchar unsigned char
#define uint unsigned int
sbit MG=P1^0;
sbit MS=P1^1;
sbit MM=P1^2;
sbit HG=P1^3;
sbit HS=P1^4;
sbit SD=P1^5;
bit shan;
code uchar NUM[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar sec,min,hour;
uchar hour1;
void delay(uint a)
{
while(a--);
}
void init0 ()
{
TMOD=0x01;
TL0=0xb0;
TH0=0x3c;
TR0=1;
EA=1;
ET0=1;
}
void display_time()
{
P0=NUM[min%10];
MG=1;
delay(300);
P1=0x00;
P0=NUM[min/10];
MS=1;
delay(300);
P1=0x00;
MS=1;
delay(300);
P1=0x00;
P0=0xbf;
MM=shan;
delay(300);
P1=0x00;
if(hour>12)
{
hour1=hour-12;
}
else
{
hour1=hour;
}
MM=shan;
delay(300);
P1=0x00;
if(hour>12)
{
hour1=hour-12;
}
else
{
hour1=hour;
}
P0=NUM[hour1%10];
HG=1;
delay(300);
P1=0x00;
HG=1;
delay(300);
P1=0x00;
P0=NUM[hour1/10];
HS=1;
delay(300);
P1=0x00;
HS=1;
delay(300);
P1=0x00;
if(hour>=12)
{
P0=0x8c;
SD=1;
delay(300) ;
P1=0x00;
}
{
P0=0x8c;
SD=1;
delay(300) ;
P1=0x00;
}
else
{
P0=0x88;
SD=1;
delay(300);
P1=0x00;
}
}
void FT()
{
while(P3==0xfe)
display_time();
sec=0;
min++;
if(min==60)
min=0;
}
void ST()
{
while(P3==0xfd)
display_time();
hour++;
if(hour==24)
hour=0;
}
main()
{
init0();
hour=1;
while(1)
{
display_time();
if(P3==0xfe) FT();
if(P3==0xfd) ST();
}
}
{
P0=0x88;
SD=1;
delay(300);
P1=0x00;
}
}
void FT()
{
while(P3==0xfe)
display_time();
sec=0;
min++;
if(min==60)
min=0;
}
void ST()
{
while(P3==0xfd)
display_time();
hour++;
if(hour==24)
hour=0;
}
main()
{
init0();
hour=1;
while(1)
{
display_time();
if(P3==0xfe) FT();
if(P3==0xfd) ST();
}
}
關鍵詞:
AT89C51電子時
評論