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.

interrupt with pic16f876a

Status
Not open for further replies.

CEstudent

Junior Member level 1
Joined
Feb 13, 2008
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,396
pic16f876a call

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 go another location .

so i tested my code i 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
	
	
	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
 

bank0 in pic16f876a

Hello.

To save the status you cant save like you did, because movf change the flag z FROM STATUS. to save the status you have to do this:

SWAPF STATUS,W
MOVWF STATUS_T

and at the end of the interrupte routine:

SWAPF STATUS_T,W
MOVWF STATUS.

i dont know if this is the problem, but make sure if you are working in the right bank.
By the way what is the purpose of the program???????
 

delay pic16f876a

hey eraser

this code is just a test to check if the interrupt is working well or not to use it in my project code

my problem is that am using goto instead of RETFIE because i dont want it the return to the same place

and the thing i'v added is that i set the GIE

BSF INTCON,GIE ;Enable Global Interrupt

and still the interrupt is happen just once!!
 

adcon1 pic 16f876a

Why you dont want return to the same place????, i dont understand that.

I think one interruption must has the RETFIE at the end , but i am not sure.
Goto to 877A datasheet, instructuion set summary, see the REFTFIE instruction.
My friend told me he had the same problem, because he didnt use the retfie.

Try put retfie in your code and see the results.
 

interrupt pic16f876a

Hi,
One way to do is to POP out the current address from the Stack, then PUSH in the new address you want to jump to and then execute a RETI. If you you do not execute a RETI, your stack will overflow. I suppose it should be possible to do with PIC.

Regards,
Laktronics

Well, as it appears PIC does not support manipulation of Stack contents as with 8051, and as such, you can not change the return address after interrupt.

Regards,
Laktronics.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top