#include
#define uchar unsigned char
uchar code seg7[]={ 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar second ,minute,hour,count,m,num,num1,i,s,f;
//void delay()
void display() ;//函数要先申明,才能在在定义前被调用
void delay1s(void)
{
uchar a,b,c;
for(c=3;c>0;c--)
for(b=2;b>0;b--)
for(a=2;a>0;a--)
display();
}
delay()
{
uchar a,b,c;
for(c=1;c>0;c--)
for(b=2;b>0;b--)
for(a=7;a>0;a--)
display();
}
delay1()
{
uchar a,b,c;
for(c=4;c>0;c--)
for(b=2;b>0;b--)
for(a=25;a>0;a--)
display();
}
delay1ms()
{
uchar a,b;
for(b=2;b>0;b--)
for(a=150;a>0;a--)
;//少了分号
}
delay5()
{
uchar a,b;
for(b=80;b>0;b--)
for(a=53;a>0;a--) ;//少了分号
}
void display()
{
if(num==1)
{
P1=seg7[second/10];
P2=0xf7;
delay1ms();
P2=0xff;
P1=seg7[second%10];
P2=0xfb;
delay1ms();
P2=0xff;
}
if(num==2)
{
P1=seg7[minute/10];
P2=0xdf;
delay1ms();
P2=0xff;
P1=seg7[minute%10];
P2=0xef;
delay1ms();
P2=0xff;
}
if(num==3)
{
P1=seg7[hour/10];
P2=0x7f;
delay1ms();
P2=0xff;
P1=seg7[hour%10];
P2=0xbf;
delay1ms();
P2=0xff;
}
if(num==0)
{
P1=seg7[second/10];
P2=0xf7;
delay1ms();
P2=0xff;
P1=seg7[second%10];
P2=0xfb;
delay1ms();
P2=0xff;
P1=seg7[minute/10];
P2=0xdf;
delay1ms();
P2=0xff;
P1=seg7[minute%10];
P2=0xef;
delay1ms();
P2=0xff;
P1=seg7[hour/10];
P2=0x7f;
delay1ms();
P2=0xff;
P1=seg7[hour%10];
P2=0xbf;
delay1ms();
P2=0xff;
}
}
settime(uchar z,uchar y,uchar x)
{
if(second==x)
if(minute==y)
if(hour==z)
{
for(i=0;i 0;m--)
{
P3_1=0;
delay1s();
P3_1=1;
delay1s();
}
}
zhengdian()
{
if(P3_4==0)
{
if(second==0)
{
if(minute==0)
{
display();
switch(hour)
{
case 1: shi(1);break;
case 2:shi(2);break ;
case 3: shi(3);break ;
case 4: shi(4);break ;
case 5: shi(5);break ;
case 6: shi(6);break ;
case 7: shi(7);break ;
case 8: shi(8);break ;
case 9: shi(9);break ;
case 10: shi(10);break ;
case 12: shi(12);break ;
}
}
}
}
if(P3_4==1)
{
delay1s();
if(P3_4==1)
{
switch(hour)
{
case 1: shi(1);break ;
case 2:shi(2);break ;
case 3: shi(3);break ;
case 4: shi(4);break ;
case 5: shi(5);break ;
case 6: shi(6);break ;
case 7: shi(7);break ;
case 8: shi(8);break ;
case 9: shi(9);break ;
case 10: shi(10);break ;
case 12: shi(12);break ;
}
}
}
}
void main()
{
hour=12;
TMOD=0x01;
TH0=60;
TL0=176;
ET0=1;
TR0=1;
EA=1;
while(1)
{
display();
timeupdown();
zhengdian();
settime(06,06,06);
}
}
void t0() interrupt 1
{
count++;
if(count=20)
{
count=0;
second++;
P3_0=~P3_0;
if(second==60)
{
second=0;
minute++;
if(minute==60)
{
minute=0;
hour++;
if(hour==13)
hour=1;
}
}
}
TH0=60;
TL0=176;
}