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.

[SOLVED] Interrupt Not Running

Status
Not open for further replies.

darktangent

Junior Member level 2
Joined
Oct 17, 2010
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,435
Hi, I am using the following code, but intterupts do not launch once the RB0 goes high.

Can you find a problem.

Code:
#include <p18f452.h>
#include <delays.h>
#pragma config WDT = OFF

void chk_isr(void); //Interrupt Handler
void inc_count(void);
void dec_count(void);

// Code to Be placed inthe Interrupt Handler
#pragma code My_HiPrio_Int = 0x08

	void My_HiPrio_Int(void){
		_asm
		GOTO chk_isr
		_endasm
	}
#pragma code	//end of interrupt vector table

#pragma interrupt chk_isr // Our Interrupt Service Routine

void chk_isr(void){
	if(INTCONbits.INT0IF == 1) inc_count();
	if(INTCON3bits.INT1IF == 1) dec_count();
	}

void display_count(void);
char count = 0;
char segment[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};

	
void main(void){
	TRISC = 0;
	TRISD = 0;
	TRISBbits.RB0 = 1;
	TRISBbits.RB1 = 1;
	INTCONbits.INT0IF = 0;
	INTCONbits.INT0IE = 1;
	INTCON3bits.INT1IE = 1;
	INTCONbits.GIE = 1;

	while(1){
		display_count();
		
	}
	
}

void display_count(void){
	char MSB;
	char LSB;
	MSB = count / 10;
	LSB = count % 10;
	PORTC = segment[MSB];
	PORTD = segment[LSB];
	
	
}

void inc_count(void){
	count++;
	INTCONbits.INT0IF == 0;
}

void dec_count(void){
	count--;
	INTCON3bits.INT1IF == 0;
}
 

I am using MPLab C 18 Lite compiler
 

you didn't cofigure the registers completely write these lines before your header file (if you are using external Crytsal oscillator)

#pragma config OSC=HS, OSCS=OFF
#pragma config PWRT=OFF, BOR=ON, BORV=45
#pragma config WDT =OFF
#pragma config DEBUG=OFF,LVP=OFF,STVR=OFF

Also you didn't declare your display_count fuction
 

Hi,

