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

how to access pointer array located in BANKn?

Emergency
how to access pointer array located in BANKn?

//Located at BANK0
code char *pStrArray[] = {
   "1",
   "2",
   "34",
};				

//Located at BANK0
void LoadString(char *strbuf, const char *pString){
   BYTE iBank;

   iBank = get_bank();
   switchbank(RES_BANK);
   strcpy(strbuf, pString);

   switchbank(iBank);
}

//Located at BANK1
void GetString(char *strbuf, const char *pStr[], unsiged char i){
   LoadString(strbuf, pStr[i]);
}

//the result is null string, why?

  • if your constant string is located in a bank using a linker directive,
    When you pass a pointer to another function located in another bank you get something with no sense ( the string is not visible )...

    The solution is to make a function in the same bank of the strings witch copy the string in a buffer in ram: the buffer will be visible in all bank of code !
    i use this solution...

    Another solution is to use far memory support from keil witch manage this problem... but you need to use LX51 and fill in assembly the file l51_bank.a51 to configure the access to different objects(function ?C?CLDXPTR, ?C?CSTXPTR, ?C?ILDXPTR, ?C?ISTXPTR, ?C?PLDXPTR, ?C?PSTXPTR, ?C?LLDXPTR, ?C?LSTXPTR )

    regards
    christophe grun

  • Take a look to the examples provided under
    \Keil\C51\EXAMPLES\FarMemory.

    The folder 1MB Constants on Classic 8051 contains an useful starting point. It should be noted that you need PK51 and the extended linker LX51 to use this example programs.