1
\$\begingroup\$

Im using MPLAB IDE & C18 compiler to program Pic18f2550. I have to initialize a const string in program memory to save space in RAM how do I do it ?

\$\endgroup\$

1 Answer 1

4
\$\begingroup\$

To put a constant string in data memory you need to use the rom qualifier in C18 compiler:

rom const char[] = "some string";

EDIT: As an advice for future questions you might have regarding the C18 compiler (or any other compiler, for that matter): please read the compiler's manual before asking for help. I haven't used the C18 in a while and I had to look up the information you needed. It only took me 2 minutes to find the manual on the internet and look for the relevant information. I'm talking from experience when I'm saying that it's much more rewarding to find the answers yourself than to ask someone for help, especially when the information is easily available.

\$\endgroup\$
7
  • \$\begingroup\$ Yes, that's it - "rom". Got there just before me :-) My answer is incorrect and I'll delete it. \$\endgroup\$
    – carveone
    Commented Jul 22, 2014 at 10:07
  • \$\begingroup\$ @carveone Yeah, you're answer is only valid for XC8 and HI-TECH PICC compilers \$\endgroup\$
    – m.Alin
    Commented Jul 22, 2014 at 10:08
  • \$\begingroup\$ Yes, I posted first and then reread the question! \$\endgroup\$
    – carveone
    Commented Jul 22, 2014 at 10:09
  • \$\begingroup\$ Interesting. Does the compiler not recognize string literals and do this for you? I use AVR, but I vaguely recall something similar (PGM, I think) as a "place this into flash" qualifier. \$\endgroup\$
    – sherrellbc
    Commented Jul 22, 2014 at 12:17
  • 1
    \$\begingroup\$ @KGregory Data memory (SRAM) in microcontrollers is usually much smaller than program memory (Flash). So, if you're running out of data memory, you could put constant variables in program memory to save SRAM space. The downside of variables in program memory is that they take a longer time and more instructions to access. \$\endgroup\$
    – m.Alin
    Commented Jul 23, 2014 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.