#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar code display_code[]=
{
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0x00
};
void delay_1ms(uchar ms)
{
uchar i;
while(ms--)
for(i=0;i<115;i++);
}
void main()
{
uchar temp,num=0;
P0=0x00;
while(1)
{
P1=0xfe;
temp=P1;
temp=temp&0xf0;
delay_1ms(2);
if(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
delay_1ms(2);
if(temp!=0xf0)
{
temp=P1; //大哥,一定要读端口的值呀,在这里弄了一个晚上
delay_1ms(2);
switch(temp)
{
case 0xee:
num=0;
break;
case 0xde:
num=1;
break;
case 0xbe:
num=2;
break;
case 0x7e:
num=3;
break;
}
while(P1==0xee||P1==0xde||P1==0xbe||P1==0x7e);//一定要注意实时性,此处两种方法都能用
/* while(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
*/
P0=display_code[num];
}
}
}
}