I'm currently attempting to devleop a bootloader/debugger utility for the PIC16F877A. In the process though, I've found that I seem to be using up a lot of RAM (my code uses up about 25% of the total available ROM space). I always get "Not enough RAM for all variables" errors when I compile. I know I am not using even 100 bytes of memory at once with all my local variables and can verify this by drawing out my call tree.
A peek into the symbol file shows that some of my functions are asking for too much scratch space (although it doesn't show how local variables are being allocated, possibly because it complains of not enough RAM). I've managed to cut this list down to only a few functions using the following techniques:
Using putc() instead of printf() for short strings
Splitting up math functions onto several lines. Such as:
var1 = var2+(var3 & var4);
into
var1= var3 & var4;
var1+= var2;
Eliminating unnecessary local variables and sizing arrays to absolute minimum values.
Would using pointers for variables larger than 8-bits help to reduce memory usage?
These functions don't call on other functions save to convert an ASCII string to an integer or to perform some operations on system registers which don't require any local variables. Would implementing code inline and avoiding a function call help if no local variables are needed in said function call?
I'm also not really sure how I can reduce a switch statment I use to decide what to do based on user menu choices.
I'm wondering if anyone else has any memory saving hints or tips and/or answers to my questions.
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
Posted: Tue Mar 14, 2006 11:45 pm
Quote:
I always get "Not enough RAM for all variables" errors when I compile.
I know I am not using even 100 bytes of memory at once with all my
local variables and can verify this by drawing out my call tree.
Have you enabled the use of all RAM ? To do so, add the line
shown below.
Code:
#include <16F877A.H>
#device *=16 <-- Add this line to enable all RAM
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