Need help to store static stings in flahs not in ram !

General discussion on mikroC.
Post Reply
Author
Message
CyberArtem
Posts: 34
Joined: 21 Mar 2009 15:13
Location: Israel

Need help to store static stings in flahs not in ram !

#1 Post by CyberArtem » 05 Feb 2010 16:46

Greetings pros !

I have a small problem regarding MikroC and pic18f4510.
In my program i use a lot of debug messages which i am sending to LCD or to UART. The problem is that the compiler puts the static messages in pics RAM not in FLASH :?
Well , the messages are static so why would it put it in RAM i have no idea.
Does any one have any suggestions about the topic ? How do i put the static messages in FLASH instead of RAM ?

Thanks :wink:

geniusse01
Posts: 10
Joined: 24 Jan 2010 18:59

Re: Need help to store static stings in flahs not in ram !

#2 Post by geniusse01 » 11 Feb 2010 13:30

CyberArtem wrote:Greetings pros !

I have a small problem regarding MikroC and pic18f4510.
In my program i use a lot of debug messages which i am sending to LCD or to UART. The problem is that the compiler puts the static messages in pics RAM not in FLASH :?
Well , the messages are static so why would it put it in RAM i have no idea.
Does any one have any suggestions about the topic ? How do i put the static messages in FLASH instead of RAM ?

Thanks :wink:
hi

usually when u wanna save specific message that wont change all over the program u need to use static before the letters..for example if u wanna save "hello: at ur program u can save it in array like this :

const int save[5]={'h','e','l','l','o'};

when u do this ur message "hello" will be saved in the program memory not at ram.

or u can use writing in eeprom of the pic ..but its limited place to save texts...

try this..and hope this will work with u..good luck..

User avatar
mileta.miletic
mikroElektronika team
Posts: 493
Joined: 05 Jun 2009 14:46
Location: Belgrade, Serbia
Contact:

Re: Need help to store static stings in flahs not in ram !

#3 Post by mileta.miletic » 12 Feb 2010 09:05

Hi,

Put string in flash by declaring it as constant, then in place of call copy it to the RAM by using CopyConst2Ram function defined bellow:

Code: Select all

const char part1[] = "some text";
char msg[16]; //declare array

// copy const to ram string
char * CopyConst2Ram(char * dest, const char * src){
  char * d ;
  d = dest;
  for(;*dest++ = *src++;)
    ;
  return d;
}

void main(){
...
  Lcd_Out(1,1,CopyConst2Ram(msg,part1)); 
...
}
Regards,
Mileta

Mince-n-Tatties
Posts: 2780
Joined: 25 Dec 2008 15:22
Location: Scotland

Re: Need help to store static stings in flahs not in ram !

#4 Post by Mince-n-Tatties » 12 Feb 2010 17:36

mileta.miletic wrote:

Code: Select all

char msg[16]; //declare array
Hi Mileta,

thank you for the professional layout. would the RAM array storage not need to be 17 for using the given function with 16 character displays.

Code: Select all

char msg[17]; //declare array
Best Regards
Mince
Best Regards

Mince

CyberArtem
Posts: 34
Joined: 21 Mar 2009 15:13
Location: Israel

Re: Need help to store static stings in flahs not in ram !

#5 Post by CyberArtem » 13 Feb 2010 14:30

Thanks guys ,the problem solved. Your assistance is much appreciated :D

User avatar
mileta.miletic
mikroElektronika team
Posts: 493
Joined: 05 Jun 2009 14:46
Location: Belgrade, Serbia
Contact:

Re: Need help to store static stings in flahs not in ram !

#6 Post by mileta.miletic » 19 Feb 2010 13:32

Mince-n-Tatties wrote:

Code: Select all

char msg[17]; //declare array
Thanks Mince.
Regards,
Mileta

Post Reply

Return to “mikroC General”