Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

interrupt betrayal

Status
Not open for further replies.

desijays

New Member
Hello everyone,

In the code below, Im trying to use the interrupt that is generated when there is a change in the PORTB pins <4,5,6,7>. The datasheet says that I need to enable the interrupt in the 3rd pin(RBIE) of INTCON. And the interrupt flag is the 0th pin(RBIF) of INTCON. I've configured MPLAB to provide stimulus to the 5th pin of PORTB at the 20th instruction cycle.

When I run the program, MPLAB provides the stimulus at the 20th instruction cycle and the RBIF flag gets set since there is a change in the 5th pin, but it is not generating an interrupt. That is, the program execution continues with the next statement without jumping to "Program Counter Address" 0x04(Default location for ISR).

Am I making a mistake somewhere?

Thank you.
Code:
	processor	16f877a
	include	          <p16f877a.inc>
	__config	 _HS_OSC & _WDT_OFF & _PWRTE_ON
	
	ORG	000H
	GOTO	MAIN
	
	ORG	004H
        GOTO	ISR
	
	ORG	200H
 
NITZ	NOP
	BANKSEL	TRISB
	MOVLW	0XFF
	MOVWF	TRISB
	BSF	INTCON,3
	RETURN

WAIT	GOTO	$
	RETURN

MAIN	CALL	NITZ
	CALL	WAIT

ISR	NOP
	
	END
 
You need to set the Global Interrupt Enable bit (bit 7 of INTCON).

Mike.
 
You also need to return from the ISR and clear the interrupt flag in software.
I would suggest to switch back to bank 0 in order to avoid future problems, if you're going to add further code.
 
Also clear that interrupt flag before enabling the interrupts. Change on PortB can happen at anytime which includes before you are ready for the change. If so, the moment you call NITZ the interrupt may trigger but be false. This happens because the micro or any of the external circuitry is not stable by the time the code is running. Enable power up time, too long for my taster, or call a short delay before MAIN.


Makes no real difference but will be much easier to read and debug if the subs are below MAIN.
 
Pommie said:
You need to set the Global Interrupt Enable bit (bit 7 of INTCON).

Mike.

oh yes, ofcourse. Silly me!! How did I forget!. Thank you for pointing it out Pom
 
donniedj said:
Makes no real difference but will be much easier to read and debug if the subs are below MAIN.

yea, i felt that too now that you pointed it out. I'll keep that in mind
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top