I have written some code, a simple program to try to increment a counter during an interrupt on portbbits.rb7 . The program builds without error however a warning exists that:
:: warning: (1273) Omniscient Code Generation not available in Free mode main.c:32: warning: (520) function "_Interrupt" is never called
#define _XTAL_FREQ 8000000
#include <pic16f887.h>
#include <xc.h>
char counter = 0;
char dummy = 0;
void main(void)
{
TRISB = 0x80; //Configure PORTB pin 7 to input
TRISC = 0xOO; //Configure PORTC to output
INTCONbits.RBIF = 0; //clear interrupt on change flag
INTCONbits.GIE = 1; //enable global interrupts
INTCONbits.RBIE = 1; //enable port change interrupt
while(1)
{
PORTC = counter; //update PORTC with value of counter
}
return;
}
void Interrupt (void)
{
INTCONbits.RBIF = 0; //clear Interrupt on change flag
dummy = PORTB; //do a dummy read to clear IOC flag
counter++; //increment counter
}
On the snippets of code I've seen, people are usually testing their interrupts on hardware. However I don't have the hardware as yet, so trying to do some simulations and checking out stuff in the address registers etc.
I made the assumption that I would be able verify the interrupt routine with just software (see attached screen grabs). File Registers Counter Variable Address
So if anyone can point out my omission, or lead me in the right direction, it would be much appreciated.
You need to add the function qualifier interrupt
to the definition of your interrupt service routine, so the compile knows it's a interrupt service routine and not a regular function, and perhaps rename the function itself so the name and qualifier are clearly seperated:
void interrupt ISR (void) //Added 'interrupt' qualifier and renamed function to 'ISR' for clarity.
{
INTCONbits.RBIF = 0; //clear Interrupt on change flag
dummy = PORTB; //do a dummy read to clear IOC flag
counter++; //increment counter
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.