Allocating constants in program memory

General discussion on mikroC PRO for AVR.
Post Reply
Author
Message
djolea
Posts: 24
Joined: 15 Oct 2011 11:56

Allocating constants in program memory

#1 Post by djolea » 03 Feb 2016 11:03

I have an issue:
How to put constant string (as explained in help file under 'code') into program memory?
If u use LCD example, and change

Code: Select all

 char txt1[] = "mikroElektronika";
into

Code: Select all

code const char txt1[] = "mikroElektronika";
, compiler reports " Illegal pointer conversion"

User avatar
lana.arsic
mikroElektronika team
Posts: 1715
Joined: 15 Jan 2016 12:50

Re: Allocating constants in program memory

#2 Post by lana.arsic » 04 Feb 2016 11:12

Hi,

The way for putting constant string into program memory, described in Help menu, is correct.

The reason why you get Illegal pointer conversion error message is because you use LCD_Out function which accepts pointer to variable in RAM.
And your text is declared as constant.

You can avoid this if you add a function which will copy ROM content into RAM before displaying.
For doing that, please follow this thread:

http://www.mikroe.com/forum/viewtopic.p ... am#p119155

Best regards,
Lana

djolea
Posts: 24
Joined: 15 Oct 2011 11:56

Re: Allocating constants in program memory

#3 Post by djolea » 04 Feb 2016 11:39

Thanks!
That will do the job.

Post Reply

Return to “mikroC PRO for AVR General”