#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit led=P2^0;
sbit wea=P2^2;
sbit web=P2^3;
sbit wec=P2^4;
sbit fm=P1^5;
sbit sw1=P3^1;
sbit sw2=P3^0;
sbit sw3=P3^2;
sbit sw4=P3^3;
uchar code duma[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71
};
uchar time ,counter,time_counter;
uchar i ;
void delay(uint z);
void delay(uint z)
{
while (z--);
}
void display(uchar i)
{ uchar shi,ge,qie;
shi=i%100/10;
ge=i%10;
qie=i/100;
P0=0XFF;
wea=0;
web=0;
wec=0;
P0=duma[ge];
delay(41);
P0=0XFF;
wea=1;
web=0;
wec=0;
P0=duma[shi];
delay(41);
P0=0XFF;
wea=0;
web=1;
wec=0;
P0=duma[qie];
delay(41);
}
void keypros()
{
if(sw1==0)
{
delay(10);
if(sw1==0)
{
time_counter++;
while(!sw1);
}
}
if(sw2==0)
{
delay(10);
if(sw2==0&&time_counter!=0)
{
time_counter--;
while(!sw2);
}
}
if(sw3==0)
{
delay(10);
if(sw3==0)
{
TR1=0;
led=1;
time_counter=0;
while(!sw3);
}
}
if(sw4==0)
{
delay(10);
if(sw4==0)
{
TR1=~TR1;
led=~led;
while(!sw4);
}
}
}
void init()
{
TMOD=0x10;
TH1=0x4b;
TL1=0x00;
TR1=0;
}
void main()
{
init();
while(1)
{
keypros();
if(TF1==1)
{ TF1=0;
TH1=0x4b;
TL1=0x00;
counter++;
}
if(counter==10)
{
counter=0;
time_counter++;
}
if(time_counter==240)
time_counter=0;
display(time_counter);
}
}
|