• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
Resource icon

Debounce Both States / Asm / Freescale 908 2011-06-13

I wrote this for toggle switches. It first looks for a change of state. If seen, it counts loops to be constantly in that state, any reversal reloads counter. Exit is by loop countout: consistent state change OR too many reloads. In effect, it soft delays out the bounce. The loop counts set debounce delay and excessive reload countout. My std rules: free to use, But put "uMax/Sarge" associated with it somewhere. TNX <<<)))

dbict   equ     $10             ;debounce Inactive count
dbact   equ     $20             ;debounce Active count
swtank  ds.b    1               ;btns/sws input tank
swprev  ds.b    1               ;previous sw state for debouncing

Sw_In:  psha
        mov	PTAD,swtank          ;get current Sw state
        lda     swtank
        cmp     swprev          ;current=previous: Xit
        beq     SWIXit
        mov     #dbict,dbIctr   ;load debounce Inactive counter
SwDbLL: mov     #dbact,dbActr   ;load debounce Active counter
        mov     swtank,swprev   ;put current->previous
        dbnz    dbIctr,SwDbLD   ;only load active debounce N times
        bra     SWIXit          ;Not full active == off
SwDbLD: bsr     SwRead          ;get current Sw state
        lda     swtank
        cmp     swprev          ; :: previous
        bne     SwDbLL          ;Any bounce to different state resets counter
        dbnz    dbActr,SwDbLD   ;must stay on for #dbact counter loops
SWIXit: pula
First release
Last update
0.00 star(s) 0 ratings

More resources from OlPhart

Latest threads

EE World Online Articles