Continue to Site

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.

  • 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.

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).
 
I had a look and i'm wondering if it ould be possible to rewrite the code so i can use it on a 12f683 .. i won't be using that many switches but i would need 2 or 3..



I guess i will need the pic to recodt the button state and continue operations , i haev looked for example files but i haven't found any..

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.

Latest threads

Back
Top