PIC interrupt

Thread Starter

sportsfan27

Joined Jan 29, 2009
43
I need to create an interrupt with a PIC microcontroller so that when a pin is "high" the controller will stop what it is doing and do something else. How do I code this? Thanks for any help
 

walid el masry

Joined Mar 31, 2009
133
as you know this is the pic16f876A i wrote the code for it and that is the chip



you have just 1 external interrupt at pin RB0 in port B with yellow
the code is for when applying high on RB0 it make an interrupt and go to execute it and return again to the main pragram
Rich (BB code):
    LIST P=16F876
    #INCLUDE<P16F876.INC>
    __CONFIG    _CP_OFF&_LVP_OFF&_BODEN_OFF&_PWRTE_ON&_WDT_OFF&_XT_OSC
    ORG 0X00
    GOTO INTIATION
    ORG 0X04
;INTERRUPT SUBRUTINE
    NOP                              ;any thing you want
    BCF INTCON,INTF        ;STOP THE INTERRUPT
    RETFIE
INTIATION
;INTERRUPT INTIATION
    MOVLW 0X90
    MOVWF INTCON           ;Enable External Interrupt & Enable Global Interrupt Gate
    MOVLW 0X47
    MOVWF OPTION_REG  ;Intrrupt Start At Falling Edge
;INTIATION PORTS
    MOVLW 0X01
    TRIS PORTB
START
NOP                                                 ;the main program
GOTO START
END
from the code we know that i used the instruction RETFIE
which mean that i want return to the exact place i was in before executing the interrupt
but if want to goto any where else you can ignore using this instruction and just write instead

Rich (BB code):
BSF INTCON,GIE          ;ALLOW OTHER INTERRUPT TO BE ABLE OCCUR
GOTO HELL                 ;joking :) , you can chose any place you want
note that it is the same for
pic16f876
pic16f876a
pic16f873
pic16f873a
thats all
END OF Replay :) :) :) :)
 
Top