#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar ms=26,a,qiangda,flag2,xs=5,n=20;
sbit we1 = P2^1;
sbit we2 = P2^2;
sbit we3 = P2^3;
sbit we4 = P2^4;
sbit beep = P3^7;
sbit zhuchi = P3^6;
sbit S1 = P1^0;
sbit S2 = P1^1;
sbit S3 = P1^2;
sbit S4 = P1^3;
sbit S5 = P1^4;
sbit S6 = P1^5;
sbit Sa = P1^6;
sbit Sj = P1^7;
sbit L1=P3^5;
uchar code tab[]={ 0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};
void delay(uint z);
void display();
void init();
void key();
void main()
{
init();
while(1)
{
display();
key();
}
}
void timer1() interrupt 3
{
TH1 = 0X4b;
TL1 = 0Xfe;
a++;
if(a == 20 && qiangda == 1)
{
a = 0;
ms--;
if(ms == 0 && qiangda == 1)
{
ms = 0;
TR1 = 0;
P0 = 0;
beep = 1;
qiangda = 0;
L1=1;
delay(20000);
L1=0;
}
}
if(a == 20 && flag2 == 1)
{
a = 0;
ms--;
if(ms == 0)
{
ms = 0;
TR1 = 0;
P0 = 0;
beep = 1;
L1=1;
delay(20000);
L1=0;
}
}
}
void delay(uint z)
{
uchar x,y;
for(x = z;x > 0;x--)
for(y = 114;y > 0;y--);
}
void display()
{
we1 = 0;P0=tab[xs]; delay(1);we1 = 1;
we2 = 0;P0=0x40;delay(1);we2 = 1;
we3 = 0;P0=tab[ms/10];delay(1);we3 = 1;
we4 = 0;P0=tab[ms%10];delay(1);we4 = 1;
}
void key()
{
if(zhuchi == 0)
{
delay(5);
if(zhuchi == 0)
{
TR1 = ~TR1;
ms=5;
xs=0;
qiangda = 1;
beep=0;delay(2000);beep=1;
while(!zhuchi);
}
}
if(Sa == 0)
{
delay(10);
if(Sa == 0)
{
beep=0;delay(2000);beep=1;
n++;
ms=n;
if(n==30)
{n=4;}
display();
while(!Sa);
}
}
if(Sj == 0)
{
delay(10);
if(Sj == 0)
{
beep=0;delay(2000);beep=1;
n--;
ms=n;
if(n==5)
{n=31;}
display();
while(!Sj);
}
}
if(qiangda == 1)
{
P1=0xff;
if(P1 != 0xff)
{
delay(5);
if(P1 != 0xff)
{
switch(P1)
{
case 0xfe:{TR1=0;xs=1;TR1=1;flag2=1;qiangda = 0;beep = 0;delay(2000);beep = 1;ms = n;};break;
case 0xfd:{TR1=0;xs=2;TR1=1;flag2=1;qiangda = 0;beep = 0;delay(2000);beep = 1;ms = n;};break;
case 0xfb:{TR1=0;xs=3;TR1=1;flag2=1;qiangda = 0;beep = 0;delay(2000);beep = 1;ms = n;};break;
case 0xf7:{TR1=0;xs=4;TR1=1;flag2=1;qiangda = 0;beep = 0;delay(2000);beep = 1;ms = n;};break;
case 0xef:{TR1=0;xs=5;TR1=1;flag2=1;qiangda = 0;beep = 0;delay(2000);beep = 1;ms = n;};break;
case 0xdf:{TR1=0;xs=6;TR1=1;flag2=1;qiangda = 0;beep = 0;delay(2000);beep = 1;ms = n;};break;
}
}
}
}
}
void init()
{
L1=0;
a = 0;
ms = 5;
beep = 1;
TMOD = 0x10;
TH1 = 0X4b;
TL1 = 0Xfe;
EA = 1;
ET1 = 1;
TR1 = 0;
}
|