11 years, 2 months ago.

KEYPAD code

Hello, maybe someone can lend a suggestion or some insight???

So I have been posed with the question as follows:

1. Which key press causes the program to continue? (Row: input with pull-down resistance).

The keypad layout is:

R0123
R1456
R2789
R3*0#
C2C1C0

This is the code:

col = 0x04; while( (row & 0x04) == 0); ......... .........

So here is what I understand; pull-down resistance equals an active high signal. Thusly, I am assuming that because hex 4 is the same as binary 0100 that C2 is active. Which means that 1,4,7,* are the possible choices, right? So the row button and 0x04 from the code have to equal 0 correct? So the value that is "anded" with 0x04 will result in the answer? Which means that any will work but the 7 key. Is this correct or did I think about it incorrectly??? Thanks in advance... Also part 2) asks how to write a code similar to this code to have just the 7 key activate the program?

I hope you don't mind I've reformatted your table.

posted by Stephen Paulger 15 Mar 2013

1 Answer

11 years, 2 months ago.

I'm not familiar with the wiring on the keypad but the test in the while loop is only checking the value of row (and not col).

This means that any button on the row that corresponds to the value 4 will allow the program to continue. To make it work with only a single button the check of the while loop would need to test both row and col.

Edit:

Actually using & with 0x04 will never give the value 0.

Accepted Answer

?; So '&' will not allow the code to execute properly? Interesting... well thanks for the reply.

posted by Anthony King 16 Mar 2013