#include <AT89X52.H>
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0x00};
unsigned char dispbitcode[]={0xfe,0xfd,0xfb,0xf7,
0xef,0xdf,0xbf,0x7f};
unsigned char dispbuf[8]={0,0,16,0,0,16,2,1};
unsigned char dispbitcnt;
unsigned char second;
unsigned char minute;
unsigned char hour;
unsigned int tcnt;
unsigned char mstcnt;
unsigned char i,j;
void delay();
void main(void)
{
TMOD=0x02;
TH0=0x06;
TL0=0x06;
TR0=1;
ET0=1;
EA=1;
hour=12;
while(1)
{
if(P3_0==0)
{
TR0=~TR0;
while(P3_0==0);
}
if(P3_1==0)
{
for(i=5;i>0;i--)
for(j=248;j>0;j--);
if(P3_1==0)
{
minute++;
if(minute==60)
{
minute=0;
}
dispbuf[3]=minute%10;
dispbuf[4]=minute/10;
while(P3_1==0);
}
}
if(P3_2==0)
{
for(i=5;i>0;i--)
for(j=248;j>0;j--);
if(P3_2==0)
{
hour++;
if(hour==24)
{
hour=0;
}
dispbuf[6]=hour%10;
dispbuf[7]=hour/10;
while(P3_2==0);
}
}
}
}
void int0(void) interrupt 1 using 0
{
mstcnt++;
if(mstcnt==8)
{
mstcnt=0;
P2=0xff; //关闭所有显示
P0=dispcode[dispbuf[dispbitcnt]];
P2=dispbitcode[dispbitcnt];
dispbitcnt++;
if(dispbitcnt==8)
{
dispbitcnt=0;
}
}
tcnt++;
if(tcnt==4000)
{
tcnt=0;
second++;
if(second==60)
{
second=0;
minute++;
if(minute==60)
{
minute=0;
hour++;
if(hour==24)
{
hour=0;
}
}
}
dispbuf[0]=second%10;
dispbuf[1]=second/10;
dispbuf[3]=minute%10;
dispbuf[4]=minute/10;
dispbuf[6]=hour%10;
dispbuf[7]=hour/10;
}
}
-
一周热门 更多>