Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
12/04/02 03:31
Read: times


 
#33717 - RE: switch debouncing
I've made a LCD Clock with your ideas months ago. It assume the first changes as user interaction. Of course till now I don't see there is any noise causing the problem. (of course the button is in the box~)
Here's the code, hopefully it helps :) Sorry for lack of comment~
and I'm still a newbie in electronics~

; Readin Port. Buttons are actively pulled low
DeB_Port        equ     P2
; Constant
DeB_Mask        equ     00001111b
; Constant
DeB_NoChange_Value      equ     11110000b
; Variables
DeB_PState      equ     02ah
DeB_CountDown   equ     02bh
DeB_IgnoreMask  equ     02ch
DeB_Result      equ     02dh
DeB_ThisTurn    equ     02eh

Init:
        mov     DeB_PState,#0ffh
        mov     DeB_IgnoreMask,#0
........
........
MainProgram:
        call    Debounce
        mov     A,DeB_Result
        xrl     A,#DeB_NoChange_Value
        jz      NoButton
                ; Button Pressed
                mov     A,DeB_Result
                cpl     A
                anl     A,DeB_ThisTurn
                anl     A,#00000100    ; If you the changes on the third button only...
                jz      NotThirdButton...

........
        NoButton: ;NoButton Pressed
...........
Debounce:
        push    ACC
        push    PSW
        push    00h
        orl     DeB_Port,#DeB_Mask
        mov     A,DeB_IgnoreMask
        cpl     A
        anl     A,DeB_Port
        anl     A,#DeB_Mask
        mov     00h,A
        mov     A,DeB_IgnoreMask
        cpl     A
        anl     A,DeB_PState
        anl     A,#DeB_Mask
        xrl     A,00h
        jz      DeB_NoChange
        ; Have Change
        mov     DeB_ThisTurn,A

        mov     A,DeB_IgnoreMask
        cpl     A
        anl     A,00h
        mov     00h,A

        mov     A,DeB_PState                ; Return the New Value
        anl     A,DeB_IgnoreMask
        orl     A,00h

        mov     DeB_Result,A
        mov     DeB_PState,A
        mov     DeB_CountDown,#50

        mov     A,DeB_ThisTurn              ; Update the Mask aginst Change
        orl     A,DeB_IgnoreMask
        mov     DeB_IgnoreMask,A
        jmp     DeB_Done
    DeB_NoChange:
        mov     DeB_Result,#DeB_NoChange_Value
        mov     A,DeB_CountDown
        jz      DeB_Done
        djnz    DeB_CountDown,DeB_Done
        mov     DeB_IgnoreMask,#0           ; CoolDown Finish
    DeB_Done:
        pop     00h
        pop     PSW
        pop     ACC
        ret


List of 32 messages in thread
TopicAuthorDate
switch debouncing            01/01/70 00:00      
RE: switch debouncing            01/01/70 00:00      
RE: switch debouncing            01/01/70 00:00      
RE: switch debouncing            01/01/70 00:00      
RE: switch debouncing            01/01/70 00:00      
RE: switch debouncing            01/01/70 00:00      
RE: switch debouncing            01/01/70 00:00      
RE: switch debouncing            01/01/70 00:00      
RE: switch debouncing            01/01/70 00:00      
RE: switch debouncing            01/01/70 00:00      
RE: switch debouncing - Jon            01/01/70 00:00      
RE: switch debouncing - Jon            01/01/70 00:00      
RE: switch debouncing            01/01/70 00:00      
RE: switch debouncing - digital cameras            01/01/70 00:00      
RE: switch debouncing - digital cameras            01/01/70 00:00      
RE: switch debouncing            01/01/70 00:00      
RE: switch debouncing            01/01/70 00:00      
RE: switch debouncing - digital cameras            01/01/70 00:00      
RE: switch debouncing - Jon            01/01/70 00:00      
RE: switch debouncing            01/01/70 00:00      
RE: switch debouncing            01/01/70 00:00      
RE: switch debouncing            01/01/70 00:00      
RE: switch debouncing            01/01/70 00:00      
RE: switch debouncing            01/01/70 00:00      
RE: switch debouncing            01/01/70 00:00      
RE: switch debouncing            01/01/70 00:00      
RE: switch debouncing            01/01/70 00:00      
RE: switch debouncing            01/01/70 00:00      
RE: switch debouncing            01/01/70 00:00      
RE: switch debouncing            01/01/70 00:00      
RE: switch debouncing            01/01/70 00:00      
RE: switch debouncing            01/01/70 00:00      

Back to Subject List