A while back, I wrote a very simple, reliable switch debouncing routine similar to what I've posted below. Problem is, I cannot find or locate that code and would like to re-create it. What I've got below is close but not reliable. If I remember correctly, there should have been 4 groups of 2 IF,THEN,ENDIF groups. Can anyone lend a hand?
tester var bit
switch var byte
TRISA.5 = %1 'Sets TRISA.5 to an input
TRISC.5 = %0 'Sets TRISC.5 to an output
Tester = 0
switch = 0
LOOP:
if (PORTA.5 = 0) and (tester = 0) THEN
tester = 0
endif
if (PORTA.5 = 1) and (tester = 0) THEN
tester = 1
switch = switch + 1
endif
if (PORTA.5 = 1) AND (tester = 1) then
tester = 1
endif
if (PORTA.5 = 0) AND (tester = 1) then
tester = 0
endif
IF SWITCH > 1 THEN
SWITCH = 0
ENDIF
if switch = 0 then
LOW PORTC.5
ENDIF
IF switch = 1 then
HIGH PORTC.5
ENDIF
Goto loop