1

I'm trying to get myself familiar with Interrupts when it comes to the 18F4550 PIC. At this point I've written a software that would light up an LED whenever the INT0 raises a flag. My code states that every 500 ms, INT0 will raise a flag and "is supposed to" jump into an ISR and fire up a LED all while "transferring dummy data between Port C and Port D" I've tried debugging, but once the debugger gets to the code that sets the INT0 flag to 1, the debugger says "No source code lines were found at current PC". Here's the code below. Any kind of help is greatly appreciated. Thanks a lot!

Please note that I am using MPLAB X and a PicKit3

#include <xc.h>
#include <p18f4450.h>
#include <stdlib.h>
#define mybit LATBbits.LATB1  //LED
#define _XTAL_FREQ 10000000   //Using a crystal oscillator

void chk_isr(void);          
void INT0_ISR(void);
void delay(unsigned int);

#pragma interrupt chk_isr   //used for high-priority interrupt only

void chk_isr (void)
{
    if(INTCONbits.INT0IF == 1)  //INT0 causes interrupt?
        INT0_ISR();             //Yes, Execute INT0ISR

}

#pragma code My_HiPrio_Int=0x08//high priority interrupt
void My_HiPrio_Int (void)
{
    asm("GOTO chk_isr");
}

void main(void)
{
    TRISBbits.TRISB1 = 0;   //RB1 = output

    mybit = 0;              //Initially LED is OFF
    TRISC = 0xFF;           //PORTC = input
    TRISD = 0;              //PORTD = output


    INTCONbits.INT0IF = 0;  //clear INT0
    INTCONbits.INT0IE = 1;  //enable INT0 interrupt

    INTCONbits.GIE = 1;     //enable all interrupts globally

    while(1)
    {
        PORTD = PORTC;          
        delay(500);         //After 500 ms
        INTCONbits.INT0IF = 1; //Flag

    }
}


void INT0_ISR(void)
{
    mybit=~mybit;           //Toggle LED
    INTCONbits.INT0IF = 0;  //clear INT0 Flag
}

void delay(unsigned int delayInput) {
    unsigned int mul = delayInput/50;
    unsigned int count = 0;
    for (count = 0; count <= mul; count ++)
        __delay_ms(50);
}
Clifford
  • 88,407
  • 13
  • 85
  • 165
TheLebDev
  • 531
  • 6
  • 18
  • When debuggers fail, add trace printf() statements and hope that they are able to make it to a console. Also, is it possible that the interrupt vector table has not been setup so the code is jumping to garbage values? – Michael Dorgan Nov 04 '16 at 17:37
  • 1
    Why have the weird line asm("GOTO...? If you just put the body of chk_isr into My_HiPrio_Int what happens? – Ross Nov 04 '16 at 18:06
  • @MichaelDorgan I'm not sure if that's the case, if it is, how do i fix that? – TheLebDev Nov 05 '16 at 06:55
  • @Ross because I want the Program Counter to jump to memory that has the Interrupt Service Routine and from there jump to another part of memory to handle that interrupt. I tried calling the method chk_isr(); directly, and that still didn't work.. – TheLebDev Nov 05 '16 at 06:58
  • @dou2abou: If you dom't belive to Ross than check the instruction at address for high-priority interrupt 0x0008 – GJ. Nov 05 '16 at 16:08
  • You need to re-enable the interrupt at the end of the ISR `INTCONbits.INT0IE = 1; `. – Rishikesh Raje Nov 07 '16 at 06:56

0 Answers0