Debouncing the SX/B Example of Keypad in the help file?
Brian Carpenter
Posts: 728
Can anyone point me in the right direction for debouncing the kepad example in the SX/B help file
This is the pertinate code snippet i believe.· I know that i need to sample the value and make sure that i get the same value for atleast a 2 cycles.·
Any body done this before?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
GET_KEY: tmpB1 = 0 ' reset keyboard value Keys = %0000_0111 ' activate first row TRIS_Keys = %1111_0000 ' refresh IO state PLP_Keys = %0000_1111 ' pull-up input pins FOR tmpB2 = 1 TO 4 ' scan four rows IF Col1 = Yes THEN EXIT ' check buttons on column INC tmpB1 ' update key value IF Col2 = Yes THEN EXIT INC tmpB1 IF Col3 = Yes THEN EXIT INC tmpB1 IF Col4 = Yes THEN EXIT INC tmpB1 Keys = Keys >> 1 ' select next row Keys = Keys | %0000_1000 ' clear previous row NEXT RETURN tmpB1
This is the pertinate code snippet i believe.· I know that i need to sample the value and make sure that i get the same value for atleast a 2 cycles.·
Any body done this before?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
Comments
Although not the exact subroutine he mentions, there is similar source code is in the TUT019.src file in the downloads section.
It's basically checking the bit, delaying (typ 20-30msec), and see if it's still pressed after the delay.
Here's an interesting link with some higher level examples.
http://www.ganssle.com/debouncing.pdf
...or Google "switch debounce software" [noparse]:o[/noparse])
Rodney
I would try something like this:
You will need to declare i and FirstKey as byte variables and KeyChanged as a bit variable.
- Sparks
Here is how I would do it. Adjust the PAUSE value as needed.·NOTE this is untested code [noparse];)[/noparse]
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
"People who are willing to trade their freedom for·security deserve neither and will lose both." Benjamin Franklin
·
I have used Bean's Code and also Sparks - R - Fun
I cant get the desired results
What i am trying to make it do:::
If TheKey = LastKey loop until it does not As soon as it does not.· Return the new value that does not match
For instance.... if no key is pressed, TheKey will be 16 and will continue to be 16 while nothing is pressed.
Now this is where it gets a little tricky
As soon as a key is pressed. Lets say 3.··· The 'TheKey' value has changed but i dont want it to be returned until 'TheKey' = 16 again. meaning that the button was released.
·So once the key is released it will return '3' in the 'TheKey' value.· and then it will continue returning 16 until another key is RELEASED
Any ideas on how this can be done?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
Post Edited (altitudeap) : 11/6/2006 5:29:40 AM GMT
Try this...
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
"People who are willing to trade their freedom for·security deserve neither and will lose both." Benjamin Franklin
·
This is what i now have.
Man i love the SX Debug feature.· As i press and hold the button i can see that the SX has noticed the state change of the switch and then just as i release it, it DEC the value in associated register.· What i cant seem to make it show me is the··Value for VendStatus.· Should i be able to see that in the register somewhere.· Maybe my code is not making the bit in the associated location go high.·· ie if the value in register 2 goes to 0 the Value in VendStatus should be 0000_0000_0000_0100
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!