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.

pic interrupts - code is not working please help

Status
Not open for further replies.

lunar

Junior Member level 2
Joined
Mar 7, 2006
Messages
23
Helped
4
Reputation
8
Reaction score
2
Trophy points
1,283
Activity points
1,412
pic interrupts

Hello i am using PIC18F4550 and i want to use its interrupts, i have written a simple code to blink an led when interrupt is received on RB0. But its not working please see the code and guide.
thanks

Code:
//************************************************************************************************* 
//test code for int0, blink led on portD on receving interrupt

#include <p18f4450.h>
void main (void);
void InterruptHandlerHigh (void);

void main ()
{
	int i=0;
	INTCON2bits.INTEDG0=1;//m interrupt is rising edge
	INTCONbits.INT0IE=1;//m enable  interrupt
  	INTCONbits.GIEH = 1;          //enable global interrupts
  	TRISB = 1;			//set port b as input
	TRISD=0;			//set port d as output
	while(1);//move in loop, gets out on receving interrupt and then comes back.
}//end main

// High priority interrupt vector
#pragma code InterruptVectorHigh = 0x08
void
InterruptVectorHigh (void)
{
  _asm
    goto InterruptHandlerHigh //jump to interrupt routine
  _endasm
}
//----------------------------------------------------------------------------
// High priority interrupt routine
#pragma code
#pragma interrupt InterruptHandlerHigh
void
InterruptHandlerHigh ()
{	int i=0;
	int j=0;
	if (INTCONbits.INT0F)
	{
	INTCONbits.INT0IE=0;//m disable the interrupt

		for(j=0;j<4;j++)//toggle the bit0 or portD on receiving interrupt
		{
			LATDbits.LATD0 = 1;
			for( i=0;i<40000;i++);
			LATDbits.LATD0 = 0;
			for( i=0;i<40000;i++);
		}	 

	INTCONbits.INT0F=0;	//m reset the flag
	}
INTCONbits.INT0IE=1;//m enable the interrupt
}

//----------------------------------------------------------------------------
//*************************************************************************************************
 

Re: pic interrupts

Hi,

Why are you disabling the interrupt inside your interrupt handler ??, seems you do not understand how interrupts work.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top