Table in upper 255 bytes of PIC16F819

Discussion in 'Embedded Systems and Microcontrollers' started by Markd77, May 1, 2010.

  1. Markd77

    Thread Starter Senior Member

    Sep 7, 2009
    MPLAB 8.36 seems to be miscalculating the amount of space needed for a table. Does anyone have a workaround?

    The pic has 0x7ff bytes of program memory.
    If I try to put
    org 0x6ff
    addwf PCL, F
    and then 255 bytes of table I get the out of space error.

    I put it at 0x5ff and all was well.

    As a test I then added 11 lines to the table and got the below error which suggests that mplab thinks the table was 534 bytes long (twice as big as it actually is).

    Then I put org 0x700 before the extra 11 lines and again it compiled fine.

    I think it would work if I put org before every line of the table but that is a lot of typing. Does anyone know a better way?

  2. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    Are you using a single retlw for each table value?

    The PIC program memory space is words rather than bytes, 14 bits wide on the 16F819.

    I wonder if something is getting confused somewhere between Byte & Word addresses or sizes..
  3. Markd77

    Thread Starter Senior Member

    Sep 7, 2009
    The left column is the location in program memory. I did mean words instead of bytes, sorry.
    It should definitely fit if I move it to 0x6ff but MPLAB isn't liking it.

  4. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    If you start it at 5FF with 255 entries, what is the highest address shown in the listing?

    Just a thought - do you have ICD enabled for debug? That reserves some program & memory space.
  5. Markd77

    Thread Starter Senior Member

    Sep 7, 2009
    Highest address shown is 06FE.
    _DEBUG_OFF in my config so I think that should be fine.

    I've just had another play and if I put org 0x700 it compiles fine, if I put org 0x6FF it gives me the not enough space error.

    I guess that solves it but I have no idea why.
  6. retched

    AAC Fanatic!

    Dec 5, 2009
    Can you do a memory dump to see what is in the locations that are causing the error?
  7. Markd77

    Thread Starter Senior Member

    Sep 7, 2009
    It's all sorted now. I think it must be some problem with MPLAB. If I comment out the org 0x700 line, it says it won't fit in program memory, although it shouldn't make any difference.

    Code ( (Unknown Language)):
    1. 1159:  
    2.                                                   1160:  
    3.                                                   1161:  org 0x6ff
    4.                                                   1162:  asin
    5.    6FF    0782     ADDWF 0x2, F                   1163:      addwf PCL, F
    6.                                                   1164:  org 0x700
    7.    700    3440     RETLW 0x40                     1165:      retlw D'64'
    8.    701    3445     RETLW 0x45                     1166:      retlw D'69'
    9.    702    3447     RETLW 0x47                     1167:      retlw D'71'
    10.    703    3449     RETLW 0x49                     1168:      retlw D'73'
    11.    704    344A     RETLW 0x4a                     1169:      retlw D'74'
    12.    705    344B     RETLW 0x4b                     1170:      retlw D'75'
    13.    706    344C     RETLW 0x4c                     1171:      retlw D'76'
    14.    707    344D     RETLW 0x4d                     1172:      retlw D'77'
    15. .
    16. <section cut>
    17. .
    18.    7FA    34B4     RETLW 0xb4                     1415:      retlw D'180'
    19.    7FB    34B5     RETLW 0xb5                     1416:      retlw D'181'
    20.    7FC    34B6     RETLW 0xb6                     1417:      retlw D'182'
    21.    7FD    34B8     RETLW 0xb8                     1418:      retlw D'184'
    22.    7FE    34BA     RETLW 0xba                     1419:      retlw D'186'
    23.    7FF    34BF     RETLW 0xbf                     1420:      retlw D'191'
    24.                                                   1421:  
    25.                                                   1422:  
    26.                                                   1423:  
    27.                                                   1424:  ; initialize eeprom locations
    28.                                                   1425:  
    29.                                                   1426:  ;    ORG    0x2100
    30.                                                   1427:  ;    DE    0x00, 0x01, 0x02, 0x03
    31.                                                   1428:  
    32.                                                   1429:  
    33.   2007    34BF     RETLW 0xbf                     1430:      END                       ; directive 'end of program'
  8. corsair


    Mar 6, 2010
    Hi Markd,

    I had a similar problem not too long back. "eblc1338" posted a working solution for me. What's happening is that the table is crossing a frame and it's causing an error in the jump.

    If you're still interested, the thread is located here: