Thread: PIC16F73 - RB Port Change Interrupt

  1. #1
    Registered User
    Join Date
    Sep 2015
    Posts
    5

    PIC16F73 - RB Port Change Interrupt

    I'm trying to practice using interrupts so I can make use of them when developing PIC programs. Here I'm using the 'RB Port Change Interrupt' with the 'RB Port Change Flag Bit'.

    There is no need to set the IOCB register here, because my pic16f73 doesn't support it.

    Here's the problem:
    When I execute the program and simulate an RB input, the flag bit goes high a successfully enters the Interrupt section. However, at the end of the Interrupt function the 'RBIF=0' command doesnt work, and I cannot enter the interrupt again when simulating an RB input.

    Please help.
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Code:
    void interrupt ISR(void)
    {
    
    RBIE=0;					//Disable RB Port Change Interrupt
    PORTC=0b10101010;
    GIE=1;					//Enable Global Interrupt
    RBIF=0;					//Disable RB Port Change Flag Bit
    }
    I am guessing your C compiler saves the PIC regs that are normally needed to be saved and the restores them on leaving the routine.

    But, I would guess that you need to add a statement at the end to re-enable the
    interrupt. Like below. I also re-order the statements in what I think is a better way.
    Code:
    void interrupt ISR(void)
    {
    RBIE=0;					//Disable RB Port Change Interrupt
    PORTC=0b10101010;
    RBIF=0;					//Disable RB Port Change Flag Bit
    RBIE=1;					//Enable RB Port Change Interrupt
    GIE=1;					//Enable Global Interrupt
    }
    I have no idea why you have the "RBIF=0;" command; but, normally re-enable Interrupt are at the end right before restoring saved regs (that your compiler likely does).

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    Sep 2015
    Posts
    5
    Hi Tim S.

    Your code looks fine, I know thats how it should be, but now the interrupt keeps looping. The RBIF Flag Bit wont change back to 0, when i simulate it executes the 'RBIF=0;' command but the register stays at 1.

    I forgot to remove the "RBIF=0;" command, i understand why its not needed,

  4. #4
    Registered User
    Join Date
    Sep 2015
    Posts
    5
    I think its a bug in the program, when user RB4 as my flag bit and it goes into the interrupt function i set "RB4=0". Now it seems to exit the interrupt function correctly, I can also set my flag bit again to go back into the interrupt without any problems.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Serial port interrupt in windows
    By ShinuMV in forum C Programming
    Replies: 2
    Last Post: 10-20-2012, 02:24 PM
  2. Time change interrupt
    By vipul_vgp in forum Linux Programming
    Replies: 9
    Last Post: 02-25-2009, 10:35 AM
  3. Can I bind a UDP socket to a port, but send to any other port?
    By trillianjedi in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-25-2009, 04:27 PM
  4. change LCD port for microcontroller
    By iedchan in forum C Programming
    Replies: 2
    Last Post: 05-11-2007, 06:19 AM
  5. change signal - seriel port - dos or linux
    By sphreak in forum C++ Programming
    Replies: 0
    Last Post: 01-03-2003, 11:24 AM

Tags for this Thread