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.

need help about saving and retrieving the W reg during interrupt handling in assembly

Status
Not open for further replies.

Noman Yousaf

Full Member level 4
Joined
Nov 19, 2003
Messages
208
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
Lahore Pakistan
Activity points
1,763
urgent help is needed please

i am facing the problem that in my software (in assembly language).
i am using timer interrupt in 16f72. there is some calculation which is done by w reg.
during calculation, when timer interrupt occurs, the value of w reg is disturbed.
when w reg goes to work for interrupt, then comes back after ISR, value has been changed.
actually problem is, when interrupt occurs, on very next step when i have to save the the w reg in any file reg, value of w reg is changed before even go to ISR (interrupt service routine).
so wrong value of w reg is saved.
please tell the appropriate solution to save then retrieve the value of w reg.
 

Hi,

When entering isr w reg is unchanged --> before you use it in isr push it on stack
Before leaving isr pop w reg from stack.

Klaus
 

You have not stated which assembler you are using. Assuming it is MPLAB or MPLABX, look in the templates for the best way to do it. You should also save the STATUS register because it holds the bank select bits, if you change those the ISR will return to the wrong address. As a general rule, always copy the template file then build the rest of your code around it.

This is an extract of Microchip's template for the 16F72:
Code:
;***** VARIABLE DEFINITIONS
w_temp		EQU	0x20		; variable used for context saving
w_temp1		EQU	0xA0		; reserve bank1 equivalent of w_temp 
status_temp	EQU	0x21		; variable used for context saving

;**********************************************************************
	ORG     0x000             ; processor reset vector

  	goto    main              ; go to beginning of program


	ORG     0x004             ; interrupt vector location

	movwf   w_temp            ; save off current W register contents
	movf	STATUS,w          ; move status register into W register
	bcf     STATUS,RP0        ; ensure file register bank set to 0
	movwf	status_temp       ; save off contents of STATUS register


; isr code can go here or be located as a call subroutine elsewhere


	bcf     STATUS,RP0        ; ensure file register bank set to 0
	movf    status_temp,w     ; retrieve copy of STATUS register
	movwf	STATUS            ; restore pre-isr STATUS register contents
	swapf   w_temp,f
	swapf   w_temp,w          ; restore pre-isr W register contents
	retfie                    ; return from interrupt

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top