This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Saving in 8051 IDATA starting from 92H

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?

Parents
  • 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 = 'l';
    ptr++;

    *ptr = '0';
    ptr++;

    I think this should work.

Reply
  • 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 = 'l';
    ptr++;

    *ptr = '0';
    ptr++;

    I think this should work.

Children
  • 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.