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

Using Constant in code bank array

Hi,
I am trying to locate a constant array in a code segment as follows.

In BL51 MISC option

"BANK0 (?CO?A)" is given.

In 'a.c'
char code a[5] = {1,2,3,4,5};

in 'main.c'
extern char code a[5];

When I try to see the values in the array 'a' in main.c I could able to see the values correctly in Watch Window. But when I try to assign that value to a variable its not getting assigned.

eg:
char b = 0;

b = a[1];

after this statement 'b' still remains as 0.
But if I put a[1] in watch window its showing me the correct value.

Why its happening? Can anybody help me out.

  • When you are place explicit constants into code banks, you have to use the switchbank function. Did you do this?

    I really recommend that you are using the far memory type for constant banking. Take a look to Keil\C51\Examples\FarMemory\1MB Constants on Classic 8051.

    Reinhard

  • Hi Reinhard Keil,
    My linker setup is like this.

    I am having 8 banks (mode 4 in L51_bank.a51), which I have configured correctly and I am sure its correct since its working fine with the board itself.

    I am having lots of contant array in one bank say Bank0. By default it goes and sits in common area, as far now its ok but now that the size of constant array is increased so bank area overflow occurs. To avoid that I placed those constant in a particular bank, by putting "Bank0 (?CO?<filename>)" in BL51 Misc-> Misc Controls,When I do it the overflow stops but the value is not correctly retrieved.

    In your reply U have mentioned to do bankswitching whether I have to take explicitly or it will take care by itself if I give the correct linker options.

    Kindly help me out.