You could either use a timer interrupt, or poll the switch in your main program loop. If the switch is pressed, decrement a counter. If it isn't reload the counter with a start value. When the counter reaches zero, set a flag that your main program can read. If you use this in a timer interupt you will need to choose suitable values for the TMR0 pre-scaler. The debounce counter will have also to be pre-loaded with a suitable value in order to get your 1/4 second interval. If your main loop is very fast, you may need to use a 16 bit counter.
You may also need to change the logic of the switch test, depending on how you've wired the switch. This example assumes the switch grounds the port pin when pressed.
Haven't actually tested this, so usual disclaimers apply....
btfss PORTB,SWITCH ; obviously put your own port and bit number in here
goto pressed ; switch is pressed
movlw 127 ; switch is not pressed, reload counter with your value
movwf counter
bcf flags,SWITCH ; clear the switch flag
goto switch_done
pressed
decfsz counter ; decrement the counter
goto switch_done ; not reached zero yet
bsf flags,SWITCH ; reached zero so set flag
switch_done
; rest of program
Cheers
Mike
-----Original Message-----
From: Longley, Jason [SMTP:Jason.Longley@UWE.AC.UK]
Sent: Friday, May 07, 1999 10:59 AM
To: PICLIST@MITVMA.MIT.EDU
Subject: Switch Debounce Routine
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
----------------------------------------
Longley, Jason
Email: Jason.Longley@uwe.ac.uk
"University of the West of England"