#include<reg52.h>
#include<intrins.h>
#include"delay.h"
unsigned char keyscan()
{
unsigned char i,j,key_value=0xff;
P1=0X0F;
if((P1&0x0f)==0x0f)return 0xff;
else
{
delay_nms(5);
if((P1&0X0F)==0x0f)return 0xff;
else
{
for(i=4;i<8;i++)
{
P1=~(1<<i)|0x0f;
for(j=0;j<4;j++)
{
if((P1&(1<<j))==0)
key_value=(i-4)*4+j;
}
}
return key_value;
}
}
}
|