#include"reg51.h"
#define uint unsigned int
#define uchar unsigned char
 uchar code num[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//
 uint keyget()//按键扫描并获取按键值
{
   uint r,c;
	int n;
	n=r=c=0;
	P1=0xf0;
	switch(P1)
	{
		case 0xe0:r=1;break;
		case 0xd0:r=2;break;
		case 0xb0:r=3;break;
		case 0x70:r=4;break;
		default:break;

	}
	P1=0x0f;
  switch(P1)
	{
		case 0x0e:c=1;break;
		case 0x0d:c=2;break;
		case 0x0b:c=3;break;
	    case 0x07:c=4;break;
		default:break;
	}
	switch(r)
	{
    case 1:if(c==1)n=1; if(c==2)n=2; if(c==3)n=3;if(c==4)n=4;
break;
     case 2:if(c==1)n=5; if(c==2)n=6; if(c==3)n=7;if(c==4)n=8;
break;
    case 3:if(c==1)n=9; if(c==2)n=10; if(c==3)n=11;if(c==4)n=12;
break;
    case 4:if(c==1)n=13; if(c==2)n=14; if(c==3)n=15;if(c==4)n=16;
break;
default:break;		
	}
return (n);	
}
main()
{
 uint a,b;
 while(1)
 {
 	a=keyget()%10;
	b=keyget()/10;
	P2=~num[b];
	P3=~num[a];
 }
}