On Fri, 11 Feb 2000, Don McKenzie wrote: > "Longley, Jason" wrote: > > > > Hi, has anyone got a Switch debounce routine for a PIC > > 16C84? > > I also require help on a routine that makes sure a switch > > is fully on for about 1/4 of a second before reseting a > > count register to 0 other wise the switch is overlooked > > have a look at: > http://www.dontronics.com/see.html > this covers most of the more common routines used by these micros. After that, look here to see an extremely fast and efficient one: http://www.dattalo.com/technical/software/pic/debounce.html If you dig into the routine, you might be able to solve your 1/4 second switch must stay down problem. 1/4 is a really long time; 250,000 uSec is the way I prefer to look at. So you're probably going to want to sample at a faster rate (than once every 250,000 uS) - 20 mS is not uncommon for this application - and save intermediate samples. Since your looking for a change of states over this period you can do something very simple like this: ; first grab the initial (presumably debounced) state: movf SW_PORT,w movwf initial_sw_state clrf change_detected ; assume no changes ... then in the periodic routine sampling the switches: ; Read the switch and see if it has changed movf SW_PORT,w ;get the current state xorwf initial_sw_state,w ;compare with initial state iorwf change_detect,f ;save any changes ... Then after the quarter second is up: btfsc change_detect,MY_SWITCH_OF_INTEREST_BIT_POSITION goto switch_changed_states ; fall through to here if the switch did not change states ; and clear the count register... Scott