korena
Newbie level 3
Hi all, can somebody please tell me whats wrong with this code ?!
its supposed to be a hardware interrupt test:
normal operation : LED1 on, LED2 off
when interrupt accurs(INT0 change) : LED1 off, LED2 on
I have to mension that my INT0 pin (RB0) is always high unless I push the button (push to break) ... is that a problem ??
thnx in advance
its supposed to be a hardware interrupt test:
normal operation : LED1 on, LED2 off
when interrupt accurs(INT0 change) : LED1 off, LED2 on
I have to mension that my INT0 pin (RB0) is always high unless I push the button (push to break) ... is that a problem ??
Code:
#include<p18f4550.h>
#include<delays.h>
#pragma config FOSC = HS // HS oscillator
#pragma config PWRT = OFF
#pragma config BOR = OFF
#pragma config WDT = OFF
#pragma config MCLRE = ON
#pragma config PBADEN = OFF
#pragma config LVP = OFF
void InterruptHandlerHigh() ;
// main ---------------------------------------------------------------------
void main(void)
{
ADCON1 = 0x0F ; // all dig
TRISB = 0b00000001 ;
INTCON2bits.RBPU = 1 ;
// INTCONbits.PEIE = 1 ; // not sure needed ...
INTCON2bits.INTEDG0 = 1 ;
INTCONbits.INT0IE = 1 ;
INTCONbits.INT0IF = 0 ;
PORTBbits.RB7 = 1 ; // turn on LED1
PORTBbits.RB6 = 0 ; // turn off LED2
}
//interrupt defs ------------------------------------------------------------
#pragma code InterruptVectorHigh = 0x08
void
InterruptVectorHigh (void)
{
_asm
goto InterruptHandlerHigh
_endasm
}
#pragma code
#pragma interrupt InterruptHandlerHigh
void
InterruptHandlerHigh ()
{
if(INTCONbits.INT0IF)
{
INTCONbits.INT0IF = 0;
PORTBbits.RB6 = 1 ; // turn on LED2
PORTBbits.RB7 = 0 ; // turn oFF LED1
}
}
thnx in advance