Date: Mon, 16 Dec 1996 09:38:30 -0500 From: Kenneth Furge <kennethf@ehusa.com> Organization: Endress+Hauser To: eric@brouhaha.com Subject: Quick addendum to your PIC interrupt page.... Great job on the PIC interrupt page! After fighting with an ISR using the ByteCraft compiler, I found your page and it had some very useful pointers. I have a possible addition to the page (a potential 3b). It turns out that the compiler switches register banks within the ISR. Therefore, after saving the w register and the status, you must also save the register bank where you came from. Otherwise when you go to restore w and status, you have a 50/50 shot of restoring them from the wrong window! It's pretty obvious now (as most bugs are) but it would be a good addition to your PIC ISR FAQ. The follwing wrapper will allow you to use both window 0 and 1 variables within your ISR and not corrupt anything in the process. Here's a code segment to help illustrate the point. "stat" is just misc status bits used within the program, temp_w and temp_stat are self explanatory. void __INT(void) { #asm movwf temp_w ; "Push" important registers swapf STATUS,W movwf temp_stat btfsc STATUS,5 ; Are we in file bank 1? goto win1h win0h bcf stat,1 ; Remember where we came from win 0 goto end_isr_head win1h bcf STATUS,5 ; Switch to win 0 where "stat" is bsf stat,1 ; Set bit to indicate we came from win 1 end_isr_head #endasm /* PUT ISR C CODE IN HERE */ #asm bcf STATUS,5 btfsc stat,1 ; did we come from bank 1? bsf STATUS,5 win1t swapf temp_stat,W ; "Pop" important registers movwf STATUS swapf temp_w,F swapf temp_w,W #endasm } - K.C. Furge
Last updated December 16, 1996