#include <reg51.h>
sbit x1 = P2^0;
sbit x2 = P2^1;
sbit x3 = P2^2;
sbit x4 = P2^3;
sbit x5 = P2^4;
sbit x6 = P2^5;
sbit k5 = P0^0; //控制分++
sbit k6 = P0^1; //控制分--
int num=0,M=0,num1=0,M1=0;
unsigned char code oo[]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f};
void delay(int z)
{
int i,j;
for(i=z;i>0;i--)
for(j=110;j>0;j--);
}
void fen()
{
if(k5==0)
{
delay(20);
if(k5==1)
{
if(M!=59)
{
delay(40);
M++;
}
else
{ delay(5);
M=0;
}
}
}
}
void int0() interrupt 1
{
TH0 = 0xFC; //初值
TL0 = 0x66;
num++;
if(num == 1000)
{
num = 0;
num1 ++;
}
if(num1==60)
{
num1=0;
M++;
}
if(M == 60)
{
M=0;
M1++;
}
}
void L_xs(int s,int g,int s1,int g1,int s2,int g2)
{
x1=1;x2=1;x3=1;x4=1;x5=1;x6=0; //秒的个位
P1=oo[g];
delay(2);
x1=1;x2=1;x3=1;x4=1;x5=0;x6=1; //秒的十位
P1=oo[s];
delay(2) ;
x1=1;x2=1;x3=1;x4=0;x5=1;x6=1; //分的个位
P1=oo[g1];
delay(2) ;
x1=1;x2=1;x3=0;x4=1;x5=1;x6=1; //分的十位
P1=oo[s1];
delay(2) ;
x1=1;x2=0;x3=1;x4=1;x5=1;x6=1; //时的个位
P1=oo[g2];
delay(2) ;
x1=0;x2=1;x3=1;x4=1;x5=1;x6=1; //时的十位
P1=oo[s2];
delay(2) ;
}
void main()
{
TMOD = 0x01; //工作模式
TH0 = 0xFC; //初值
TL0 = 0x66;
TR0 = 1;
ET0=1;
EA =1; //总中断
while(1)
{
L_xs((num1/10),(num1%10),(M/10),(M%10),(M1/10),(M1%10));
fen();
if(num1 == 60)
{
num1 = 0 ;
}
if(M == 60)
{
M = 0;
}
if(M1 == 24)
{
M1 =0;
}
}
}
|