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.

Multiple Indirect addressing Code Problem

Status
Not open for further replies.

Suraj143

Active Member
I’m using 10 GP registers in the ISR to show the display. For that I’m using indirect addressing. (Only reads the INDF)

In my main menu also I’m using indirect addressing to update the above 10 GP registers.(Writing to INDF)

I’m using the same 10 GP registers in both cases.

Problem is the display is working nicely. But the update stuff never happens.

Do I have to save something in the ISR? I’m using only bank0 in PIC16F628A.
 
You should save (and restore) FSR in your ISR. If that doesn't work then post your code.

Mike.
 
Hi mike thanks for the help.

Is this correct way to save FSR?

Code:
Save_Context	movwf   WT           	;save W register 
		[COLOR="Red"]movf	FSR,W
		movwf	S_FSR		;save FSR	[/COLOR]	
		movf	STATUS,W        ;move status register into W register
		movwf	STAT
		movfw	PCLATH
		movwf	p_temp		;Save PCLATH 

		---
		---
		---

Rest_Context	movfw	p_temp
		movwf	PCLATH		;Restore PCLATH
		[COLOR="Red"]movf	S_FSR,W
		movwf	FSR		;Restore FSR[/COLOR]
		movf    STAT,W     	
		movwf	STATUS          ;restore STATUS register
		swapf   WT,F
		swapf   WT,W          	;restore W register		
		retfie
 
No, you have to save FSR after you save STATUS,

Code:
Save_Context	movwf   WT           	;save W register 
		movf	STATUS,W        ;move status register into W register
		[COLOR="Red"]clrf	STATUS[/COLOR]
		movwf	STAT
		movf	FSR,W
		movwf	S_FSR		;save FSR		
		movfw	PCLATH
		movwf	p_temp		;Save PCLATH

You should also clear status (as shown) so that variables STAT, S_FSR and p_temp can be in the normal (bank 0) area. WT still has to be in the common area (0x70-0x7f).

Mike.
 
No, you have to save FSR after you save STATUS,

Code:
Save_Context	movwf   WT           	;save W register 
		movf	STATUS,W        ;move status register into W register
		[COLOR="Red"]clrf	STATUS[/COLOR]
		movwf	STAT
		movf	FSR,W
		movwf	S_FSR		;save FSR		
		movfw	PCLATH
		movwf	p_temp		;Save PCLATH

You should also clear status (as shown) so that variables STAT, S_FSR and p_temp can be in the normal (bank 0) area. WT still has to be in the common area (0x70-0x7f).

Mike.

A very very good comment you did.That will be work for sure.I'll try & tell the latest progress.

Thanks for the excellent correction.
 
I would also suggest you rethink your programming - it's important to keep an ISR as short and fast as possible - you certainly don't normally want to be doing display routines in there (with the exception of multiplexing for them).
 
Hi Mike after saving context correctly it was worked perfectly.That was a really good point.

Thanks Mike.

Nigel I'll think about your idea thanks for that hint. :)
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top