1
我在下面有一些代碼有一個小問題,我不知道如何解決。基本上發生了什麼是我的高ISR在設置標誌後運行兩次。它只運行兩次並且一致。該子程序只能運行一次,因爲當RB上的輸入發生變化時該標誌被設置,並且該程序在一次改變爲RB輸入後運行兩次。該測試是在MPLAB v8.6中使用工作簿功能進行的。爲什麼RB中斷例程運行兩次?
#include <p18f4550.h>
#include <stdio.h>
void init(void)
{
RCONbits.IPEN =1; //allows priority
INTCONbits.GIE = 1; //allows interrupts
INTCONbits.PEIE = 1; //allows peripheral interrupts
INTCONbits.RBIF = 0; //sets flag to not on
INTCONbits.RBIE = 1; //enables RB interrupts
INTCON2bits.RBPU = 1; //enable pull up resistors
INTCON2bits.RBIP = 1; //RB interrupts is high priority
PORTB = 0x00;
TRISBbits.RB7 = 1; //enable RB7 as an input so we can throw interrupts when it changes.
}
#pragma code
#pragma interrupt high_isr
void high_isr(void)
{
if(INTCONbits.RBIF == 1)
{
INTCONbits.RBIF = 0;
//stuff
}
}
#pragma code
#pragma code high_isr_entry = 0x08
void high_isr_entry(void)
{_asm goto high_isr _endasm}
void main(void)
{
init();
while(1);
}
你確保清除中斷標誌在你//填充碼? –
是的,我應該將其包含在我的原始代碼中。編輯! –
不知道會發生什麼,但如果你壓縮併發送給我你的項目,我可以在我的機器上嘗試。查看我的個人資料獲取電子郵件 –