#include<reg51.h>
#include<intrins.h>
int keyscan();
void delay();
void main()
{ while(1)
P0=keyscan();
}
int keyscan()
{ int j=0;
P3=0x00;
P1=0xff;
if(P1!=0xef)
{
delay();
if(P1!=0xef)
{
P3=0xfb;
do{ j++;
switch(P1)
{ case 0xaf:
switch(j)
{case 0x01:return 2;break;
case 0x02:return 5;break;
case 0x03:return 8;break;
case 0x04:return 11;break;
}
break;
case 0x6f:
switch(j)
{case 0x01:return 3;break;
case 0x02:return 6;break;
case 0x03:return 9;break;
case 0x04:return 12;break;
}
break;
case 0xcf:
switch(j)
{case 0x01:return 1;break;
case 0x02:return 4;break;
case 0x03:return 7;break;
case 0x04:return 10;break;
}
break;
case 0xef: break;
}
P3=_crol_(P3,1);
} while(P3!=0xbf);
}
}
}
void delay()
{int i,j;
for(i=200;i>0;i--)
for(j=50;j>0;j--);
}