put that data declaration defore the interrupt handler and after the interrupt handler use a #pragma code directive
I have not verified the bits about the GPIO interrupt.
char count = 0;
char segment[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
Hope, i help you
regards
JoseMiguel
 

Hi,

put that data declaration defore the interrupt handler and after the interrupt handler use a #pragma code directive
I have not verified the bits about the GPIO interrupt.
char count = 0;
char segment[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
Hope, i help you
regards
JoseMiguel

Thanks for the help but i am already using the directive. Have a look
#pragma code My_HiPrio_Int = 0x08

void My_HiPrio_Int(void){
_asm
GOTO chk_isr
_endasm
}
#pragma code

Also what purpose will be served by putting the data declaration before the interrupt handler?

---------- Post added at 07:59 ---------- Previous post was at 07:56 ----------

you didn't cofigure the registers completely write these lines before your header file (if you are using external Crytsal oscillator)

#pragma config OSC=HS, OSCS=OFF
#pragma config PWRT=OFF, BOR=ON, BORV=45
#pragma config WDT =OFF
#pragma config DEBUG=OFF,LVP=OFF,STVR=OFF

Also you didn't declare your display_count fuction

Thanks for the reply mate, i will make these changes and then update you about it.

I am using the display_count function declaration, i think you missed it :)

void display_count(void);
 
Last edited:

Hi, I am using the following code, but intterupts do not launch once the RB0 goes high.
Hi darktangent;
I don't know this proc nor this compiler exactly but ... try out this (look at the red lines):

Code:
#include <p18f452.h>
#include <delays.h>
#pragma config WDT = OFF

void chk_isr(void); //Interrupt Handler
void inc_count(void);
void dec_count(void);

// Code to Be placed inthe Interrupt Handler
#pragma code My_HiPrio_Int = 0x08

	void My_HiPrio_Int(void){
		_asm
		GOTO chk_isr
		_endasm
	}
#pragma code	//end of interrupt vector table

#pragma interrupt chk_isr // Our Interrupt Service Routine

void chk_isr(void){
	if(INTCONbits.INT0IF == 1) inc_count();
	if(INTCON3bits.INT1IF == 1) dec_count();
	}

void display_count(void);
char count = 0;
char segment[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};

	
void main(void){
	TRISC = 0;
	TRISD = 0;
	TRISBbits.RB0 = 1;
	TRISBbits.RB1 = 1;
	INTCONbits.INT0IF = 0;
	INTCONbits.INT0IE = 1;
                [COLOR="red"]INTCON3bits.INT1IF = 0;[/COLOR]
                INTCON3bits.INT1IE = 1;
	[COLOR="red"]INTCONbits.PEIE = 1;[/COLOR]
                INTCONbits.GIE = 1;

	while(1){
		display_count();
		
	}
	
}

void display_count(void){
	char MSB;
	char LSB;
                [COLOR="red"]INTCONbits.GIE = 0;[/COLOR]
                MSB = count / 10;
	LSB = count % 10;
                [COLOR="red"]INTCONbits.GIE = 1;[/COLOR]

	PORTC = segment[MSB];
	PORTD = segment[LSB];
	
	
}

void inc_count(void){
	count++;
	INTCONbits.INT0IF == 0;
}

void dec_count(void){
	count--;
	INTCON3bits.INT1IF == 0;
}
 
Last edited:

you didn't cofigure the registers completely write these lines before your header file (if you are using external Crytsal oscillator)

#pragma config OSC=HS, OSCS=OFF
#pragma config PWRT=OFF, BOR=ON, BORV=45
#pragma config WDT =OFF
#pragma config DEBUG=OFF,LVP=OFF,STVR=OFF

Also you didn't declare your display_count fuction

The interrupts does not even work after the fixes. I want to use an internal oscillator. Is it fine to use these commands with it?

---------- Post added at 09:31 ---------- Previous post was at 09:31 ----------

Hi darktangent;
I don't know this proc nor this compiler exactly but ... try out this (look at the red lines):

Code:
#include <p18f452.h>
#include <delays.h>
#pragma config WDT = OFF

void chk_isr(void); //Interrupt Handler
void inc_count(void);
void dec_count(void);

// Code to Be placed inthe Interrupt Handler
#pragma code My_HiPrio_Int = 0x08

	void My_HiPrio_Int(void){
		_asm
		GOTO chk_isr
		_endasm
	}
#pragma code	//end of interrupt vector table

#pragma interrupt chk_isr // Our Interrupt Service Routine

void chk_isr(void){
	if(INTCONbits.INT0IF == 1) inc_count();
	if(INTCON3bits.INT1IF == 1) dec_count();
	}

void display_count(void);
char count = 0;
char segment[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};

	
void main(void){
	TRISC = 0;
	TRISD = 0;
	TRISBbits.RB0 = 1;
	TRISBbits.RB1 = 1;
	INTCONbits.INT0IF = 0;
	INTCONbits.INT0IE = 1;
                [COLOR="red"]INTCON3bits.INT1IF = 0;[/COLOR]
                INTCON3bits.INT1IE = 1;
	[COLOR="red"]INTCONbits.PEIE = 1;[/COLOR]
                INTCONbits.GIE = 1;

	while(1){
		display_count();
		
	}
	
}

void display_count(void){
	char MSB;
	char LSB;
                [COLOR="red"]INTCONbits.GIE = 0;[/COLOR]
                MSB = count / 10;
	LSB = count % 10;
                [COLOR="red"]INTCONbits.GIE = 1;[/COLOR]

	PORTC = segment[MSB];
	PORTD = segment[LSB];
	
	
}

void inc_count(void){
	count++;
	INTCONbits.INT0IF == 0;
}

void dec_count(void){
	count--;
	INTCON3bits.INT1IF == 0;
}

Thanks, i will try.

---------- Post added at 09:40 ---------- Previous post was at 09:31 ----------

Nothing of all the help provided worked! I checked every one.
 

you didn't initialize the Flag of interreupt RB1 to 0 in your main function. write (INTCON3bits.INT1IF == 0) in main fuction.

another thing you only initialize the Interuupt pins to input using tris, but you didnt write any default value to port such as
PORTBbits.RB0=1;
PORTBbits.RB1=1;
or
PORTBbits.RB0=0;
PORTBbits.RB1=0;

so that when interrupt comes from external harware (may be from push button) then RB0, RB1 changes its state. you need pullup and pulldown resistors for that.(depending upon whether you set RB0 and RB1 pin as 0 or 1).
 
Study the datasheet and set properly the priority of the RB0 and RB1 interrupts to high (I don't see it now).
An other idea: switch on the PORTB internal pullups via set RBPU.
 

you didn't initialize the Flag of interreupt RB1 to 0 in your main function. write (INTCON3bits.INT1IF == 0) in main fuction.

another thing you only initialize the Interuupt pins to input using tris, but you didnt write any default value to port such as
PORTBbits.RB0=1;
PORTBbits.RB1=1;
or
PORTBbits.RB0=0;
PORTBbits.RB1=0;

so that when interrupt comes from external harware (may be from push button) then RB0, RB1 changes its state. you need pullup and pulldown resistors for that.(depending upon whether you set RB0 and RB1 pin as 0 or 1).

Thanks a Lot mate. The Pull Up resistors solved the Issue. I am choosing yours the Best answer.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top