300我帮你搞定 没这个数不想动脑筋
#include
void display(unsigned char time[]);
void display0(unsigned char data0[]);
void display1(unsigned char data1[]);
void display2(unsigned char data2[]);
void display3(unsigned char data3[]);
void display4(unsigned char data4[]);
void display5(unsigned char data5[]);
void display6(unsigned char data6[]);
void display7(unsigned char data7[]);
void display8(unsigned char data8[]);
void display9(unsigned char data9[]);
void key(void);
unsigned char code seg[13]=
{
0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f,
0x77, 0x7c, 0x39
};
unsigned char code sel[4]=
{
0x10,0x20,0x40,0x80
};
unsigned char time[4]={0,0,0,0};
unsigned char data1[4]={0,0,0,0},data2[4]={0,0,0,0},data3[4]={0,0,0,0},
data4[4]={0,0,0,0},data5[4]={0,0,0,0},data6[4]={0,0,0,0},
data7[4]={0,0,0,0},data0[4]={0,0,0,0},data8[4]={0,0,0,0},
data9[4]={0,0,0,0};
unsigned char count;
unsigned char keytmp;
unsigned char begin=0;
void timeinit(void) interrupt 1
{
count=1;
TH0=0xd8;
TL0=0xf0;
}
void main(void)
{
unsigned char a,b,c,d,i;
count=0;
TMOD=0x01;
TH0=0xd8;
TL0=0xf0;
ET0=1;
TR0=1;
EA=1;
while(1)
{
P1 = 0xfe;
keytmp = P1;
if(keytmp==0xf6)
{
begin=1;
a=0;
b=0;
c=0;
d=0;
}while(P1==0xf6);
if(begin==1)
{
if(count==1) {a++;count=0;}
if(a==10) {b++;a=0;}
if(b==10) {c++;b=0;}
if(c==10) {d++;c=0;}
time[0]=a;
time[1]=b;
time[2]=c;
time[3]=d;
display(time);
}
P1 = 0xfe;
keytmp = P1;
switch(keytmp)
{
case 0xee: {data7[0]=a;data7[1]=b;data7[2]=c;data7[3]=d;}while(P1==0xee);
break;
case 0xde: {data4[0]=a;data4[1]=b;data4[2]=c;data4[3]=d;}while(P1==0xde);
break;
case 0xbe: {data1[0]=a;data1[1]=b;data1[2]=c;data1[3]=d;}while(P1==0xbe);
break;
default: break;
}
P1 = 0xfd;
keytmp = P1;
switch(keytmp)
{
case 0xf5: {data0[0]=a;data0[1]=b;data0[2]=c;data0[3]=d;}while(P1==0xf5);
break;
case 0xed: {data8[0]=a;data8[1]=b;data8[2]=c;data8[3]=d;}while(P1==0xed);
break;
case 0xdd: {data5[0]=a;data5[1]=b;data5[2]=c;data5[3]=d;}while(P1==0xdd);
break;
case 0xbd: {data2[0]=a;data2[1]=b;data2[2]=c;data2[3]=d;}while(P1==0xbd);
break;
default: break;
}
P1 = 0xfb;
keytmp = P1;
switch(keytmp)
{
case 0xeb: {data9[0]=a;data9[1]=b;data9[2]=c;data9[3]=d;}while(P1==0xeb);
break;
case 0xdb: {data6[0]=a;data6[1]=b;data6[2]=c;data6[3]=d;}while(P1==0xdb);
break;
case 0xbb: {data3[0]=a;data3[1]=b;data3[2]=c;data3[3]=d;}while(P1==0xbb);
break;
default: break;
}
P1 = 0xfb;
keytmp = P1;
if(keytmp==0xf3)
{
TR0=0;
}while(P1==0xf3);
while(TR0==0 )
{
P1 = 0xfe;
keytmp = P1;
switch(keytmp)
{
case 0xee: {for(i=0;i<100;i++) display7(data7);}while(P1==0xee);
break;
case 0xde: {for(i=0;i<100;i++) display4(data4);}while(P1==0xde);
break;
case 0xbe: {for(i=0;i<100;i++) display1(data1);}while(P1==0xbe);
break;
default: break;
}
P1 = 0xfd;
keytmp = P1;
switch(keytmp)
{
case 0xf5: {for(i=0;i<100;i++) display0(data0);}while(P1==0xf5);
break;
case 0xed: {for(i=0;i<100;i++) display8(data8);}while(P1==0xed);
break;
case 0xdd: {for(i=0;i<100;i++) display5(data5);}while(P1==0xdd);
break;
case 0xbd: {for(i=0;i<100;i++) display2(data2);}while(P1==0xbd);
break;
default: break;
}
P1 = 0xfb;
keytmp = P1;
switch(keytmp)
{
case 0xeb: {for(i=0;i<100;i++) display9(data9);}while(P1==0xeb);
break;
case 0xdb: {for(i=0;i<100;i++) display6(data6);}while(P1==0xdb);
break;
case 0xbb: {for(i=0;i<100;i++) display3(data3);}while(P1==0xbb);
break;
default: break;
}
P1 = 0xfe;
keytmp = P1;
if(keytmp==0xf6) { TR0=1;} while(P1==0xf6);
}
}
}
void display(unsigned char time[] )
{
unsigned char i;
unsigned int j;
for(i=0;i<4;i++)
{
P2=sel[i];
P0=seg[time[i]];
for (j=0; j<1000; j++);
}
}
void display0(unsigned char data0[] )
{
unsigned char i;
unsigned int j;
for(i=0;i<4;i++)
{
P2=sel[i];
P0=seg[data0[i]];
for (j=0; j<1000; j++);
}
}
void display1(unsigned char data1[] )
{
unsigned char i;
unsigned int j;
for(i=0;i<4;i++)
{
P2=sel[i];
P0=seg[data1[i]];
for (j=0; j<1000; j++);
}
}
void display2(unsigned char data2[] )
{
unsigned char i;
unsigned int j;
for(i=0;i<4;i++)
{
P2=sel[i];
P0=seg[data2[i]];
for (j=0; j<1000; j++);
}
}
void display3(unsigned char data3[] )
{
unsigned char i;
unsigned int j;
for(i=0;i<4;i++)
{
P2=sel[i];
P0=seg[data3[i]];
for (j=0; j<1000; j++);
}
}
void display4(unsigned char data4[] )
{
unsigned char i;
unsigned int j;
for(i=0;i<4;i++)
{
P2=sel[i];
P0=seg[data4[i]];
for (j=0; j<1000; j++);
}
}
void display5(unsigned char data5[] )
{
unsigned char i;
unsigned int j;
for(i=0;i<4;i++)
{
P2=sel[i];
P0=seg[data5[i]];
for (j=0; j<1000; j++);
}
}
void display6(unsigned char data6[] )
{
unsigned char i;
unsigned int j;
for(i=0;i<4;i++)
{
P2=sel[i];
P0=seg[data6[i]];
for (j=0; j<1000; j++);
}
}
void display7(unsigned char data7[] )
{
unsigned char i;
unsigned int j;
for(i=0;i<4;i++)
{
P2=sel[i];
P0=seg[data7[i]];
for (j=0; j<1000; j++);
}
}
void display8(unsigned char data8[] )
{
unsigned char i;
unsigned int j;
for(i=0;i<4;i++)
{
P2=sel[i];
P0=seg[data8[i]];
for (j=0; j<1000; j++);
}
}
void display9(unsigned char data9[] )
{
unsigned char i;
unsigned int j;
for(i=0;i<4;i++)
{
P2=sel[i];
P0=seg[data9[i]];
for (j=0; j<1000; j++);
}
}