Sunday, February 22, 2009

How to use ROM for storing DATA in MikroC Avoid Error Not Enough RAM and Strings problem (const truncated)

Most of the Microcontrolleres having limited RAM, For Avoiding the Errors Not Enough RAM and Strings problem (const truncated) .
You have to move the strings to ROM (FLASH program) memory, and there by save RAM.

In MikroC
if the string is declared as constant - compiler will move it to ROM
This is the way in which const truncated problem can be solved if
great number of strings was used that was located in RAM.

How we can impliment it in MikroC, see the example

First you declare the following

char text[15]; // this is stored in RAM
const char *mesg1="shibuvarkala1234"; // this is stored in ROM
const char *mesg2="CE Attingal"; // this is stored in ROM

here is the function for copying string before the usage ,
copy the following function to your code( Received from Mikroelecronica) :

// --- Copying strings from ROM to RAM
void strConstCpy(char *dest, const char *source) {
*dest++ = *source++ ;

*dest = 0 ;

you have to use the above function to access the strings stored in ROM,

LCD_Out(1,1,text); // Now output is shibuvarkala1234

LCD_Out(1,1,text); // Now output is CE Attingal


jamal said...

hi im jamal from karachi, pakistan,using ccs compiler forpic16f877a,what do i type code to generate PWM

NetoMX said...

Thank you! solved me many problems

Anonymous said...

thanks bro help me.. whew

Anonymous said...

Very good. Thanks.