Search This Blog

Tuesday, January 3, 2012

The data space.

In 8051 there are 3 spaces in which one can store data.

1)      The 128 bytes of RAM space with address 00 to 7Fh. We can read and write directly or indirectly into this space using R0 and R1 registers.
2)      The 64k bytes of code space or generally called program space with address 0000 – FFFFh. This 64k of memory is used for storing opcodes and is directly under control of program counter (PC) register. We can use MOVC command to refer it. There are 2 major problems with this usage. First being that since its ROM it can be burned only by predefined data. And we are unable to write during execution. Second problem is that more code space we use for lookup table less the space we have for our program code. For this purpose for storing lookup tables we use external memory.
3)      The 64k bytes of external memory which can be used both for RAM and ROM purpose. We access it using MOVX instruction. So this gave us a 64k on chip ROM plus a 64k off chip ROM. Increasing memory to 128k.

So how to differentiate this in c??
For that lets see an excerpt for examples.
Unsigned char xyz[] = ‘abcdefghijk’;
Unsigned char I;
Both variable xyz and I uses RAM space for storage. So imagine RAM space used when we write this..
Unsigned char xyz[100];
Int array[21];
As you must have already counted that the char xyz[100] uses 100 bytes of RAM space whereas the int array[21] uses 42 bytes of RAM space overloading our existing RAM space. So in cases like these we need to use code space.

To make C complier use code space instead of RAM space we need to use keyword code in front of the variable declaration.
code unsigned char xyz[] = “abcdef”;
code int array[12];
The keyword code helps complier recongnize where to store the data in RAM or in ROM.

No comments:

Post a Comment