pic12F683 Button de-bouncing.

Status
Not open for further replies.
In the code snippets is the routine I wrote/use. It's absolute, not probabilistic like RC damping is. The active/inactive count values allow tuning to switch type. It's in Freescale assembler, but should have enough comments to understand the logic. I wrote it on having had Way enough trouble with other debounce methods. G.H... <<<)))
 
I'm kind of new to PIC's and programming but i'm sure i can figure out the code and be able to adjust it to fitt my needs
 
Mike McLaren wrote this code it really test the switch state

Code:
'
'  swnew  __----____----_________    new sample (positive logic)
'  swold  ___----____----________    switch state latch
'  delta  __-___-___-___-________    changes, press or release
'  newhi  __-_______-____________    filter out "release" bits
'  flags  ___--------____________    toggle flag bits for main
'
Interrupt TMR2_Interrupt(1)        ' 8-msec Timer 2 interrupts
    TMR2IF = 0                     ' clear TMR2 interrupt flag
    swnew = Not PORTB              ' sample active lo switches
    delta = swnew Xor swold        ' changes, press or release
    newhi = delta And swnew        ' filter out "new release" bits
    flags = flags Xor newhi        ' toggle flag bits for main
    swold = swnew                  ' update switch state latch
End Interrupt
 
Way back in post #10 the OP asked if 1uF across the switch would be ok with a 10k pull-up. IMHO the simple answer is 'yes' (but in the light of the other posts there may be better ways).
 

The code is asm, u don't have to rewrite anything. Whether u want 2 or 3 or 8 switches the code is the same and the execution is the same. Note the commented out lines in the beginning that show how to assign a switch on any pin to a 8 bit byte for parallel processing of up to 8 switches.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…