Maker Pro
Maker Pro

PIC interrupts

D

David M

Jan 1, 1970
0
Hi,

I've written a program for a PIC12F675 that monitors the GP2 pin.

When the input changes it generates an interrupt.

However my interrupt code only gets called intermittently.

Can anyone give me a definitive list of the registers I need to set to
get this working properly.

Regards

David
 
B

Bruce

Jan 1, 1970
0
I've written a program for a PIC12F675 that monitors the GP2 pin.
When the input changes it generates an interrupt.

However my interrupt code only gets called intermittently.

Can anyone give me a definitive list of the registers I need to set to
get this working properly.

Regards

David

Are you turning off A/D & comparators..?

Here's a simple program my son wrote when first experimenting with the 12F.
The Init sub-routine shows setup for GPIO.2 int on change. Hope this helps.

regards,

-Bruce
http://www.rentron.com

list p=12F675 ; list directive to define processor
#include <p12f675.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file

__CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT

#define BANK1 banksel 0x80 ;Select BANK1
#define BANK0 banksel 0x00 ;Select BANK0

cblock 0x20
INNER
OUTER
LOOPS
endc

ORG 0x000 ; processor reset vector
goto Init ; go to beginning of program

ORG 0x004 ;Interrupt vector location
goto Isr

Main
nop
goto Main

Init
call 0x3FF ;retrieve factory calibration value
BANK1
movwf OSCCAL ;update register with factory cal value
BANK0
clrf GPIO ;Clear Port
BANK1
clrf ANSEL ;PIC12F675 Only
movlw 0x04 ;GPIO.2 input, rest outputs
movwf TRISIO ;Set GPIO.2 = input
clrf VRCON ;Vref Off
BANK0
movlw 0x07
movwf CMCON ;Comparator Off
BANK1
movlw b'10000000' ;Pull-ups off
movwf OPTION_REG
bsf IOCB,2 ;Interrupt on Pin Change For GP2
bsf INTCON,GPIE ;Interrupt on Change Enabled
bcf INTCON,GPIF ;Clear Interrupt On Change Flag
bsf INTCON,GIE ;Turn on Global Interrupts
BANK0
goto Main

Isr
BANK0
Wait
btfss GPIO,2 ;wait for button release/debounce
goto Wait
movlw 0x04
movwf LOOPS
bsf GPIO,0 ;LED on

Loop
clrf OUTER
clrf INNER
D1
decfsz INNER,f
goto D1
D2
decfsz OUTER,f
goto D1
decfsz LOOPS,f
goto Loop

bcf GPIO,0 ;LED off
movf GPIO,w ;Clear mismatch Condition
BANK1
bcf INTCON,GPIF ;Clear Interrupt On Pin Change Flag
retfie ;Return from interrupt

end
 
Top