|
|
View previous topic :: View next topic |
Author |
Message |
aquiles Guest
|
Not enough RAM for all Variables error messageon PIC16F877A |
Posted: Fri Oct 07, 2005 2:28 pm |
|
|
Hello All,
I am new in MCU programming. I just developed a few small projects using PIC MCUs and CCS compiler.
I am trying to compile a program for a 16F877A that has a simple main( ) function a some array variables declared:
If I declare just this variable:
int8 aBuffer[ 128 ];
it does not compile. I think is because some page limitation, it is correct? or what is the reason related to this error?
If I declare as
int8 aBuffer[80] ; // it compiles
it now compiles. But, declaring several variables:
int8 bBuffer[ 80 ];
int8 aBuffer[ 60 ];
int8 cBuffer[ 10 ];
BYTE a1;
BYTE a2;
BYTE a3;
BYTE a4;
BYTE a5;
BYTE a6;
BYTE a7;
BYTE a8;
BYTE a9;
BYTE b1;
BYTE b2;
BYTE b3;
it compiles if I remove variable b3 otherwise it give me a memory error.
The PIC data sheet shows that 16F877A has 368 bytes of RAM, so whay I am getting a "Not Enough RAM memory for variables"? The statics for the compiler (removing b3 variable) are:
ROM used: 180 (2%)
180 (2%) including unused fragments
0 Average locations per line
13 Average locations per statement
RAM used: 175 (100%) at main() level
175 (100%) worst case
Any idea how I can skip this problem?
Kind regards. |
|
|
Ttelmah Guest
|
|
Posted: Fri Oct 07, 2005 2:41 pm |
|
|
This has been answered so many times it is getting silly.
There are two 'parts' to the answers. The first is that on the 16 family chips, to use RAM outside the first bank, you need the option:
#device *=16
near the top of the program, to allow the memory outside the first bank to be used. Without this, the compiler generates smaller code (without any bank switching), but can only use the RAM present in page0 (96 bytes for your chip).
The second part os linked to this. An array, has to be assignable as one continuous 'lump' of memory. Unfortunately the RAM in these PICs, is laid out in pages, and so though there is 268bytes in total, the maximum array size is limited to the largest amount available in one bank. On the 877, this is 96bytes. (actually 112 bytes are available in the latter banks, but the top 16 addresses of this, and duplicated into the bottom bank, stopping these addresses being used in the upper bank, if they are used in the lower one).
A scan of the archives will find _dozens_ of explanations of this.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|