On Tue, 20 Jan 1998 11:45:35 -0500 "Najemy, Daniel" writes: >Thanks Harold - I'm certainly learning this the hard way - you >solution >works really well. I was also switching to the incorrect bank as well. > No problem, Daniel. I KNEW of this problem yet still did not see it in some of my own code. In my case, it appeared that an interrupt routine was corrupting w even though the context (including w) was saved on going into an interrupt. I posted the code on the list and someone pointed out that my disableIRQ actually just put a delay in there to allow the port to settle. The problem wasn't the interrupt at all. So I changed to code similar to what I sent you. I've also done a few macros so I don't have to remember which bit does what for banks and interrupts. I think they're real useful. Here they are... ;----------------------MACRO DEFINITIONS------------------------------------------------ DisableIRQ macro local DIRQloop ; Declare local symbol in macro DIRQloop bcf intcon,gie ; disable global interrupts btfsc intcon,gie ; make sure it's clear goto dirqLoop ; if not, go clear again endm EnableIRQ macro bsf intcon,gie ; set global interrupt enable endm cblock ; reserve ram for save and restore context isrW ; Hold registers during ISR isrStatus isrFSR endc SaveContext macro ; Save register context for isr. Swaps swap high and low halves of f with the result going either ; back to f or to w. Swap is used here because they affect no status bits. movwf isrW ; Save W swapf status,w ; get status in W (including bank select bits) swapping hi/lo halves bcf status,rp0 ; force to bank 0 movwf isrStatus ; and save swapped status movf fsr,0 ; Get fsr in w movwf isrFSR ; and save it endm RestoreContext macro movf isrFSR,0 ; get old fsr movwf fsr ; and restore it swapf isrStatus,w ; get old status (including bsr bits) in w, swapping back to normal movwf status ; restore it swapf isrw,1 ; swap halves in isrw making them backwards swapf isrw,0 ; swap back to forward and in W without affecting status endm Bank1 macro bsf status,rp0 ; Set bank select bit endm Bank0 macro bcf status,rp0 ; Clear bank select bit endm Harold