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.

Return from interrupt without RETFIE

Status
Not open for further replies.

cestudent

New Member
hello guyz how r u all?

i need ur help with this problem , am using the external interrupt of pic16f876a

as i know that after the interrupt finished it should return to the same location its occurred but in my code i don't want to return it back to the same location i want it to goto another location .

so i tested my code it works but the interrupt happened just once !!When i power up the circuit so what is the problem ? i cleared the interrupt flag but still there is a problem
Code:
;//interrupt code


;///////////////////////////////
 TMR0		EQU     1
PORTA		EQU	5
PORTB		EQU	6
PORTC		EQU	7
TRISA		EQU	5
TRISB		EQU	6
PORTC		EQU	7
TRISC		EQU	7
PC		EQU	2
STATUS		EQU	3
ZEROBIT		EQU	2
CARRY		EQU	0
EEADR		EQU	0DH
EEDATA		EQU	0CH
EECON1		EQU	0CH

EECON2		EQU	0DH
ADCON1		EQU	1FH 
RD		EQU	0
WR		EQU	1
WREN		EQU	2
ADCON0		EQU	1FH
ADCON1		EQU	1FH
ADRES		EQU	1EH
CHS0		EQU	3
GODONE		EQU	2
INTCON		EQU	0BH
OPTION_R	Equ	1
GIE	 	EQU	7	;global Interrupt bit
INTE	 	EQU	4	;B0 interrupt enable bit.
INTF	 	EQU	1       ;B0 interrupt flag
COUNT	 	EQU	24H	;means count is file 0C.
			;a register to count events.
TMR0_T	 	EQU	20H	;TMR0 temporary file
W_TEMP	 	EQU	21H	;W temporary file
STATUS_T 	EQU	22H	;STATUS temporary file
PORTB_T  	EQU	23H	;PORTB temporary file
COUNT_T		EQU	25H 
;******************************************

LIST	P=16F876A
ORG	0
GOTO	START
ORG	4
GOTO	ISR		;location4 jumps to ISR


;************************************************

;SUBROUTINE SECTION

; DELAY FOR 1 SEC 
DELAY	CLRF	TMR0
	MOVLW	.61
	MOVWF	COUNT
	BCF	STATUS,5
WAITA	BCF	INTCON,2
WAITB	BTFSS	INTCON,2
	GOTO	WAITB
	DECFSZ	COUNT,1
	GOTO	WAITA
	RETURN
	RETLW	0




;Interrupt Service Routine

ISR	
	MOVWF	W_TEMP	        ;Save W
	MOVF	STATUS,W	
	MOVWF	STATUS_T	;Save STATUS
	MOVF	TMR0,W
	MOVWF	TMR0_T	        ;save TMR0
	MOVF	COUNT,W		
	MOVWF	COUNT_T		;save PORTB
	
	BSF	PORTC,7
	CALL	DELAY
	CALL	DELAY 
	CALL	DELAY 
	CALL	DELAY 
	CALL	DELAY 
	BCF	PORTC,7
	
	BSF       INTCON,GIE  
	BCF	INTCON,INTF	;Reset Interrupt Flag
COMP	MOVF	STATUS_T,W
	MOVWF	STATUS		;Restore Status
	MOVF	TMR0_T,W
	MOVWF	TMR0		;Restore TMR0
	MOVF	COUNT_T,W
	MOVWF	COUNT		;Restore PORTB
	MOVF	W_TEMP,W	;Restore W


	
	GOTO	ss				;Return from the interrupt

;**************************************************************

;CONFIGURATION SECTION

START 	BCF	STATUS,5    ; BANK0
	BCF	STATUS,6    
	
	CLRF	PORTA
	CLRF	PORTB
	CLRF	PORTC

	BSF	STATUS,5    ; BANK1

	MOVLW	0X06
	MOVWF	ADCON1

	MOVLW	B'00011111'; PORTA are I/P
	MOVWF	TRISA
	



	MOVLW	B'00000001' ;B0 is an input, B1-7 O/P
	MOVWF	TRISB

	MOVLW	B'00000000'
	MOVWF	TRISC

	
	MOVLW	B'01000101'	;Prescalar is /64 
	MOVWF	OPTION_R		
	BCF	STATUS,5
	
	CLRF	PORTA		;Clears PortA.
	CLRF	PORTB		;Clears PortB.
	BSF	INTCON,GIE	;Enable Global Interrupt
	BSF	INTCON,INTE	;Enable B0 interrupt
;***********************************************************

;program starts now

BEGIN	BSF	PORTC,7
	CALL	DELAY
	BCF	PORTC,7
	CALL	DELAY 

	GOTO	BEGIN

ss
	BSF	PORTC,1
	CALL	DELAY 
	CALL	DELAY 
	CALL	DELAY 
	BCF	PORTC,1
	GOTO	BEGIN	
END

PLZ HELP
 
You must use a RETFIE from a subroutine. else the stack never gets popped and you'll quickly have a stack overflow.

PS use the include file, lots of examples out there.
 
Last edited:
u mean there no way to return to another place " goto " and the interrupt re-enable?
and plz what is the the include file that u said about it ?
 
u mean there no way to return to another place " goto " and the interrupt re-enable?
and plz what is the the include file that u said about it ?

hi,
This shows a *.inc,
Code:
 CONF_WORD = 0x3f31
	list p=16f876a
	#include <p16f876a.inc>
	radix dec
                errorlevel -302, -207

this is then not required
Code:
ORTA		EQU	5
PORTB		EQU	6
PORTC		EQU	7
TRISA		EQU	5
TRISB		EQU	6
PORTC		EQU	7
TRISC		EQU	7
PC		EQU	2
PSTATUS		EQU	3
ZEROBIT		EQU	2
CARRY		EQU	0
 
You can't exit a subroutine or interrupt routine with a goto. You must use a return. What book are you getting your tutorial from? Throw it out.
 
thanx ericgibbs and ericgibbs
sorry i repeat the Q but am a beginner in programing so can u help me in doing that?
 
Last edited:
am doing a lift project and am using interrupt coz when the lift is start working it should reset , in the reset function it is a loop to drive the stepper motor " lift goes down " what i want is if the lift touched the limit switch the the lift an interrupt is occured and then the lift should go for example to floor 1 if I used return it will return to the down loop again
 
Don't use interrupts if you're not sure what they're for. Do a simple state machine and poll the input pin. Interrupts are great when you use them for what they're designed for.
 
;program starts now

hi,
As Bill says, keep the program simple,:)

Question, what is 'ss' routine for and how do you get into it.?

Code:
BEGIN	BSF	PORTC,7
	CALL	DELAY
	BCF	PORTC,7
	CALL	DELAY 

	GOTO	BEGIN

ss
	BSF	PORTC,1
	CALL	DELAY 
	CALL	DELAY 
	CALL	DELAY 
	BCF	PORTC,1
	GOTO	BEGIN
 
ericgibbs


this program is just a test to check if the interrupt works with goto at the end , it works but the interrupt is occurred just once.

blueroomelectronics

thanx for what u said :)
 
coz as i told u before in my project code am using a loop when the interrupt is happen i want it then to return to another place coz if i used retfie then i will go back to the loop thats my problem
 
Last edited:
what is "RETFIE //return from subroutine" in C program? thanks
Return From Interrupt in assembly language. Look in your PIC's datasheet.

There are no "subroutines" in C. Only functions, which kind of work a bit like the same thing, only better. When they get to the end they return automatically, or you can use a Return statement to terminate a function and return a parameter (or not).
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top