Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
Posted: Mon Sep 19, 2005 1:44 am
From page 1 of the compiler manual:
Quote:
The compilers have some limitations when compared to a more traditional C
compiler. The hardware limitations make many traditional C compilers
ineffective. As an example of the limitations, the compilers will not permit
pointers to constant arrays. This is due to the separate code/data segments in
the PICmicroŽ MCU hardware and the inability to treat ROM areas as data.
Your problem is caused by the PIC processors having seperate memory areas for data and program memory. The constant data string must be stored in ROM program memory (or it would be lost at power down) but in CCS a char pointer always points to RAM. The C language offers no default method for solving these types of memory conflicts and every compiler vendor provides it's own solution (often in a seperate linker/locator module).
There are a few solutions to work around the pointer problem, the most common is to first copy data from ROM to RAM and from then on everything works as usual.
Code:
char string[25];
strcpy(string, "This will work.");
A second very powerfull workaround can be found on page 71 of the CCS manual:
Quote:
A (non-standard) feature has been added to the compiler to help get around the
problems created by the fact that pointers cannot be created to constant strings.
A function that has one CHAR parameter will accept a constant string where it is
called. The compiler will generate a loop that will call the function once for each
character in the string.
Example:
void lcd_putc(char c ) {
...
}
lcd_putc ("Hi There.");
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum