I'm a sucker for simplicity.
Try this;
Code:
GPIO.4 ----/\/\/\---|<|----+5V.
LED
10K
GPIO.0 --|--/\/\/\---+5V
|--switch---GND.
When you press the switch it grounds GPIO.0.
Code:
@ device pic12F629, intrc_osc_noclkout, wdt_on, mclr_off, protect_off
DEFINE OSCCAL_1K 1
DEFINE OSC 4
RELAY VAR GPIO.4 ' relay output
Pswitch VAR GPIO.0 ' switch input
TRISIO = %00000001 ' GPIO.0 input, rest outputs
WPU = 0 ' input pull-ups disabled
CMCON = 7 ' disable comparators
PAUSE 10 ' POR delay
MAIN:
RELAY = ! Pswitch ' Relay pin = the opposite of Psiwtch pin
GOTO MAIN
END
Does this work?
Bookmarks