Difficulty with multi-key debounce Getkey subroutine
Torquewrench
Posts: 28
I'm using a modified version of the menu software from NV51 except with direct inputs, and I cannot seem to get the buttons to work. Here are the relevant excerpts from my code and my whole code is attached. Can anyone see the problem?
Thank you,
Phil
' Stamp (Function) Connection
'
' pin 1 SOUT J1:6
' pin 2 SIN J1:5
' pin 3 ATN J1:4
' pin 4 VSS J1:3
' pin 5 P0 broken
' pin 6 P1 J1:2 Tourney Lock
' pin 7 P2 open
' pin 8 P3 J3:5 Trigger
' pin 9 P4 J3:3 Safety
' pin 10 P5 J3:1 Valve
' pin 11 P6 J2:9 Mode
' pin 12 P7 J2:7 Select
' pin 13 P8 open
' pin 14 P9 open
' pin 15 P10 J2:6 E
' pin 16 P11 J2:5 RS
' pin 17 P12 J2:4 DB4
' pin 18 P13 J2:3 DB5
' pin 19 P14 J2:2 DB6
' pin 20 P15 J2:1 DB7
' pin 21 Vdd +5V out
' pin 22 RES open
' pin 23 Vss Ground
' pin 24 Vin +9V in
'Constants
Trig_Swt CON 3 ' Trigger switch
Safe_Swt CON %00010000 ' Safety switch
Key_Mode CON %01000000 ' Mode Button
Key_Sel CON %10000000 ' Select Button
E CON 10 ' LCD Enable pin (1 = enabled)
RS CON 11 ' Register Select (1 = char)
'Variables
key VAR Byte ' button/switch input variable
key_In VAR INL ' shoes state of input buttons
Init:
DIRS = %1111110000100000 ' defines outputs, 1 = output
OUTS = $0000 ' clear the pins (hex $0000 is equivalent to %0000000000000000
GetKey:
key = %11010000 ' assume all pressed
FOR loop = 1 TO 5 ' test five times
key = key & ~key_In ' test against new input
PAUSE 5 ' wait 5 ms between tests
NEXT
RETURN
Thank you,
Phil
' Stamp (Function) Connection
'
' pin 1 SOUT J1:6
' pin 2 SIN J1:5
' pin 3 ATN J1:4
' pin 4 VSS J1:3
' pin 5 P0 broken
' pin 6 P1 J1:2 Tourney Lock
' pin 7 P2 open
' pin 8 P3 J3:5 Trigger
' pin 9 P4 J3:3 Safety
' pin 10 P5 J3:1 Valve
' pin 11 P6 J2:9 Mode
' pin 12 P7 J2:7 Select
' pin 13 P8 open
' pin 14 P9 open
' pin 15 P10 J2:6 E
' pin 16 P11 J2:5 RS
' pin 17 P12 J2:4 DB4
' pin 18 P13 J2:3 DB5
' pin 19 P14 J2:2 DB6
' pin 20 P15 J2:1 DB7
' pin 21 Vdd +5V out
' pin 22 RES open
' pin 23 Vss Ground
' pin 24 Vin +9V in
'Constants
Trig_Swt CON 3 ' Trigger switch
Safe_Swt CON %00010000 ' Safety switch
Key_Mode CON %01000000 ' Mode Button
Key_Sel CON %10000000 ' Select Button
E CON 10 ' LCD Enable pin (1 = enabled)
RS CON 11 ' Register Select (1 = char)
'Variables
key VAR Byte ' button/switch input variable
key_In VAR INL ' shoes state of input buttons
Init:
DIRS = %1111110000100000 ' defines outputs, 1 = output
OUTS = $0000 ' clear the pins (hex $0000 is equivalent to %0000000000000000
GetKey:
key = %11010000 ' assume all pressed
FOR loop = 1 TO 5 ' test five times
key = key & ~key_In ' test against new input
PAUSE 5 ' wait 5 ms between tests
NEXT
RETURN
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Get_Key:
· key = %11111010··········' assume all pressed
· FOR idx = 1 TO 5········ ' test five times
·· ·key = key & ~key_In··· ' test against new input
·· ·PAUSE 5·············· ·' wait 5 ms between tests
· NEXT
· RETURN
Note that I changed your variable called "loop" to "idx" -- this prevents a keyword conflict with PBASIC 2.5.· When the subroutine is done there will be a 1 in the bits of "key" that had a button pressed through the entire routine.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Thank you,
Phil
DEBUG BIN INB
I get only 111 in the debug window, so I think something might be wrong with P7. Is this a good test?
Thanks,
·· It's certainly possible that something happened to it somewhere.· There's a schematic in the Help file for the editor for connecting a pushbutton, Active-High or Active-Low.· Try wiring up P7 like that, then try the test code included in that page under Example (Top right of page) and make sure you set the pin for P7.· That should tell you in the pin is working as an input.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Thanks,
Phil