Hi Aratti,

You're doing a good job here, but there are a couple issues I'd like to bring up.
Don't shoot me.

While scanning the first row, you set PortB =16 which puts RB4 high and RB5-7 low.

<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=3010" /><!-- Name:  KeypadShort.JPG
Views: 4300
Size:  18.2 KB -->

If someone accidentally presses keys 1.1 and 2.1 at the same time, you have a dead short across RB4 and RB5. If you have a small power supply it won't last long because the PIC will reset as soon as the voltage drops low enough. But if you have a strong power supply, somethings likely to smoke.

The problem can be overcome a couple ways, either by adding ~100 ohm resistors in series with each Row's pin. Or you can manipulate the TRIS register in your program instead of PORTB, and only allow 1 Row at a time to be in OUTPUT mode.

And, it would be allot nicer to have the Outputs on the lower bits of PORTB, and the Inputs on RB4-7.

Then you would be able to use the PortB Change interrupts to monitor the keypad, and you wouldn't have to keep scanning it all the time. You would then place all outputs to HIGH and when you get an interrupt, scan the rows 1 by 1 like normal.

HTH,