In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Zoot wrote: e.g. [code] :startdebounceroutine CLR buttonCount :again MOV buttonPrev, buttonState ' load previous button state MOV W, #0 ' presume active low, but make 1 if button pressed SB ButtonPin MOV W, #1 MOV buttonState, W XOR W, buttonPrev SZ CLR buttonCount ' if unstable, reset debounce count JNZ, @:again ' if it's unstable, repeat INC buttonCount ' how many times stable CJB buttonCount, #100, @:again ' adjust depending on clock frequency, switch noise, etc. This is 500us debounce or so at 20mhz, not much ' now the current debounced state of the button is in buttonState.... JNB buttonState.0, @:nolight :light SETB LedPin MOV tmpB1, #200 ' these two numbers depend on clock speed, easier in an ISR, really MOV tmpB2, #200 :pauseloop TEST tmpB2 JNZ, :dec TEST tmpB1 JZ, @:nolight :dec SUB tmpB1, #1 SUBB tmpB2, /C JMP @:pauseloop :nolight CLRB LedPin :done [/code] ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=429713#m429774 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2010 (http://www.dotNetBB.com)