DEBOUNCE

Top  Previous  Next

Action

Debounces a port pin connected to a switch.

 

 

Syntax

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

 

 

Remarks

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 will wait 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 uses 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

CONFIG DEBOUNCE

 

 

Example

'-----------------------------------------------------

'                 DEBOUN.BAS

'           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

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

 

Debounce P1.0 , 1                       'no branch

Debounce P1.0 , 1 , Pr                 'will result in a return without gosub

End

 

Pr:

Print "P1.0 was/is low"

Return