Hi, I have two memory (Flash & NVRAM). I need to access both memories. I am writing program in C. If I want to store some variables in NVRAM and some in Flash how do I do it? Is there any mechanism (like code if U give it will directly go to code memory) so that I will define NVRAM as my first address of the NVRAM then after that if I declare some variables under NVRAM (like code or Xdata) it will work?
I presume both are being mapped into the 8051's XDATA address space? This is a job for the Linker. Keep the definitions of your Flash & NVRAM variables is separate files, and use Linker directives to locate them in the appropriate address ranges. You will, of course, need to study the Linker Manual - probably also worth browsing through the Application Notes, and searching the knowledgebase. NB: you don't need to have all your Flash variables defined in a single file, nor all your NVARM variables in a single file - you just jave to ensure that no file contains both Flash and NVRAM variable definitions.
The two memories would occupy different address ranges in the xdata memory space. You would not use two extra keywords. The _at_ keyword might come in handy for you. It allows you to place individual variables at particular memory addresses. When declaring large amounts of data, it is probably easier to keep the variable in separate files, and use the linker controls to locate the entire segment into flash or NVRAM as Andrew describes.
Can U eloborate it. It will be useful for me
Can you not type as though you are on a mobile phone? Seriously - how much time do you save by typing "U" instead of "you"?
"Seriously - how much time do you save by typing "U" instead of "you"?" It's a capital 'U' as well. That's quite a sophisticated bit of hand/brain coordination.
Sorry for my mistake. Kindly excuse.
hi; you write this for example: unsigned char xdata messaage _as_ 0x012e every time you use message you can write or read it. ofcouse you must design with nvram. address bus link to 74ls573 latch and data bus to nvram data bus
unsigned char xdata messaage _at_ 0x012e;
"That's all very well for just one or two variables, but impractical otherwise. You would have to manually calculate the address of each variable, and explicitly assign its address in the definition in your source code." I suppose you could group all the variables in a struct and locate that with a single _at_? It might even be a nice way of doing it if they are related. "Fortunately, there is a tool available to do this all automatically - it is called the Linker!" Indeed, but the thing (well, one of the things) I like about the _at_ keyword is that you can see exactly what is going on while you're working on the source rather than having to remember what is specified on a tab in the project options. Another possibility I can't remember having tried is to select the 'Keep variables in order' checkbox for the source file, then declare the first variable with the _at_ keyword.
I have two memory (Flash & NVRAM). I need to access both memories. If you have to access both all the time I have no suggestion except address decoding, but that will either force you to banking or limit you to 64k total. In my case I access SRAM "all the time" and need extremely fast operation at such time. Then, oh say once an hour, I need to read a bit from flash to SRAM and have "plenty of time". In this scenario, I have all "standard C" variables ( x = y;) be in SRAM and variables in flash only accessible by functions U8 ReadFlashByte(U32 adderess) and WriteFlashByte(U32 adderess, U8 data). Erik