From: George Neuner on
On Mon, 09 Aug 2010 07:52:07 -0500, "etmax"
<max(a)n_o_s_p_a_m.einstein-tech.com.au> wrote:

>I've created an array of bitmaps for an LCD display (6 bytes per character)
>and when I tried to define an array of addresses of the bitmap arrays Code
>composer allocated them in RAM even though I said they were const, so I
>cast them as an array of ints.

Why do you think "const" should change where the pointers are stored?
If you need them to be in a particular segment you need to put them
there explicitly.

>I had planned to get a pointer to the first address then use array
>terminology to get the address of the bit map for the current char but I
>keep on getting a char not an int back.
>
>Can anyone tell me where I went wrong please
>
>const uint Chars0[] = {(uint)&Data0020,(uint)&Data0020,(uint)&Data0020};
>uchar *CharPtr;
>CharPtr = (uchar*)&Chars0 //this works ok (points to the first element)

Your data is integer but you're addressing it as char.

>CharPtr = (uchar*)((uint)CharPtr[Char]); // this puts in only one byte of
>the address??

This line makes no sense at all - it's trying to load the first byte
of character data as a pointer. I'm pretty sure that's not want you
wanted. I think you want something like:

const uint Chars0[] = { ... }
uint *CharPtr = &Chars0
uint data = CharPtr[index]; // where index is 0..2


Even better would be to define a struct for the character data even
though the data is just an integer array. That way, the compiler will
do the math for you when you index in the array of characters.

typedef struct { int data[3]; } Character;
Character Font[] =
{ { ... },
{ (uint)&Data0020,(uint)&Data0020,(uint)&Data0020 },
{ ... }
};
uint data = Font[ /* 0..numChars */ ].data[ /* 0..2 */ ];


And try not to use variables with names like "Char" ... it's too easy
to mistype them and get errors from the compiler. I know this is
difficult when you're playing with fonts because the logical names to
use are variations on "character". But don't do it.

George
From: Albert van der Horst on
In article <atudnZcl8OVqZMLRnZ2dnUVZ_vmdnZ2d(a)giganews.com>,
etmax <max(a)n_o_s_p_a_m.einstein-tech.com.au> wrote:
>I've created an array of bitmaps for an LCD display (6 bytes per character)
>and when I tried to define an array of addresses of the bitmap arrays Code
>composer allocated them in RAM even though I said they were const, so I
>cast them as an array of ints.
>
>I had planned to get a pointer to the first address then use array
>terminology to get the address of the bit map for the current char but I
>keep on getting a char not an int back.
>
>Can anyone tell me where I went wrong please

You are barking up the wrong tree, so to say.
You are talking to the compiler, but the compiler doesn't decide in what
sections data go.
That is the task of a program, that is called linker, linking loader or
sometimes loader. So you have to summon up the linker and tell it your wishes.
This can be complicated in a IDE, that does everything automatically.

>
>const uint Chars0[] = { (uint)&Data0020,(uint)&Data0020,(uint)&Data0020};
>
>uchar *CharPtr;
>
>CharPtr = (uchar *)&Chars0 //this works ok (points to the first element)
>
>CharPtr = (uchar*)((uint)CharPtr[Char]); // this puts in only one byte of
>the address??

Put this data in a separate file and generate a separate object file.
Then tell the linker, via link file, link configuration, linker script, makefile
or some such that you want it in ROM. This depends on your IDE and only
people with experience with your exact IDE can give more details.

>
>What am I doing wrong?

I wouldn't call it wrong. You're missing an insight that IDE's try to
hide it from you.

>
>---------------------------------------
>Posted through http://www.EmbeddedRelated.com

Groetjes Albert

--
--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert(a)spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst