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.

pic interrupt context save and restore

Status
Not open for further replies.

candy66

Newbie level 6
Joined
Dec 17, 2007
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,363
context save +pic

Hey guys....i try to execute this interrupt routine but it is not working.Did i save and restore my context correctly?Can anyone help?


int_serv


movwf savew ;Store the value of w temporarily
movf status,w ;w now has copy of status
clrf status ;ensure we are in bank 0 now!
movwf savestatus ;save status


receive btfss PIR1,5 ; (5) check for received data
goto receive
movf RCREG,w ; save received data in W
movlw 08H ; move it from register 1 to w.
movwf LATB ; move it to PORTB to light up the LED


intclean

movwf status ;restore status! (bank=original)
swapf savew,f ;restore w from *original* bank
swapf savew,w ;swapf does not affect any flags

retfie
 

pic interupts

Looks ok, use the code tags though as they make it easier to read.

You don't need to context save or restore W & STATUS on the 18F unless you're using high priority interrupts.
 

high priority retfie 18f4550

hm..i am using 18F452 low priority interrupts...but it doesn't seem to be working.
 

18f452 interrupt context

That's because you're programming it like a 16F. You need to use
RETFIE FAST
that will pop W,STATUS & BSR off the stack

That goto is it outside the ISR?
 

hm nope....the "goto receive" instruction is in the ISR...and i only enable (INTCON<7>)..is there any other bit i need to set? hm..btw i am using normal interrupt..not using high or low priority anymore=)
 

You have to set the PIE register too.
Have you cleared the flag bit before the return?
It's all in the datasheet. Have you read it for your PIC?
 

Yup...i did set.But it is still not working=(
 

movf RCREG,w ; save received data in W
movlw 08H ; move it from register 1 to w.
movwf LATB ; move it to PORTB to light up the LED

does this:

movf RCREG,w ; move the data from the recieve register to W
>>>movlw 08H <<< ; overwrite the data in W with literal value of 08H
movwf LATB ; set PORTB,3 (08H)


are you sure you want to overwrite the data in W? you havent saved it, and overwrite it with the next instruction
 

Hm...i had already replace the codes:


movlw 08H ; move it from register 1 to w.
movwf LATB ; move it to PORTB to light up the LED

with this:

bsf LATB,3 ;light RB3 led
 

check the highlighted line


intclean

movf savestatus,w ; get the stored status information
movwf status ;restore status! (bank=original)
swapf savew,f ;restore w from *original* bank
swapf savew,w ;swapf does not affect any flags


make sure that you have the org 0x0018 statement

you will find it easier to use the movFF command



this is an example of how the template files normally code a low priority interupt


Code:
;Low priority interrupt vector and routine
; This code will start executing when a low priority interrupt occurs.
; This code can be removed if low priority interrupts are not used.

		ORG	0x0018
		goto	LPINT  ;include this if you use a linker

the code   ;include this if you use a linker
LPINT    ;include this if you use a linker

		movff	STATUS,STATUS_TEMP	;save STATUS register
		movff	WREG,WREG_TEMP		;save working register
		movff	BSR,BSR_TEMP		;save BSR register

;	*** low priority interrupt code goes here ***


		movff	BSR_TEMP,BSR		;restore BSR register
		movff	WREG_TEMP,WREG		;restore working register
		movff	STATUS_TEMP,STATUS	;restore STATUS register
		retfie


if it is none of those things please provide more details as to the nature of the problem such as:

1) is it assembling?
2) does any part of the system run?
3) do you have any information on how it simulates?
4) are you sure that everthing else is set up properly in the controlling registers?
5) any other usefull information as to what you can see happening!
 

i working on Rs232 serial communication(com to picdem 2 plus).when a byte have been recieved, the LED will led up.Hm...i mange to run high priority interrupt(which does not need to save and restore context right?)...But When i change it to low priortity(with or without save and restore context) it still work like high prortity.
Did you know wad i mean?Below are some of the registers that i have set.Thx


<ORG 0x0018 ;interrupt vector addresses>
.
.
.
.
bsf RCON,7
bsf PIE1,5 ; enable usart interrupt
movlw b'11000000'
movwf INTCON
bcf INTCON,1 ;INTF - Clear flag bit just in case
 

But When i change it to low priortity(with or without save and restore context) it still works like high prortity


if it is branching to the wrong vector,

check:

IPR1 <5>

this bit tells the interupt hardware whether to treat a USART interupt as a high or low priority interupt and decides which origin the program branches to.

i mange to run high priority interrupt(which does not need to save and restore context right?)

high priority interupts using the "retfie FAST" automatically save and restore the 3 main registers, but only these 3 registers.

retfie 0 will not use the automatic context restore.
use this for the low priority interupt
manually implement the context save and restore.

we do this because a high priority interupt can interupt a low priority interupt and you will need the fast to return from the high priority to the low priority.

if you have set up the IPR bits and it is still branching to the wrong vector, check that there are no other interupts active. (it may be branching to the low priority vector only to be interupted by a high priority interupt from elsewhere
 

I can not post long replies (I still don't know why)

Try to PM me and I will try to send you my two ISR codes for low and high priority
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top