Josh Koffman wrote: > > Bob, > > Thanks again! I think I understand now. The PCLATH register doesn't > function the same as the PCL, where a modification to the PCL results in > an immediate jump. So we can modify the PCLATH register and continue on > as if nothing had happened, assuming there is no GOTO or CALL > instruction. When there is, the value of PCLATH is used to compute the > next line of code to be executed. I'm assuming that by modifying the PCL > directly, we force the reading of the PCLATH as well? That's why we can > set the PCLATH to the page with the table, then put our index value in > the PCL, and when that instruction executes, PCLATH is read and we > switch pages. When we execute the retlw, the values for the PCL and > PCLATH are read off the stack, not the registers, so program code > continues back in page one with no problems. But we need to manually fix > PCLATH because if we don't our next GOTO or CALL will be messed up. I > hope that's right? What happens if we get an interrupt while we're > playing with the PCLATH. Assuming I save all my registers at the > beginning of my handler, and restore them at the end, I should have no > problem right? Hi Josh, When the PCL is changed by any instruction, the PCLATH is used to make up the ROM address bits that the instruction can't. For example, a GOTO instruction can only fit 11 bits of address information in it. As the 14 bit PICs are 13 bit addressable, there needs to be two other bits specified somewhere. These 2 bits come from the PCLATH bits <4,3> and are placed into the 13 bit ROM address (PC) in bit positions 12 and 11. This is done automatically whenever a GOTO or CALL instruction is processed. This equates to 2K ROM page boundaries for these two instructions. If the PCL is changed by something like ADDWF PCL, then only 8 bits of address information is available from the instruction itself. So in this case, 5 extra bits need to come from somewhere to make up 13 bits total. These 5 bits also come from the PCLATH in bits <4-0>, and are placed into the ROM address (PC) in bit positions 8 to 12. This is also done automatically whenever an instruction such as ADDWF PCL, SUBWF PCL is processed. This equates to the 256 word ROM boundaries for these type of instructions. RETURN, RETFIE and RETLW instructions pull a complete 13 bit word from the stack and place it directly into the Program Counter, and the PCLATH value 'is not' changed. > As an aside, how do you know if your program crosses a page boundary? I > have never checked, and I know for this program it should be safe to let > my table start on page 3, but how do I know for sure? Warning messages are places in the *.lst file and at the end of the assembly information file providing that these messages are not turned off by a compiler directive. If you want, I can forward you an animated turorial (Windows 95 up) on this subject to help make it a bit clearer. It will be about 600K. -- Best regards Tony mICros http://www.bubblesoftonline.com mailto:sales@bubblesoftonline.com -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu