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

look up table

i am trying to use code memory space to store some constants patterns. to do this, i have defined an array in code memory space as follows:

unsigned char code A[]={0x00,0x3F,0x50,0x90,0x50,0x3F,0xAA};

it doesn't work at all or sometimes i get unpredicted results. but when i define the array in data memory and initialize the array as follows. can anyone help me? thanks

A[1] = 0x00;
A[2] = 0x3F;
.
A[6] = 0xAA

Parents
  • Note that

    unsigned char code A[]={0x00,0x3F,0x50,0x90,0x50,0x3F,0xAA};
    is not equivalent to
    A[1] = 0x00;
    A[2] = 0x3F;
    :
    A[6] = 0xAA;
    Your array indexes are out by one!

    If you are making the same mistake elsewhere in your code, you will get unexpected behaviour!
    (and you are probably trying to access the byte after the end of the array...!)

Reply
  • Note that

    unsigned char code A[]={0x00,0x3F,0x50,0x90,0x50,0x3F,0xAA};
    is not equivalent to
    A[1] = 0x00;
    A[2] = 0x3F;
    :
    A[6] = 0xAA;
    Your array indexes are out by one!

    If you are making the same mistake elsewhere in your code, you will get unexpected behaviour!
    (and you are probably trying to access the byte after the end of the array...!)

Children