板子是郭天祥的,作为参考使用。
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula = P2^6;
sbit wela = P2^7;
sbit key1 =P3^4;
sbit key2 = P3^5;
uchar code table[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar code table2[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};//0xff
uint a = 0,b;
void time(uint t);
void kk(){//数码管显示
dula = 1;
P0 = table[a%10];
dula = 0;
wela = 1;
P0 = 0xdf;
wela = 0;
time(10);
dula = 1;
P0 = table[a/10];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = 0xef;
wela = 0;//
time(10);
}
void main()
{
while(1){
kk();
if(key1 == 0){
time(10);
if(key1 == 0){
while(1){
a++;
time(100);
kk();
if(a<0||a>=60){
a = 0;
break;
}
if(key2 == 0){break;}
}
if(key2 == 0){
time(10);
if(key2 == 0){
while(1){
a--;
kk();
time(100);
if(a<0||a>=60){
a = 0;
break;
}
if(key1 == 0){break;}
}
}
}
}
}
}
}
void time(uint t){
uint i,j;
for(i=t;i>0;i--)
for(j=110;j>0;j--);
}