SeanHatch
New Member
Hi;
I have been working on this interrupt for a while now, and I can't get it to work. I'm trying to turn on or off an LED with a push button.
I have a PIC18F452
Here is the code:
I know I'm pretty close. If I uncomment the line INTCONbits.INT0IF = 1, the interrupt functions as it should. So I know that the interrupt is properly coded and stuff.
Also, I know that the button works. I have a multimeter on the RD0 pin, and it is changing from 5V to 0V when I push the button.
Basically, the voltage change on the RD0 pin is not setting the INT0 flag, and I don't know why? Am I missing initializing something?
Thanks
I have been working on this interrupt for a while now, and I can't get it to work. I'm trying to turn on or off an LED with a push button.
I have a PIC18F452
Here is the code:
Code:
#include <p18cxxx.h>
#pragma config WDT=OFF
#pragma config LVP=OFF
#include <ADC.h>
#include<math.h>
#include<portb.h>
void change(void);
#pragma code HIGH_INTERRUPT_VECTOR = 0x8
void high_ISR (void){
_asm
goto change
_endasm
}
#pragma code
#pragma interrupt change
void change(void)
{
PORTDbits.RD0 = !PORTDbits.RD0;
INTCONbits.INT0IF = 0;
}
void main()
{
TRISD = 0b11111111;
//TRISB = 0b00000000;
RCONbits.IPEN = 1;
INTCONbits.GIEH = 1;
OpenRB0INT (PORTB_CHANGE_INT_ON &
PORTB_PULLUPS_ON &
FALLING_EDGE_INT);
for(count = 1; count < 10000; count++);
while(1) // forever
{
//PORTDbits.RD0 = !PORTDbits.RD0;
//INTCONbits.INT0IF = 1;
for(count = 1; count < 5000; count++);
}
}
I know I'm pretty close. If I uncomment the line INTCONbits.INT0IF = 1, the interrupt functions as it should. So I know that the interrupt is properly coded and stuff.
Also, I know that the button works. I have a multimeter on the RD0 pin, and it is changing from 5V to 0V when I push the button.
Basically, the voltage change on the RD0 pin is not setting the INT0 flag, and I don't know why? Am I missing initializing something?
Thanks