Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

External Interrupt problem (C18)

Status
Not open for further replies.

korena

Newbie level 3
Joined
Jul 4, 2010
Messages
4
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Activity points
1,305
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 ??




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 :)
 

google search results in too many interrupt issues, most of which are I/O config problems ... but I cant figure out any flaw in this code :( ... So guys, if you do not see a mistake, could u try the code and let me know if it works or not ?
INT0 is input, RB6 & RB7 should change if an interrupt accurs ...


thnx in advance ...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top