【问题标题】:XC8 Interrupt ConfigurationXC8 中断配置
【发布时间】:2015-11-12 23:43:47
【问题描述】:

我正在尝试为 pic16f887 编写定时器中断。我检查了几个网站,其中大多数都建议将中断子程序编写为

void 中断名称(void)

但是我的程序说这样做我的中断名称与 Isr 冲突。 main.c:42: error: (1375) 为只有一个中断向量的设备定义了多个中断函数(_led 和 _isr)

这是我的代码示例。

/******************************************************************************/
/* Files to Include                                                           */
/******************************************************************************/

#define _XTAL_FREQ 4000000

#include <xc.h>
#include <stdint.h>        /* For uint8_t definition */
#include <stdbool.h>       /* For true/false definition */
#include <htc.h>

#include "system.h"        /* System funct/params, like osc/peripheral config */
#include "user.h"          /* User funct/params, such as InitApp */
#include "pic16f887.h"
/******************************************************************************/
/* User Global Variable Declaration                                           */
/******************************************************************************/

/* i.e. uint8_t <variable_name>; */

/******************************************************************************/
/* Main Program                                                               */
/******************************************************************************/
// CONFIG1
#pragma config FOSC = INTRC_CLKOUT// Oscillator Selection bits (INTOSC oscillator: CLKOUT function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF      // RE3/MCLR pin function select bit (RE3/MCLR pin function is digital input, MCLR internally tied to VDD)
#pragma config CP = OFF         // Code Protection bit (Program memory code protection is disabled)
#pragma config CPD = OFF        // Data Code Protection bit (Data memory code protection is disabled)
#pragma config BOREN = ON       // Brown Out Reset Selection bits (BOR enabled)
#pragma config IESO = OFF       // Internal External Switchover bit (Internal/External Switchover mode is disabled)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled)
#pragma config LVP = OFF        // Low Voltage Programming Enable bit (RB3 pin has digital I/O, HV on MCLR must be used for programming)

// CONFIG2
#pragma config BOR4V = BOR40V   // Brown-out Reset Selection bit (Brown-out Reset set to 4.0V)
#pragma config WRT = OFF        // Flash Program Memory Self Write Enable bits (Write protection off)

void interrupt led(void)


{
    PORTA = 0X00;`enter code here`

}


void main(void)
{  
   OSCCON = 0b01110000;

    TRISA = 0X00;
    ANSEL = 0X00;
    ANSELH = 0X00;

    while(1)
    {
        PORTA = 0X03;
        __delay_ms(1000);
        PORTA = 0X01;
        __delay_ms(1000);


    }

}

【问题讨论】:

  • 试试void interrupt _isr(void)。记得清除中断标志。
  • 该错误意味着其中一项将 isr 定义为高优先级中断处理程序(您只能拥有一个)。尝试在所有文件中搜索标签 isr。但是,如果什么都不会产生中断,为什么还要有一个处理程序呢?
  • 首先,我将删除htc.hpic16f887.h#include - 你应该只需要xc.h,其余的由项目配置处理。
  • 可能听起来很傻,但是您在 PORTA=0x00 行上有语法错误。把分号后面的东西注释掉

标签: pic xc8


【解决方案1】:

如果您有 xc8 2.0 及更高版本,您的 ISR 应该如下所示:

#include <xc.h>

....
void __interrupt() ISR(void)    
{
...... // do Interrupt stuff
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-31
    • 1970-01-01
    • 2021-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-19
    • 1970-01-01
    相关资源
    最近更新 更多