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.

Unable to stop Interrupt

Status
Not open for further replies.

garg29

Advanced Member level 1
Advanced Member level 1
Joined
Nov 17, 2004
Messages
443
Helped
25
Reputation
50
Reaction score
10
Trophy points
1,298
Activity points
3,593
Hi friends,

In the following code I have not Enabled the external Interrupt still the processor is accepting it I cant understand why, please have a look:-
Code:
/** I N C L U D E S **********************************************************/
#include <p18cxxx.h>
#include<stdlib.h>

#include "delay.h"

.
.
.
.
.
.
.
.
.
.
.



extern void _startup (void);        // See c018i.c in your C18 compiler dir



//----------------------------------------------------------------------------
// High priority interrupt vector

#pragma code InterruptVectorHigh = 0x0800
void
InterruptVectorHigh (void)
{
  _asm
    goto InterruptHandlerHigh //jump to interrupt routine
  _endasm
}

//----------------------------------------------------------------------------
// High priority interrupt routine

//----------------------------------------------------------------------------
// High priority interrupt routine

#pragma code
#pragma interrupt InterruptHandlerHigh

void
InterruptHandlerHigh ()
{
  	if (INTCONbits.INT0IF)
    {
		 	CountPulse++;
		 		
			//INTCONbits.PEIE=1;
			//INTCONbits.INT0IE=1;
			INTCONbits.INT0IF = 0;            //clear interrupt flag
     
					
    }
    
    
     
    
   if (INTCONbits.TMR0IF)		//check for TMR0 overflow
   {                                   
      
      //INTCONbits.PEIE=0;
			
      	TMR0H=0xD6;
		TMR0L=0x0C;
		
		Display7Segment();
			
		INTCONbits.TMR0IF=0;
		//INTCONbits.PEIE=1;
		
		
   }
    
    
    
    
}

///////////////////////////////////////////////////////////////


.
.
.
.
.
.
.
.
.
.

 
 
/** D E C L A R A T I O N S **************************************************/
#pragma code

void main(void)
{
    
    unsigned int i;

	RCONbits.IPEN=1;
	
	
	CMCON |= 0x07; 
	ADCON1 |= 0x0F; 
	CVRCON = 0;
	INTCON2=0x04;
	OSCCONbits.IOFS = 1;
	INTCONbits.INT0IE=0;
	INTCONbits.RBIE =0;
	INTCONbits.RBIF =0; 
	
	T0CON=0x08;
	TMR0H=0x3C;
	TMR0L=0xB0;
	INTCONbits.TMR0IF=0;
	INTCONbits.TMR0IE=1;
	T0CONbits.TMR0ON=1;
	

	INTCONbits.PEIE=0;
	INTCONbits.GIE=1;
	
		
		
	TRISA=0x00;
	PORTA=0x00;
	LATA=0x00;
	
	TRISB=0x01;
	PORTB=0x01;
	LATB=0x01;
	
	TRISC=0x00;
	PORTC=0x00;
	LATC=0x00;
	
	TRISD=0x00;
	PORTD=0x00;
	LATD = 0x00;
	
	TRISE=0x00;
	PORTE=0x00;
	LATE = 0x00;

		
	CountPulse=0;
	
    while(1)
    {   
		
			DataForDisplay(CountPulse);
			
      		DelayMs(100);
        
    }//end while
}//end main




Actually I want to initailly make
Code:
INTCONbits.INT0IE=1;

then when the "CountPulse" becomes greater than 1000 I want the processor to stop accepting the External INT0 Interrupt by making
Code:
if(CountPulse>1000)
      INTCONbits.INT0IE=0;//stop the External INT0 Interrupt
, but cant do it can anyone please help me out, I'm using PIC18F4550 & C18 compiler


Please help me out....
 

One of the things is the correct headers include:

#include <p18cxxx.h>

it should be the actual device ID (such as P18F4550.h or similar).
 

have you seen p18cxxx.h first have a look then reply
 

for ease of reading i have removed the variable declarations & display functions. counts are working fine & display is working fine only the interrupt is causing the problem ........................,
 

Try the following inside your Interrupt routine:
if (INTCONbits.INT0IF && INTCONbits.INT0IE) instead of if (INTCONbits.INT0IF)

Reason: the interrupt flag will always be set even if you disallow INT0IE and get into the interrupt routine via your timer interrupt (TMR0IF).

I hope this will help you.

best regards
 

    garg29

    Points: 2
    Helpful Answer Positive Rating
Thanks C-Man I was too thinking for the same but wasn't sure if this was a correct method.
As you said,

Code:
Reason: the interrupt flag will always be set even if you disallow INT0IE and get into the interrupt routine via your timer interrupt (TMR0IF).

so, can this be said as a bug in microchip controllers?
 

No, this is not a bug.
It can be quite useful to use the interrupt flags (by polling) and not use interrupts.
The flags are always set for all interrupts whether the interrupt is enabled or not.
You can still use them and clear them.
Once you realize this, I'm sure you will find them useful in quite a lot of situations.
 

    garg29

    Points: 2
    Helpful Answer Positive Rating
Without this feature, the interrupts which arrive while you are servicing another interrupt would be lost, as GIE is reset (made 0) by the hardware in case of an interrupt.
 

    garg29

    Points: 2
    Helpful Answer Positive Rating
Thanks all of you, that worked out.... :)... I have clicked "helped me" for all of you.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top