Hello,
I have the following line of code which I need to store in the IDATA memory starting from 92H.
char code *text_to_compare = "Tesing";
How can I achieve this please?
It isn't obvious if you are talking about the pointer or the character array.
But did you start by going to the reference, i.e. looking at the manual? Or did you consider Google?
Trying Google with "keil c51 placing variable in idata" seems to be a rather good start...
I have the following line of code which I need to store in the IDATA memory starting from 92H. in C you do not want absolute addresses char idata *text_to_compare = "Tesing";
you may want to spell "testing" correctly
I am more familiar with assembly and that's why I am finding it difficult to achieve this.
I did search the web and found this:
http://www.keil.com/support/man/docs/c51/c51_le_absvarloc.htm
In this tutorial the code §struct link list idata _at_ 0x40; is used. I tried changing this code from a structure to a string but unfortunately it did not work.
PS: Sorry for my poor English.
"I tried changing this code from a structure to a string but unfortunately it did not work."
And the question then is still if you wanted to move the pointer or the character array to a specific memory region. It really is important to understand the difference between:
char *str = "hello";
and:
char str[] = "hello";
Thanks for the reply. I need to move the character array starting from 92H.
Can you create a pointer and then assign the address of the pointer the memory location 92H.
Then just assign the character data one character at a time.
char * ptr;
ptr = 0x92;
*ptr = 'h'; ptr++;
*ptr = 'e'; ptr++;
*ptr = 'l'; ptr++;
*ptr = '0'; ptr++;
I think this should work.
Again, why this fixation with the absolute address?
Really, that's not the way to be thinking in 'C'!
www.catb.org/.../smart-questions.html
You would have to make sure that it's a specific IDATA pointer
http://www.keil.com/support/man/docs/c51/c51_le_memtypes.htm
http://www.keil.com/support/man/docs/c51/c51_le_ptrs.htm
But before an idata char pointer is used to write data into IDATA RAM, you need to make sure that you "own" that address range within the IDATA RAM.
So it's best to stop thinking about absolute addresses and just have the compiler create a variable (potentially initialized) of type character array within IDATA. And the Keil manuals clearly indicates how to create a variable within IDATA or any other memory region. Then a pointer of type "pointing to IDATA" (note the difference from a pointer stored in IDATA) can access this character array.
While the IDATA memory region is specific to the 8051 processor architecture, there is a lot of similarity with pointers and the "const" keyword. You can have a pointer to const data. I.e. you can't modify the data through the pointer. Or you can have a const pointer, i.e. you can't change the value of the pointer. And similarly, you can have a pointer to IDATA. Or you can have a pointer stored in IDATA.
So in the end, there are two separate things to read up on. One is the C language standard related to additional attributes for pointer types. And one is the Keil manual related to all the C51-specific keywords for specifying size of pointer or memory region.
It is very hard (impossible?) to work efficiently with the 8051 architecture without having read up on these concepts.
And you can have a pointer which is both stored in and points to IDATA.
Just like you can also have a const pointer to const data.
Use the code below:
idata unsigned char imem[6] _at_ 0x92; // creates 6 bytes of storage at 0x92 in // idata space idata unsigned char *text_to_compare; // creates pointer to idata memory text_to_compare = &imem; // assigns pointer to imem
The _at_ allows you to assign absolute memory locations to variables.
If you look at the pointers entry in the C51 manual it describes how to assign pointers to specific memory areas.