Aubrey McIntosh, Ph.D. wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > source= http://www.piclist.com/piclist/2003/09/10/074104a.txt? > > Thanks all for the comments. > > Part of my confusion was that I did not pay attention to the > difference between figure 2-3 and 2-4. The large parts, '876 '877, > do map '70 -'7F in common and it seems proper to allocate the save > frame in that area. The '874 part only maps PCL, STATUS, FSR, > PCLATH, and INTCON across the banks. No General Purpose registers > are mapped across. (I have not looked at the '-A' datasheet, but my > samples are in now, and maybe it is time ... Who knows? perhaps it > is all fixed. ) AFAICT, the -A parts work exactly the same in this regard. > My experience with a PIC is new, but I have mature assembly > experience. I will make a .o file with the context save code, put it > in a library, and modify the .lkr file to put this in the memory that > I want. On the 16F874 part that I am using, I have modified the > START definition of gpr1 so that the address 0xA0 is never allocated. > When this code is stable, tested, and edited for clarity I'll put it > on my Web page. The ideas are sketched out here: > > in Application.asm > GLOBAL Hook > RESET CODE H'000' > ; ORG 0x000 ; processor reset vector > goto Main ; go to beginning of > program > > > BODY CODE > Hook ;handle the IRQs > return ;to the middle of the context save restore at 004 > > > - ---- > in IRQContext.asm > EXTERN Hook > INTERRUPT CODE H'004' > ; ORG 0x004 ; interrupt vector location > movwf w_temp ; save off current W > register contents > ... > call Hook > ... restore and retfie > > project.lkr > SECTION NAME=RESET ROM=vectors > SECTION NAME=INTERRUPT ROM=vectors > DATABANK NAME=gpr1 START=0xA1 END=0xFF //Does 0x20 & > 0xA0 map together? > > My concern is that the template and code examples are misleading. > From the responses, I gather that the consensus is emerging that 1) > indeed the '874 '877 distinction is subtle, 2) the register support > on the '874 is too weak and incorrectly documented, 3) there are some > fixes at either code writing time or linker time (if using > relocatable code). > > > The question that follows this is : what is the procedure to submit a > correction recommendation to Microchip? Also, if the "-A" part fixes > this, I'll just move on ... It's not that there is a bug in the chip or that the documentation is wrong, just a design inconvenience. Without the common RAM it makes it slightly more tricky to save context, but not impossible. The following code was cut/pasted from the datasheet so it should work well for you. The key is that W_TEMP must be allocated in each bank at the same location (e.g. 7F, FF, 17F, 1FF) as you don't know where it's going to get plunked down at the beginning of the ISR. This is because you don't know which bank is currently selected. All other temp storage locations need be allocated in Bank 0 only. Don't forget to save/restore FSR if you use that in the ISR. MOVWF W_TEMP ;Copy W to TEMP register SWAPF STATUS,W ;Swap status to be saved into W CLRF STATUS ;bank 0, regardless of current bank, Clears IRP,RP1,RP0 MOVWF STATUS_TEMP ;Save status to bank zero STATUS_TEMP register MOVF PCLATH, W ;Only required if using pages 1, 2 and/or 3 MOVWF PCLATH_TEMP ;Save PCLATH into W CLRF PCLATH ;Page zero, regardless of current page : :(ISR) ;(Insert user code here) : MOVF PCLATH_TEMP, W ;Restore PCLATH MOVWF PCLATH ;Move W into PCLATH SWAPF STATUS_TEMP,W ;Swap STATUS_TEMP register into W ;(sets bank to original state) MOVWF STATUS ;Move W into STATUS register SWAPF W_TEMP,F ;Swap W_TEMP SWAPF W_TEMP,W ;Swap W_TEMP into W I'm glad you brought this up because I finally understand how to deal with it. michael brown > > ******** > > B. Pearce wrote: > >> Well as he is using a 16F87x it is better to have it saved in the >> 0x70-0x7f region where the same ram is shared between all banks. Then >> it does not matter which bank you are in on interrupt entry. > > He's apparently using a 16F873 or 16F874. According to the datasheet, > there is no shared ram between Bank 0 and Bank 1. I have wondered the > same question about how to properly save context on these particular > chips. > > michael brown > > > > - --- > Aubrey McIntosh > http://www.piclist.com/member/AM-vima-Y84 > PIC/PICList FAQ: http://www.piclist.com > > > -----BEGIN PGP SIGNATURE----- > Version: PGPfreeware 7.0.3 for non-commercial use > > iQA/AwUBP181YAKlSw8yssF7EQII5QCgtSzll2lkuo2YmIPcOwrrLVxhHNkAnAr8 > sn/BtN3ibfq4i4mRqoKKLUpq > =gfOb > -----END PGP SIGNATURE----- -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics