#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit key1=P3^0;
sbit key2=P3^6;
sbit key3=P3^5;
sbit JDQ=P3^7;
sbit we1=P3^1;
sbit we2=P3^2;
sbit we3=P3^3;
sbit we4=P3^4;
bit dian;
uchar code table[]={
0xfc,0x60,0xda,0xf2,0x66,
0xb6,0xbe,0xe0,0xfe,0xf6
};
void keyscan();
void init();
uchar num,fen,miao,shi;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void display(shi,fen)//dis)
{
we1=0;
P1=table[shi/10]|dian;//时十位
delay(5);
P1=0xff;
we1=1;
we2=0;
P1=table[shi%10]|dian;//时个位
delay(5);
P1=0xff;
we2=1;
we3=0;
P1=table[fen/10]|dian;//分十位
delay(5);
P1=0xff;
we3=1;
we4=0;
P1=table[fen%10]|dian;//分个位
delay(5);
P1=0xff;
we4=1;
}
void display1(fen,miao)//dis)
{
we1=0;
P1=table[fen/10]|dian;//时十位
delay(5);
P1=0xff;
we1=1;
we2=0;
P1=table[fen%10]|dian;//时个位
delay(5);
P1=0xff;
we2=1;
we3=0;
P1=table[miao/10]|dian;//分十位
delay(5);
P1=0xff;
we3=1;
we4=0;
P1=table[miao%10]|dian;//分个位
delay(5);
P1=0xff;
we4=1;
}
void main()
{
init();
while(1)
{
keyscan();
if(shi==0)
display1(fen,miao);
else
display(shi,fen);
}
}
void init()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=0;
JDQ=1;
}
void keyscan()
{
if(key1==0)
{
delay(10);
if(key1==0)
{
miao=0;
fen=fen+1;//分加一
if(fen==60)
fen=0;
while(!key1);
}
}
if(key2==0)
{
delay(10);
if(key2==0)
{
shi=shi+1;
if(shi==100)
shi=0;
while(!key2);
}
}
if(key3==0)
{
delay(10);
if(key3==0)
{
TR0=1;
JDQ=0;
while(!key3);
}
}
}
void T0_time() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num++;
if(num%10==0)
dian=~dian;
if(num==20)
{
num=0;
miao--;
if(miao==0xff)
{
miao=59;
fen--;
if(fen==0xff)
{
fen=59;
shi--;
}
}
}
if(shi==0&&fen==0&&miao==0)
{
TR0=0;
JDQ=1;
we1=we2=we3=we4=1;
P1=0x02;
we1=we2=we3=we4=0;
while(1);
}
}
|