#include<reg52.h> //52????????
#define uchar unsigned char //???
#define uint unsigned int
sbit key1=P3^4; //?????
sbit key2=P3^5;
sbit key3=P3^6;
sbit key4=P3^7;
sbit dula=P2^6; //??U2??????
sbit wela=P2^7; //??U3??????
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //???????
void delayms(uint);
uchar numt0,num;
void display(uchar numdis)
{
uchar shi,ge; //???????????
shi=numdis/10; //??
ge=numdis%10; //??
P0=0xff; //??
wela=1; //??U3???
P0=0xfe; //??????
wela=0; //??U3???
dula=1; //??U2???
P0=table[shi]; //????????
dula=0; //??U2???
delayms(5); //??
P0=0xff; //??
wela=1; //??U3???
P0=0xfd; //??????
wela=0; //??U3???
dula=1; //??U2???
P0=table[ge]; //????????
dula=0; //??U2???
delayms(5);
}
void delayms(uint ys)
{
uint i,j;
for(i=ys;i>0;i--) //i=ys ????ys??
for(j=110;j>0;j--);
}
void init() //???????
{
TMOD=0x01; //?????0?????1(0000 0001)
TH0=(65536-45872)/256; //???50ms????
TL0=(65536-45872)%256;
EA=1; //????
ET0=1; //????0??
}
void keyscan()
{
if(key1==0)
{
delayms(10);
if(key1==0)
{
num++;
if(num==60) //?60?????0
num=0;
while(!key1); //??????
}
}
if(key2==0)
{
delayms(10);
if(key2==0)
{
if(num==0) //??0????60
num=60;
num--;
while(!key2);
}
}
if(key3==0)
{
delayms(10);
if(key3==0)
{
num=0; // ?0
while(!key3);
}
}
if(key4==0)
{
delayms(10);
if(key4==0)
{
while(!key4);
TR0=~TR0; //????????0
}
}
}
void main()
{
init(); //?????
while(1)
{
keyscan();
display(num);
}
}
void T0_time() interrupt 1
{
TH0=(65536-45872)/256; //????
TL0=(65536-45872)%256;
numt0++;
if(numt0==20)
{
numt0=0;
num++;
if(num==60)
num=0;
}
}#include<reg52.h> //52????????
#define uchar unsigned char //???
#define uint unsigned int
sbit key1=P3^4; //?????
sbit key2=P3^5;
sbit key3=P3^6;
sbit key4=P3^7;
sbit dula=P2^6; //??U2??????
sbit wela=P2^7; //??U3??????
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //???????
void delayms(uint);
uchar numt0,num;
void display(uchar numdis)
{
uchar shi,ge; //???????????
shi=numdis/10; //??
ge=numdis%10; //??
P0=0xff; //??
wela=1; //??U3???
P0=0xfe; //??????
wela=0; //??U3???
dula=1; //??U2???
P0=table[shi]; //????????
dula=0; //??U2???
delayms(5); //??
P0=0xff; //??
wela=1; //??U3???
P0=0xfd; //??????
wela=0; //??U3???
dula=1; //??U2???
P0=table[ge]; //????????
dula=0; //??U2???
delayms(5);
}
void delayms(uint ys)
{
uint i,j;
for(i=ys;i>0;i--) //i=ys ????ys??
for(j=110;j>0;j--);
}
void init() //???????
{
TMOD=0x01; //?????0?????1(0000 0001)
TH0=(65536-45872)/256; //???50ms????
TL0=(65536-45872)%256;
EA=1; //????
ET0=1; //????0??
}
void keyscan()
{
if(key1==0)
{
delayms(10);
if(key1==0)
{
num++;
if(num==60) //?60?????0
num=0;
while(!key1); //??????
}
}
if(key2==0)
{
delayms(10);
if(key2==0)
{
if(num==0) //??0????60
num=60;
num--;
while(!key2);
}
}
if(key3==0)
{
delayms(10);
if(key3==0)
{
num=0; // ?0
while(!key3);
}
}
if(key4==0)
{
delayms(10);
if(key4==0)
{
while(!key4);
TR0=~TR0; //????????0
}
}
}
void main()
{
init(); //?????
while(1)
{
keyscan();
display(num);
}
}
void T0_time() interrupt 1
{
TH0=(65536-45872)/256; //????
TL0=(65536-45872)%256;
numt0++;
if(numt0==20)
{
numt0=0;
num++;
if(num==60)
num=0;
}
} |