#include<reg51.h>
#define LEDData P0
unsigned char code LEDCode[]={0xcf,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
int minit,second,count,count1; //???????????
char min=15,sec=0;
sbit add1=P1^0; //???????????μ?1?? /??δ???????????????
sbit dec1=P1^1; //????????????μ?1?? /??δ???????????????
sbit exchange=P1^2; //????????
sbit add2=P1^3; //???????????μ?1?? /??δ????????????????
sbit dec2=P1^4; //????????????μ?1?? /??δ????????????????
sbit p24_sec=P1^5;
sbit secondpoint=P0^7; //????????
//----???ε?????????λ------
sbit led1=P2^7;
sbit led2=P2^6;
sbit led3=P2^5;
sbit led4=P2^4;
sbit led5=P2^3;
sbit led6=P2^2;
sbit led7=P2^1;
sbit led8=P2^0;
sbit led9=P3^7;
sbit led10=P3^6;
sbit led11=P3^5;
sbit led12=P3^4;
sbit alam=P1^7; //????
bit playon=0; //???????б??λ???1????????????????????
bit timeover=0; //???????????λ???1????????????
bit AorB=0; //????????λ????λ
bit halfsecond=0; //??????λ
unsigned int scoreA; //???÷?
unsigned int scoreB; //???÷?
char sec24=24;
void Delay5ms(void)
{
unsigned int i;
for(i=100;i>0;i--);
}
void display(void)
{
//-----------???????--------------
LEDData=LEDCode[minit/10];
led1=0;
Delay5ms();
led1=1;
LEDData=LEDCode[minit%10];
led2=0;
Delay5ms();
led2=1;
//-------------???????------------
if(halfsecond==1)
LEDData=0x7f;
else
LEDData=0xff;
led2=0;
Delay5ms();
led2=1;
secondpoint=0;
//-----------????????------------
LEDData=LEDCode[second/10];
led3=0;
Delay5ms();
led3=1;
LEDData=LEDCode[second%10];
led4=0;
Delay5ms();
led4=1;
//-----------???1????????λ-------
if(AorB==0)
LEDData=LEDCode[scoreA/100];
else
LEDData=LEDCode[scoreB/100];
led5=0;
Delay5ms();
led5=1;
//---------------???1????????λ-----------
if(AorB==0)
LEDData=LEDCode[(scoreA%100)/10];
else
LEDData=LEDCode[(scoreB%100)/10];
led6=0;
Delay5ms();
led6=1;
//---------------???1????????λ-----------
if(AorB==0)
LEDData=LEDCode[scoreA%10];
else
LEDData=LEDCode[scoreB%10];
led7=0;
Delay5ms();
led7=1;
//-----------???2????????λ-------
if(AorB==1)
LEDData=LEDCode[scoreA/100];
else
LEDData=LEDCode[scoreB/100];
led8=0;
Delay5ms();
led8=1;
//-----------???2????????λ-----------
if(AorB==1)
LEDData=LEDCode[(scoreA%100)/10];
else
LEDData=LEDCode[(scoreB%100)/10];
led9=0;
Delay5ms();
led9=1;
//-----------???2????????λ-----------
if(AorB==1)
LEDData=LEDCode[scoreA%10];
else
LEDData=LEDCode[scoreB%10];
led10=0;
Delay5ms();
led10=1;
//-----------???????--------------
LEDData=LEDCode[sec24/10];
led11=0;
Delay5ms();
led11=1;
LEDData=LEDCode[sec24%10];
led12=0;
Delay5ms();
led12=1;
}
//=========================??????????================================================
void keyscan(void)
{
if(playon==0)
{
if(add1==0)
{
display();
if(add1==0);
{
if(minit<99)
minit++;
else
minit=99;
min=minit;
}
do
display();
while(add1==0);
}
if(dec1==0)
{
display();
if(dec1==0);
{
if(minit>0)
minit--;
else
minit=0;
min=minit;
}
do
display();
while(dec1==0);
}
if(add2==0)
{
display();
if(add2==0);
{
if(second<59)
second++;
else
second=59;
sec=second;
}
do
display();
while(add2==0);
}
if(dec2==0)
{
display();
if(dec2==0);
{
if(second>0)
second--;
else
second=0;
sec=second;
}
do
display();
while(dec2==0);
}
if(exchange==0)
{
display();
if(exchange==0);
{
TR1=0; //???T1??????
alam=1; //?????
AorB=~AorB; //???????
minit=min; //???????????15??00
second=sec;
sec24=24;
}
do
display();
while(exchange==0);
}
}
else
{
if(add1==0)
{
display();
if(add1==0);
{
if(AorB==0)
{
if(scoreA<999)
scoreA++;
else
scoreA=999;
}
else
{
if(scoreB<999)
scoreB++;
else
scoreB=999;
}
}
do
display();
while(add1==0);
}
if(dec1==0)
{
display();
if(dec1==0);
{
if(AorB==0)
{
if(scoreA>0)
scoreA--;
else
scoreA=0;
}
else
{
if(scoreB>0)
scoreB--;
else
scoreB=0;
}
}
do
display();
while(dec1==0);
}
if(add2==0)
{
display();
if(add2==0);
{
if(AorB==1)
{
if(scoreA<999)
scoreA++;
else
scoreA=999;
}
else
{
if(scoreB<999)
scoreB++;
else
scoreB=999;
}
}
do
display();
while(add2==0);
}
if(dec2==0)
{
display();
if(dec2==0);
{
if(AorB==1)
{
if(scoreA>0)
scoreA--;
else
scoreA=0;
}
else
{
if(scoreB>0)
scoreB--;
else
scoreB=0;
}
}
do
display();
while(dec2==0);
}
if(p24_sec==0)
{
display();
if(p24_sec==0)
{
sec24=24;
TR0=1;
alam=1;
while(p24_sec==0) display();
}
}
}
}
//******************************??????*************************************************
void main(void)
{
TMOD=0x11;
TL0=0xb0;
TH0=0x3c;
TL1=0xb0;
TH1=0x3c;
minit=min; //?????15??00
second=sec;
EA=1;
ET0=1;
ET1=1;
TR0=0;
TR1=0;
EX0=1;
IT0=1;
IT1=1;
// EX1=1;
PX0=1;
// PX1=1;
PT0=0;
P1=0xFF;
P3=0xFF;
alam=1;
while(1)
{
keyscan();
display();
}
}
void PxInt0(void) interrupt 0
{
Delay5ms();
EX0=0;
alam=1;
TR1=0;
if(timeover==1)
{
timeover=0;
}
if(playon==0)
{
playon=1; //??????λ
TR0=1; //??????
if((minit+second)==0)
{
sec24=24;
minit=min;
second=sec;
}
}
else
{
playon=0; //??????λ??????????
TR0=0; //??????
}
EX0=1; //???ж?
}
/*
void PxInt1(void) interrupt 2
{
Delay5ms();
EX1=0; //???ж?
if(timeover==1) //????????????????????????????????????????????????
{
TR1=0; //???T1??????
alam=1; //?????
AorB=~AorB; //???????
minit=15; //???????????15??00
second=0;
}
EX1=1; //???ж?
}
*/
//*********************************?ж??????**************************************
void time0_int(void) interrupt 1
{
TL0=0xb0;
TH0=0x3c;
TR0=1;
count++;
if(count==10)
{
halfsecond=0;
}
if(count==20)
{
count=0;
halfsecond=1;
// if(second>0)
{
second--;
if(second<0)
{
if(minit>0)
{
second=59;
minit--;
}
else
{
second=0;
timeover=1;
playon=0;
TR0=0;
TR1=1;
}
}
sec24--;
if(sec24<=0)
{
if((minit+second)!=0)
{
alam=0;
TR0=0;
}
sec24=0;
}
}
}
}
//*********************************?ж??????**************************************
void time1_int(void) interrupt 3
{
TL1=0xb0;
TH1=0x3c;
TR1=1;
count1++;
if(count1==10)
{
alam=0;
}
if(count1==20)
{
count1=0;
alam=1;
}
}
|