简体   繁体   English

IOC(PIC 16F877A)模拟器未调用MPLAB XC8中断例程

[英]MPLAB XC8 interrupt routine doesn't get called for IOC (pic 16f877a) simulator

I have written some code, a simple program to try to increment a counter during an interrupt on . 我写了一些代码,一个简单的程序,试图在的中断期间增加计数器。 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 ::警告:(1273)在自由模式下无法使用Omniscient代码生成main.c:32:警告:(520)永远不会调用函数“ _Interrupt”

#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: 您需要将函数限定符interrupt添加到中断服务例程的定义中,以便编译器知道它是中断服务例程而不是常规函数,并可能重命名函数本身,以便名称和限定符明显分开:

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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM