PIC Program Jumps to Unexpected Location but

Discussion in 'Embedded Systems and Microcontrollers' started by icedtea, Sep 15, 2011.

  1. icedtea

    Thread Starter New Member

    Aug 28, 2010
    10
    0
    I am programming a fairly large project that is approaching, but has not yet passed the Page1 (0x7FF) boundary of the program memory space. I did run into this a little before with the same program with a CALL to a Look-Up Table and looked for a solution. One of the answers involved setting the PCLATH register. The program size at that time was still below the Page 1 boundary.

    I did use the PCLATH code to correct that problem which was:

    Code ( (Unknown Language)):
    1.  
    2.   MOVLW   HIGH TABLE    ; Load High 8-bit Address of TABLE
    3.   MOVWF   PCLATH        ; into PCLATH
    4.   CALL    TABLE
    5.  
    It worked, but it doesn't make much sense to me. I've read the Datasheet, searched online extensively but it does not seem like this should not be happening if I'm within and stay within the 1st Page, right?

    Now I'm running into the same thing again, I think, when I call a general subroutine. The question I have is: Why is this even happening when I'm staying within the boudary of the 1st Page of Program Memory?

    I'm using MPLAB IDE, PICKit2 Programmer, 16F917 MCU, 3 pushbuttons, 16x2 LCD display, 2Kbit EEPROM memory chip, 4 16F54 slave MCUs via parallel connection to the 16F917 master. Everything has been working extremely well...just a few bumps in the road along the way that have lead to an educational experience. :-D

    Thanks again everyone, you have lead me to answers before and love this forum.
     
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
  3. icedtea

    Thread Starter New Member

    Aug 28, 2010
    10
    0
    Thank you for the quick reply. This is an appnote that I came across when I ran into the first jump to an unexpected location within the program code with a table look-up. I guess it will work with a subroutine call too. I just don't understand why this is happening while I'm still within the 1st page of program memory. Perhaps PCLATH is being changed by another instruction before this call. Thanks again, I really do appreciate the help!
     
  4. icedtea

    Thread Starter New Member

    Aug 28, 2010
    10
    0
    Checking again revealed that I placed the CLRF PCLATH in the wrong location leading to the unexpected jump to the wrong location in the program code. Thanks for bearing with me. JP
     
Loading...