int readkeypad (void)
{
output_bit (r1, 0);
output_bit (r2, 0);
output_bit (r3, 0);
output_bit (r4, 0);
output_bit (r1, 1);//activate 1st row and scan for column
delay_ms(10);
IF (input (c1)) RETURN 10;
IF (input (c2)) RETURN 0;
IF (input (c3)) RETURN 11;
//IF (input (c4)) RETURN 12;
output_bit (r1, 0);//Deactivate 1st row
output_bit (r2, 1);//activate 2nd row and scan for column
delay_ms(10);
IF (input (c1)) RETURN 7;
IF (input (c2)) RETURN 8;
IF (input (c3)) RETURN 9;
//IF (input (c4)) RETURN 13;
output_bit (r2, 0);//Deactivate 2nd row
output_bit (r3, 1);//activate 3rd row and scan for column
delay_ms(10);
IF (input (c1)) RETURN 4;
IF (input (c2)) RETURN 5;
IF (input (c3)) RETURN 6;
IF (input (c4)) RETURN 14;
output_bit (r3, 0);//Deactivate 3rd row
output_bit (r4, 1);//activate 4th row and scan for column
delay_ms(10);
IF (input (c1)) RETURN 1;
IF (input (c2)) RETURN 2;
IF (input (c3)) RETURN 3;
IF (input (c4)) RETURN 15;
output_bit (r4, 0);//Deactivate 4th row
RETURN 255;
}