sccode=0xFE;/*every scan initiative value,11111110*/
while(sccode!=0xEF)/*sccode is not 11101111,follow;or return 0*/
{
PORTA=sccode;/*send scan code 11111110 to portA*/
PORTA=sccode;/*send scan code 11111110 to portA*/
if((PINA&0xF0)!=0xF0)/*read portA,if high 4 bits are not 1111,key pressed in this line*/
{
recode=(PINA&0xF0)|0x0F;/*portA high 4 bits reserved,low 4 bits are 1111*/
while((PINA&0xF0)!=0xF0)
{};
/*read portA,if portA high 4 bits are not 1111,key
;pressed,
if key pressed,we must wait,wait for key released*/
return((~sccode)+(~recode));/*return row+column*/
}
else
{
sccode=(sccode<<1)|0x01;
/*scan code left shift 1 bit, add 1 to right,11111101*/
}
}