Hey all;
I've built a switching unit around a PIC16F737. There are 14 switches, each going to a different pin on the PIC. Most of the time, things work fine, but every once in a while a switch may stick - IOW, it gets pressed, the proper result is obtained, but all the other switches are non-responsive. Most of the time I can get everything to work again by pressing the 'stuck' switch again, but sometimes I have to power down and restart. Also, I've found that I can make the switch 'stick' if I press it gently and release it very slowly (although it may stick under normal pressing conditions as well). It's possible that my switches suck, but I'm wondering if it's a code thing. Here's my switch debounce code:
dbcount and dc1 are counters. Can anyone see anything wrong with this? I'm pretty sure it's actually working, although I've been having doubts as I look more at it. For instance, if I held the switch down, wouldn't the PIC get caught in this loop and never get to the actual instructions?
Thanks
I've built a switching unit around a PIC16F737. There are 14 switches, each going to a different pin on the PIC. Most of the time, things work fine, but every once in a while a switch may stick - IOW, it gets pressed, the proper result is obtained, but all the other switches are non-responsive. Most of the time I can get everything to work again by pressing the 'stuck' switch again, but sometimes I have to power down and restart. Also, I've found that I can make the switch 'stick' if I press it gently and release it very slowly (although it may stick under normal pressing conditions as well). It's possible that my switches suck, but I'm wondering if it's a code thing. Here's my switch debounce code:
Code:
db_down movlw 0x1A ;max count = 20ms/768us = 26 = 0x1A
movwf dbcount
clrf dc1 ;reset dc1
dn_dly incfsz dc1,f ;delay 256x3 = 768us
goto dn_dly
btfsc PORTE,3 ;if button up (RE3 hi),
goto db_down ; restart count
decfsz dbcount,f ;else repeat until max count is reached
goto dn_dly
dbcount and dc1 are counters. Can anyone see anything wrong with this? I'm pretty sure it's actually working, although I've been having doubts as I look more at it. For instance, if I held the switch down, wouldn't the PIC get caught in this loop and never get to the actual instructions?
Thanks