How do you convert INA[3..0] into a decimal value

Hello Everyone
I am using a MM74C922 16-Key Encoder (Keypad Encoder) from Fairchild Semiconductor. This chip sets the value of pins 0 - 3 according to the truth table in the datasheet. For easy deciphering within my program, I want to convert these bits into a decimal value. Here is the scenario:
How do I convert these bits into a decimal value?
Thanks
Bruce
I am using a MM74C922 16-Key Encoder (Keypad Encoder) from Fairchild Semiconductor. This chip sets the value of pins 0 - 3 according to the truth table in the datasheet. For easy deciphering within my program, I want to convert these bits into a decimal value. Here is the scenario:
PUB Main cognew(MonitorKeypad, @KeypadCheckStack) REPEAT UNTIL PressedKey == 0 OR PressedKey == 8 IF KeyPressed == 1 PiezoInputError KeyPressed := 0 PUB MonitorKeypad DIRA[0..3]~ DIRA[5]~ REPEAT WAITPEQ(|<5, |<5, 0) PressedKey := INA[3..0] KeyPressed := 1 WAITPNE(|<5, |<5, 0)
How do I convert these bits into a decimal value?
Thanks
Bruce
Comments
John Abshier
I know the value is in INA[0..3] through previous testing using FullDuplexSerialPlus, but when I use it as stated above, it fails to recognize the value.
Thanks For Responding
Bruce
If the value is wrong it outputs to Piezo to indicate that an incorrect key was pressed.
Bruce
Your main routine will exit it's repeat loop and and then exit the routine and everything stops.
That is correct for this example.
However if 1 or another wrong key is pressed then it pulses a piezo.
Thanks for responding
Bruce
If I were debugging your hardware, I'd write my main program so it would display the bits of PressedKey every time that KeyPressed changed from 0 to 1 and then would set KeyPressed back to 0.
Look at functions Main and MonitorKeypad. In MonitorKeypad I obtain the the bits from INA[3..0], and in the main I test the value.
Thanks for responding.
Bruce
The wiring should be okay, but I will double check. So then according to the code above, the piezo should beep if a 1 is pressed?
Bruce
Obviously, you haven't given your complete program. Remember that the variables are likely to be initialized to zero unless you initialize them to something else. That includes PressedKey. What happens if PressedKey is initially zero?
http://forums.parallax.com/showthread.php?128228-Snippet-needed-for-Prop-and-the-MM74C922-keypad-encoder
in main:
As you takeover INA very early and set KeyPressed to 1 at the end on one hand, but check PressedKey and THEN KeyPressed immediately after each other, there is a chance that the if fails because of the timing.
Jon --> I have a completely different situation now. The Proto Board is now in the machine, and I have no to the Serial Terminal. If I should attempt to use this without testing, it appears that n would indicate a value for the pressed key and that getkey returns the value of n. Is there anything else I need to know?
Bruce
When a valid key has been retrieved the beep method (you need to write this) is called -- you can modify this to beep on a specific key.
I don't know what the non-digit key codes represent so the case structure makes those easy to deal with.
Edit: I added a beep method based on your code. It requires constants for the output (SPKR) and the number of ticks per millisecond (MS_001).
I must say that was much more difficult than I would have imagined. In the original posted code the problem was that PressedKey was never initialized so it was equal to 0 and the Main loop exited immediately. In addition to that, getting it to work the way I wanted it to was also difficult. Without explaining all the pitfalls, here is the resulting code which I am ultimately satisfied with.
Don't try this at home unless you are ready for some aggravation
Bruce