0
\$\begingroup\$

I am trying to understand the use of external memory with an 8051. When you are using external memory with something like C8051F962 where you have to configure the ports to access the memory, how do you initialize that memory with data. For example, internal RAM you use DB statement to initialize the memory-

MYVAR:  DB  'SOMETEXT'

But I am assuming that will not work with external memory because from the documentation it sounds like you can only move data into it with MOVX. Also, your DB statement would have to come after the port initialization for the external memory.

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

Initialized data in RAM has to come from somewhere - typically from ROM or from disk, or whatever place the program code is coming from.

In a programming environment complex enough to have canned "startup code" typically initialized data designated for RAM will actually be packaged by the linker into flash (or on a larger system, the disk image or structured binary, eg ELF, PE, whatever) along with some collective start/end metadata, and the startup code will do a block copy of this from that initial location to the needed location in RAM.

In your case, you have to do some initial pre-configuration to even be able to use the RAM at all.

That probably means there are two possibilities:

  1. Put the data in flash, then have your own routine which copies it to RAM after performing the necessary configuration to make RAM work

  2. Possibly your toolchain is aware enough of your expanded system configuration that there's already a canned mechanism for doing that

In reality though there's a third choice, too:

  1. Don't use initialized storage in RAM - use constants for things that have initial values (which will probably end up constructed from the most efficient representation) and then use RAM only for values generated an runtime.
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.