#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar bai,shi,ge;
uint b;
uchar const table[]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f,0x76,0x79,0x38,0x00};
sbit dula=P2^6;
sbit wela=P2^7;
uchar keycan(void);
void delayms(uint z);
void display(uchar bai,uchar shi,uchar ge);
void main()
{
uchar key;
P0=0x00;
while(1)
{
key=keycan();
switch(key)
{
case 0xee: b=1*1*1; break;
case 0xde: b=2*2*2; break;
case 0xbe: b=3*3*3; break;
case 0x7e: b=4*4*4; break;
case 0xed: b=5*5*5; break;
case 0xdd: b=6*6*6; break;
case 0xbd: b=7*7*7; break;
case 0x7d: b=8*8*8; break;
case 0xeb: b=9*9*9; break;
case 0xdb: b=10*10*10; break;
case 0xbb: b=11*11*11; break;
case 0x7b: b=12*12*12; break;
case 0xe7: b=13*13*13; break;
case 0xd7: b=14*14*14; break;
case 0xb7: b=15*15*15; break;
case 0x77: b=16*16*16; break;
}
bai=b/100;
shi=b%100/10;
ge=b%10;
display(bai,shi,ge);
}
}
uchar keycan()
{
uchar temp_h,temp_l;
P3=0x0f;
temp_h=P3&0x0f;
if(temp_h!=0x0f)
{
delayms(100);
temp_h=P3&0x0f;
if(temp_h!=0x0f)
{
P3=temp_h|0xf0;
temp_l=P3&0xf0;
return(temp_h+temp_l);
}
}return (0xff);
}
void delayms(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void display(uchar bai,uchar shi,uchar ge)
{
dula=1;
P0=table[bai];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delayms(1);
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
wela=0;
delayms(1);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xdf;
wela=0;
delayms(1);
}
P2.6,P2.7接锁存器