I've been working with this for a couple days, and can't get it to behave properly. This minimal code should use interrupts to simply set the output state based on the input state. I've tried this without interrupts (basically just using the interrupt handler as the main loop) and it works fine, so I know my inputs and outputs are right.
Any insight as to why this doesn't work will be greatly appreciated!
Any insight as to why this doesn't work will be greatly appreciated!
Code:
#define BUTTON_BIT 2
#define OUTPUT_BIT 4
LIST p=12F629
include "P12F629.inc"
__config b'10000110000100'
org 0x0000
goto Setup
org 0x0004
goto Interrupt
Setup
;turn comparators off
movlw 0x07
movwf CMCON
bsf STATUS, RP0 ;Bank 1
;Specify input ports
clrf TRISIO
bsf TRISIO, BUTTON_BIT
;Enable pull up on input
clrf WPU
bsf WPU, BUTTON_BIT
;Set interrupt on change for input
clrf IOC
bsf IOC, BUTTON_BIT
;Callibrate internal oscillator
call 3FFh
movwf OSCCAL
;Set options (enable global weak pull ups)
movlw b'01111111'
movwf OPTION_REG
bcf STATUS, RP0 ;Bank 0
;Read input state
movf GPIO,w
;Enable global interrupts and GPIO change interrupt
bsf INTCON, GPIE
bsf INTCON, GIE
;infinite loop
goto $
Interrupt
;Clear interrupt flag
bcf INTCON,GPIF
;Set output based on input state
btfss GPIO,BUTTON_BIT
goto $+3
bsf GPIO,OUTPUT_BIT
goto $+2
bcf GPIO,OUTPUT_BIT
retfie
end