1. sportsfan27

    Thread Starter Active Member

    Jan 29, 2009
    43
    0
    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
     
  2. russ_hensel

    Well-Known Member

    Jan 11, 2009
    818
    47
    use the rb0 interrupt, see the data sheet.
     
  3. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    Which compiler and programming language are you using?
     
  4. walid el masry

    Active Member

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

    [​IMG]

    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
    Code ( (Unknown Language)):
    1.  
    2.     LIST P=16F876
    3.     #INCLUDE<P16F876.INC>
    4.     __CONFIG    _CP_OFF&_LVP_OFF&_BODEN_OFF&_PWRTE_ON&_WDT_OFF&_XT_OSC
    5.     ORG 0X00
    6.     GOTO INTIATION
    7.     ORG 0X04
    8. ;INTERRUPT SUBRUTINE
    9.     NOP                              ;any thing you want
    10.     BCF INTCON,INTF        ;STOP THE INTERRUPT
    11.     RETFIE
    12. INTIATION
    13. ;INTERRUPT INTIATION
    14.     MOVLW 0X90
    15.     MOVWF INTCON           ;Enable External Interrupt & Enable Global Interrupt Gate
    16.     MOVLW 0X47
    17.     MOVWF OPTION_REG  ;Intrrupt Start At Falling Edge
    18. ;INTIATION PORTS
    19.     MOVLW 0X01
    20.     TRIS PORTB
    21. START
    22. NOP                                                 ;the main program
    23. GOTO START
    24. END
    25.  
    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

    Code ( (Unknown Language)):
    1.  
    2. BSF INTCON,GIE          ;ALLOW OTHER INTERRUPT TO BE ABLE OCCUR
    3. GOTO HELL                 ;joking :) , you can chose any place you want
    4.  
    note that it is the same for
    pic16f876
    pic16f876a
    pic16f873
    pic16f873a
    thats all
    END OF Replay :) :) :) :)
     
Loading...