나는 수정 해야할지 모르는 약간의 버그가있는 아래 코드가있다. 근본적으로 무슨 일이 일어나고있는가 높은 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);
}
당신이 당신의 // 물건 코드에서 인터럽트 플래그를 지우려면 확인하고 있습니까? –
예, 원본 코드에 포함시켜야합니다. 수정되었습니다. –
무슨 일이 일어날 지 모르지만 프로젝트를 보내 주시면 내 컴퓨터에서해볼 수 있습니다. 이메일 주소는 내 프로필을 참조하십시오. –