switch (and other noisey input) functions are provided in the libraries

LIB/debounce_lib.bas


 
debounce_init initialise the debounce driver
debounce_queue_service invoke the debounce driver
read_switch read the last stable state of a switch
read_porta read PORTA debouncing noisey inputs
read_portb read PORTB debouncing noisey inputs