• AVR Freaks

Hot!Passing a string in XC8

Author
Wiizzer
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2021/01/10 10:41:00
  • Location: 0
  • Status: offline
2021/01/16 11:50:43 (permalink)
0

Passing a string in XC8

Hi,
I'm using MPLAB X IDE v1.63,  XC8 v2.31 and a Pickit 3 to write to a PIC18F67k40 on a MIKROE Click 2.
 
For some reason I am unable to pass a fixed string (const char*) to a function
 
const char buff1[]="String1";     // string in Program memory
 
void WriteStr(const char *str)     // function using the string
{...process str ...}
 
using
        WriteStr("String0"); 
or
        WriteStr(buff); 
 
I can see the text in program memory (at E01) and the address is passed to the function, but I believe that this is RAM address and has not been converted for Program Memory.  The compiler seems to be using the right address but looking in the wrong memory block. I believe the compiler should automatically use the correct address as XC8 does not seem to have a ROM type/command like XC16. I have tried several variant of this code with arrays, pointers, statics , const and normal char without success. I have used similar code on other systems, so I am thinking that it is more likely to be the compiler options or development environment.
 
Thanks
Paul
#1

7 Replies Related Threads

    mbrowning
    USNA79
    • Total Posts : 1874
    • Reward points : 0
    • Joined: 2005/03/16 14:32:56
    • Location: Melbourne, FL
    • Status: offline
    Re: Passing a string in XC8 2021/01/18 09:23:37 (permalink)
    +3 (3)
    Read the errata sheet for your part and implement the fix. I believe turning on the "NVMREG" fix in XC8 will do it.
    Always read the errata sheet for any IC. It's as important as the datasheet.
    #2
    ric
    Super Member
    • Total Posts : 29861
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Passing a string in XC8 2021/01/18 12:20:19 (permalink)
    +1 (1)
    +1
    There's some more background in this thread: https://www.microchip.com/forums/m969418.aspx
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #3
    Wiizzer
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2021/01/10 10:41:00
    • Location: 0
    • Status: offline
    Re: Passing a string in XC8 2021/01/19 13:18:25 (permalink)
    0
    That seems to have sorted it. THANX!!
     
    Just a small observation...
    The code seems to work by copying the data from the Program Memory, but the pointer seen in the Variables window still seems to look at RAM.
    #4
    ric
    Super Member
    • Total Posts : 29861
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Passing a string in XC8 2021/01/19 13:52:27 (permalink)
    +2 (2)
    If the array is defined inside a function rather than global or static, then it IS in RAM. can't tell from the isolated snippet you have posted.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #5
    ric
    Super Member
    • Total Posts : 29861
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Passing a string in XC8 2021/01/23 14:43:12 (permalink)
    +1 (1)
    There is a missing post in this thread by "OscarTheGrouch".
    I assume it contained one of the Firewall trigger words.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #6
    OscarTheGrouch
    Super Member
    • Total Posts : 368
    • Reward points : 0
    • Joined: 2010/11/29 18:07:28
    • Location: 0
    • Status: offline
    Re: Passing a string in XC8 2021/01/25 09:18:52 (permalink)
    +1 (1)
    ric
    There is a missing post in this thread by "OscarTheGrouch".
    I assume it contained one of the Firewall trigger words.

    LOL, I triggered something? Is the FBI going to visit? ;)
    #7
    Jump to:
    © 2021 APG vNext Commercial Version 4.5