Let say you have 4 by 4 row and column keypad and wanna scan it.
You need to pull either the column or row high with a 2k resistor .
Then the remaining row or collum is get scan for the low signal. From that we can figure out which key is being press
connect the whole 8 wires of keypad at one port.
the wires of rows at one nibble and that of cols at other.
then first send 0x0f and scan the port and then 0xf0 and scan the port. then logically OR the two results. thats ur code. really. only do the same process after giving a little delay(loop delay) for deboiuncing