PortB Change Interrupts


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    RBC_INT only triggers on chages with PORTB<7:4>

    For PORTB.0, you would use INT0_INT
    PORTB.1 is INT1_INT

    Each one should have it's own handler, so it automatically knows which pin triggered.
    <br>
    DT

  2. #2


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    RBC_INT only triggers on chages with PORTB<7:4>

    For PORTB.0, you would use INT0_INT
    PORTB.1 is INT1_INT

    Each one should have it's own handler, so it automatically knows which pin triggered.
    <br>
    Actually, I meant to read from pin 4 and 5. That solves half of the problem.

    I have corrected that in my code, still same problem.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Keep in mind that any changes on PORTB.6 or 7 will also trigger an interrupt. It's best to Not Use 6 and 7 for anything else.
    Code:
    Old_Bits VAR BYTE
    New_Bits VAR BYTE
    
    INCLUDE "DT_INTS-18.bas"        ' Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas"     ' Include if using PBP interrupts
    
    ASM
    INT_LIST  macro    ; IntSource,         Label,  Type, ResetFlag?
            INT_Handler    RBC_INT,  _RBC_handler,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    Old_Bits = PORTB
    @    INT_ENABLE   RBC_INT     ;RB Port Change Interrupt
    
    Main:
      Pause 1000
    GOTO Main
    
    '---[RBC - interrupt handler]---------------------------------------------------
    RBC_handler:
        New_Bits = PORTB
        IF (New_Bits.4 <> Old_Bits.4) THEN
            ; -- PORTB.4 has changed -- 
        ENDIF
        IF (New_Bits.5 <> Old_Bits.5) THEN
            ; -- PORTB.5 has changed -- 
        ENDIF
        Old_Bits = New_Bits
    @ INT_RETURN
    DT

  4. #4
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Default Re: PortB Change Interrupts

    Quote Originally Posted by Darrel Taylor View Post
    RBC_INT only triggers on chages with PORTB<7:4>
    <br>
    Darrel, I know this statement was related to a posting for a 18F66J15, but I am trying to use RBC_INT for PortB.2 and PortB.3 on a 16F886. I had a design going on a 18F2550 that used INT2_INT on PortB2 and worked well. However, for reasons I won't go into here I had to move the design to a 16F886 and continue to use PortB.2 and PortB.3 as interrupt inputs from the alarm pins on a DS1337 RTC. I already have PCBs built originally for the 28-pin 18F2550 and am trying to salvage them without trace changes by substituting a 28-pin 16F886 on the same board layout. My question...is there anyway I can use RBC_INT on the PortB.2 and PortB.3 pins of a 16F886 and monitor which pin actually received the interrupt? I have noted your OLDPORT vs NEWPORT technique to do this kind of interrupt isolation and presume I can do this on my 16F886 if RBC_INT will work ont these ports? Can you help me out here?

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: PortB Change Interrupts

    John,

    On the 16F88x's use IOC_INT (Interrupt On Change).

    Set the pins you want to monitor in the IOCB register.
    DT

  6. #6
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Default Re: PortB Change Interrupts

    Quote Originally Posted by Darrel Taylor View Post
    John,

    On the 16F88x's use IOC_INT (Interrupt On Change).

    Set the pins you want to monitor in the IOCB register.
    OK, Darrel...I got rid of the On Change interrupt related statements in my code and set up for the IOC_INT per following.
    Code:
    ;--- Setup Interrupts ----------------------------------------------------
    ASM
    INT_LIST  macro      ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler      IOC_INT,       _Alarm,   PBP,  yes
    ;       INT_Handler      LVD_INT,     _VoltLow,   PBP,  yes
            endm
            INT_CREATE               ; Creates the interrupt processor
    ENDASM
    @    INT_ENABLE   IOC_INT      ; enable IOC interrupts
    
    ' Per DT, DT_INTS already takes care of setting registers
    ' but this code doesn't work unles below registers set as indicated:
        IOCB.2= 1           ' ENABLE IOC INERRUPT ON PORTB.2 (RB2) for Alarm1
        TRISB = %00011100   ' RB2 & RB3 set as RTC Alarm1 & Alarm2 inputs
                            ' PORTB.2 is also an interrupt from manual switch GND
                            ' PORTB.4 is set for input as A/D Channel 11
        WPUB = 0            ' DISABLE all PortB pull-ups
        CM1CON0 = 0         ' DISABLE COMPARATORS
        CM2CON0 = 0         ' DISABLE COMPARATORS
    However I get the following assembler errors which made me go into the .lst file to see where the problem was but I can't locate what is causing these errors. Can you tell me?
    Warning[205] C:\PBP26\ELLIS_CODES\RTC\16F886\0SETDS1337CLOCK.AS M 364 : Found directive in column 1. (endm)
    Warning[207] C:\PBP26\ELLIS_CODES\RTC\16F886\0SETDS1337CLOCK.AS M 551 : Found label after column 1. (INT_ENABLE)
    Error[122] C:\PBP26\ELLIS_CODES\RTC\16F886\0SETDS1337CLOCK.AS M 551 : Illegal opcode (IOC_INT)

  7. #7
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Default Re: PortB Change Interrupts

    Discovered I had forgotten to uncomment the follwoing statements required for using DT_INTS.

    INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas" ' Include if using PBP high priority interrupts

    However, after fixing that however, I still have the following assembly errors I can't figure out:
    Error[101] C:\PBP26\ELLIS_CODES\RTC\16F886\0SETDS1337CLOCK.AS M 790 : ERROR: ("INT_Handler" - Interrupt Flag ( INTCON,IOCIF ) not found.)
    Error[101] C:\PBP26\ELLIS_CODES\RTC\16F886\0SETDS1337CLOCK.AS M 790 : ERROR: ("INT_ENABLE" - Interrupt Flag ( INTCON,IOCIF ) not found.)

  8. #8
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Default Re: PortB Change Interrupts

    Looked in .lst file for the above errors and found both.

    This one is strange because it indicates INTERRUPT_handler was not labeled with PBP...it was. Can you tell me from this why the error?
    Code:
                      M         if (PBP  == PBP)                     ; If INT handler is PBP
                              M           ifdef ReEnterUsed
                              M             btfsc  _Vars_Saved
                              M             goto   AfterSave
                              M             GetAddress  AfterSave, _RetAddr  
                              M             L?GOTO  _SavePBP                 ; Save PBP system Vars
                              M             LABEL?L  AfterSave
                              M           else
                              M             error ReEnterPBP must be INCLUDEd to use PBP type interrupts
                              M           endif
                              M         endif
                              M         GetAddress  AfterUserRoutine, _RetAddr   ; save return address
                              M         L?GOTO   _Alarm                      ; goto the users INT handler
                              M         LABEL?L AfterUserRoutine
                              M 
                              M         if (yes   == YES)
                              M           CHK?RP   INTCON
                              M           bcf      INTCON,  IOCIF          ; reset flag (if specified)
                              M         endif
                              M       else
                              M         INT_ERROR  "INT_Handler"
    Error[101]  : ERROR: ("INT_Handler" -  Interrupt Flag ( INTCON,IOCIF ) not found.)
                              M     error "INT_Handler" -  Interrupt Flag ( INTCON,IOCIF ) not found.
                              M       endif
    For this error I can't see why the FlagBit wasn't set. Can you explain this error to me?
    Code:
                          00989     INT_ENABLE   IOC_INT      ; enable IOC interrupts
                              M       ifdef FlagBit
                              M         ifdef INT_ENABLECLEARFIRST
                              M           if (INT_ENABLECLEARFIRST == 1)       ; if specified
                              M             MOVE?CT 0, INTCON,  IOCIF          ;   clear the flag first
                              M           endif
                              M         endif
                              M         MOVE?CT  1, INTCON,    IOCIE           ; enable the INT source
                              M       else
                              M         INT_ERROR  "INT_ENABLE"
    Error[101]  : ERROR: ("INT_ENABLE" -  Interrupt Flag ( INTCON,IOCIF ) not found.)
                              M     error "INT_ENABLE" -  Interrupt Flag ( INTCON,IOCIF ) not found.
                              M       endif

  9. #9
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: PortB Change Interrupts

    Sorry, it is RBC_INT on that chip. But you still use the IOCB register like other chips with IOC_INT.

    Microchip does things different everytime.
    DT

Similar Threads

  1. PICs can do more if use others than delays instructions
    By hardcore in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 24th February 2010, 19:52
  2. Returning from Int on PortB change
    By sheryl in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th December 2008, 18:09
  3. shifting problem
    By helmut in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 31st August 2007, 06:11
  4. Output PIC module
    By freelancebee in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th September 2005, 20:10
  5. Can anyone help a beginner in a struggle?
    By douglasjam in forum mel PIC BASIC
    Replies: 1
    Last Post: - 5th May 2005, 23:29

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts