Debounce is a port pin connected to a switch.


DEBOUNCE Px.y , state , label [ , SUB]


Px.y A port pin like P1.0 , to examine.
State 0 for jumping when Px.y is low , 1 for jumping when Px.y is high
Label The label to GOTO when the specified state is detected
SUB The label to GOSUB when the specified state is detected
When you specify the optional parameter SUB, a GOSUB to label is performed instead of a GOTO.
The DEBOUNCE statements wait for a port pin to get high(1) or low(0).
When it does it waits 25 mS and checks again (eliminating bounce of a switch)
When the condition is still true and there was no branch before, it branches to the label.
When DEBOUNCE is executed again, the state of the switch must have gone back in the original position before it can perform another branch.

Each DEBOUNCE statement which use a different port uses 1 BIT of the internal memory to hold it's state.

What also should be mentioned is that P2.2-P2.7 and P3 have internal pull up resistors. This can affect the debounce statement. With these port pins, debounce is best to be used as: Debounce P1.1, 0, Pr [, sub ] , as it will not require an external pull up resistor.

See also


' demonstrates DEBOUNCE

CONFIG DEBOUNCE = 30 'when the config statement is not used a default of 25mS will be used
'Debounce P1.1 , 1 , Pr 'try this for branching when high(1)
Debounce P1.0 , 0 , Pr,SUB
' ^----- label to branch to
' ^---------- branch when P1.0 goes low(0)
' ^---------------- examine P1.0

'when P1.0 goes low jump to subroutine Pr

'P1.0 must go high again before it jumps again
'to the label Pr when P1.0 is low


Print "P1.0 was/is low"