#include <reg52.h>
#define uint unsigned int
sbit P3_0=P3^0;
sbit K1=P3^2;
sbit K2=P3^3;
sbit K3=P3^4;
sbit K4=P3^5;
uint count,min,hour,miao,i,j=0;
uint code tab1[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uint code tab2[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};
uint code tab3[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xff,
0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xff,0x00,0xff,0x00,0xff,
0xfe,0xfb,0xef,0xbf,0xfd,0xf7,0xdf,0x7f,0x7e,0x3c,0x18,0x00,0x81,
0xc3,0xe7,0xff,0xe7,0xdb,0xbd,0x7e,0xff,0x7e,0xbd,0xdb,0xe7,0xff,
0x00,0xff,0x00,0xff,0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00,0x80,
0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff,0x00,0xff,0x00,0xff,0xfe,0xfc,
0xf8,0xf0,0xe0,0xc0,0x80,0x00,0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,
0xff,0xfc,0xf9,0xf3,0xe7,0xcf,0x9f,0x3f,0xff,0x00,0xff,0x00,0xff};//流水灯
void adjust(void)
{
if(!K2) //分调整
{
for(i=0;i<20000;i++);min++;
if(min==60)min=0;
}
if(!K1) //时调整
{
for(i=0;i<20000;i++);hour++;
if(hour==24)hour=0;
}
}
void display(void)
{
P0=tab1[min%10];P2=0xef;for(i=0;i<5;i++);P2=0xff;//分个位显示
P0=tab1[min/10];P2=0xdf;for(i=0;i<5;i++);P2=0xff;//分十位显示
P0=tab2[hour%10];P2=0xbf;for(i=0;i<5;i++);P2=0xff;//时个位显示
P0=tab1[hour/10];P2=0x7f;for(i=0;i<5;i++);P2=0xff;//时十位显示
P0=tab1[miao%10];P2=0xfb;for(i=0;i<5;i++);P2=0xff;//秒个位显示
P0=tab1[miao/10];P2=0xf7;for(i=0;i<5;i++);P2=0xff;//秒十位显示
}
void ring(void)
{
if(hour/10==0&&(hour%10>=8&&hour%10<=9))P3_0=0;//早上7:00到晚上7:00自动整点报时,其中13、14点不报时
if(hour/10==1&&(hour%10>=0&&hour%10<=2))P3_0=0;
if(hour/10==1&&(hour%10>=5&&hour%10<=9))P3_0=0;
}
void update(void)
{
if(count==20)
{
count=0;miao++;
if(miao==60)
{
miao=0;min++;
if(min==60)
{
min=0;hour++;
}
if(hour==24)hour=0;
ring();
}
}
}
void main(void)
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
EA=1;
ET0=1;
while(1)
{
if(count==120)P3_0=1;//报时六秒后自动关闭蜂鸣器
adjust();
display();
}
}
void timer0_rupt(void) interrupt 1 // 定时器0中断
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count%10==0)
{
P1=tab3[j];
j++;
if(j>99)j=0;
}
update();
}
ä½ è½å¸®å¿ç»è¯´æä¸ï¼ä»ä»tab1[],tab2[]å¦ä½æ¥å¤ç让æ¶éæ¾ç¤ºæ¶é´çåï¼å°±æ¯è¯´éè¾¹ç16è¿å¶æ°å®æ¯æä¹å¤çç让æ°ç 管æ¥æ¾ç¤ºæ¶é´çé£....
追çmiaoï¼minï¼houræ¯ä½ ç¨å®æ¶å¨åçæ¶é´æ°æ®ãtab1[],ä¸ç16è¿å¶æ°æ¯æ°ç 管çç¼ç ï¼è¿ä½ å¾ç¥éæ°ç 管çåçï¼ä¸ç¶åä½ è¯´ä¸æ¸ ã