If the first thing in the ISR you set bank bits in STATUS and then store W, the STATUS will be corrupted and can't be restored. That's why you'll need to save W in a global RAM area, if this PIC has it, or save it in any bank that STATUS happens to point to. On exit, STATUS will be restored first, and W will be read then from the correct bank. PCLATH is saved and cleared just to prevent jumps to any page except 0, that is where the ISR is located. If you don't have jumps/calls in the ISR, it's not strictly necessary. movf pclath,pclath_temp? <- PIC doesn't have an instruction like that, it can move only between a file register and a working register. Bank aliasing means simply that a PIC, for example, has physical 16 bytes of RAM in upper bank 0, but other banks don't have RAM in that area, and when you address byte 7F in bank 1 (or 2, 3,...), it will be 'redirected' to byte 7F in bank 0. Check the data sheet for which registers are aliased (or mapped) and which are not. You can't assume that for every PIC. Happy PICcing, :) Nikolai ---- Original Message ---- From: Stuart Sent: Thursday, September 21, 2000 10:59:45 To: PICLIST@MITVMA.MIT.EDU Subj: context saving for an isr, Iknow how but I dont'tcompletely understand why > I've been programing pics for a while using Pic Basic Pro but now have the > need to write an assembly language ISR. I've read the manual and I got the > following information from the website > http://204.210.50.240/techref/default.asp?from=/techref/microchip/&url=isrre > gs.htm > I now know how to do it but I don't completely understand why I am doing it > this way. I've added comments to the following code to show where I am > having trouble, my comments start with > ;*************************************************************************** > **************************************************************************** > ********** > ;Interrupt Service Routine Register State Maintenance > ;Tony Nixon quotes the Microchip datasheet for the 16f8xx (and Robert Rolf > added comments): > movwf w_temp ; save work register into w_temp, thats fine but > ; shouldn't i be checking to see > what ram bank i am pointing to first > ;eg. shouldn't i do something like > this > ; bcf status,rp0 ;set bank > selection to bank one > ;bcf status,rp1 ;set bank > selection to bank one > ;movwf w_temp > swapf status,w ;The swapf instruction, unlike the movf, affects NO status > bits, which is why it is used here. yep , I understand this > clrf status ; is this so i am now pointing to bank 0? > movwf status_temp : yep, I understand this > movf pclath,w ; Ok, you are saving the pclath. Is > this incase you were interupted just before you were going to do a goto > movwf pclath_temp ; across page boundry? > ; why can't you do a movf > pclath,pclath_temp? > clrf pclath ;is this just to make sure you > start your isr from a known position? > bcf status,irp ;This bcf is redundant & unnecessary. why is this > unnecessary > movf fsr,w ;I take it the reason you save the fsr is > incase you are using it in your isr and > movwf fsr_temp ;main program > ; ISR > ;The example fails to restore FSR here. > ;One should > movf fsr_temp,w > movwf fsr > ;to complete the restore sequence. > movf pclath_temp,w > movwf pclath > swapf status_temp,w > movwf status > swapf w_temp > swapf w_temp,w > Tom Handley says: > ...one of the nice things about the 16C76/77 and 16F876/877 devices is that > the upper 16 Bytes are aliased to Bank 0. This is a good place to keep a > copy of W, STATUS, PCLATH, FSR, etc, during an ISR routine. > does this mean if i save something into one of the top 16 bytes of > any ram bank in will automaticall be saved in the > other three ram banks? > Thankyou for your help > Regards > Stuart > -- > http://www.piclist.com hint: The PICList is archived three different > ways. See http://www.piclist.com/#archives for details. -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu