Hi Rob,
Welcome to the forum! As you can imaging there are several ways to do this (and most other things). Amoque shows you one, here's another (which also tries to take care of the debounce):
Code:
LED VAR GPIO.0
Switch VAR GPIO.1
ANSEL = 0 ' No analog inputs
CMCON = 7 ' Comparators disabled
TRISIO = %11111110 ' GPIO.0 as output
Main:
IF Switch = 1 THEN ' If the button is pressed...
TOGGLE LED ' ...we toggle the LED.
Pause 20 ' Then we wait for contact bounce on make to die, may need tweaking
WHILE Switch = 1 : WEND ' Then we wait for the user to actually release the button
Pause 20 ' Finally we wait for contact bounce on release to die, may need tweaking
ENDIF
Goto Main
/Henrik.
Bookmarks