Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to arrange program to save RAM & ROM space

Status
Not open for further replies.

Mithun_K_Das

Advanced Member level 3
Joined
Apr 24, 2010
Messages
899
Helped
24
Reputation
48
Reaction score
26
Trophy points
1,318
Location
Dhaka, Bangladesh, Bangladesh
Activity points
8,252
How can I save some RAM & ROM arranging the LCD program. Say, I've two texts to show in LCD Display (16X2).

Code C - [expand]
1
2
Text1: "Battery Parameter";
Text2: "System Information";



Say these two texts consuming 100bit RAM & 100bit ROM.

How can I arrange these texts in MicroC so that it consumes less than 70bit RAM & 70 bit ROM?
 
Last edited:

You can save 10 bytes by dividing your messages in 3 strings:

Text1: "Battery"
Text2: "System"
Text3: "Parameter"

As "Parameter is a common for both :)

It's funny that your strings are at the same tome consuming RAM and ROM. They should occupy only ROM space.
 

Each string above uses 20 characters, including '/n' terminator.
Therefore, both 2 texts should theoretically consume 40 bytes.

However, you are probably using some 16-bits core processor which natively performs memory access to entire magnitude of the address, what implies 2 text above would consume somewhat as ~80 bytes.

You must ensure that size optimization of compiler is properly configured so that 8-bit data can be stored inline.



+++
 

Search the MikroE forum to find work-around solutions.

e.g. https://www.mikroe.com/forum/viewtopic.php?f=88&t=47629&p=191372&hilit=saving+ram#p191372

Strings are held in RAM by default, and since RAM contents are lost at power-off, also have to be held in ROM.

Store strings directly in ROM (as long as the string will not change during run time) to save RAM space. Use the "const" qualifier.

You then need write (or find) simple functions to copy from ROM to destination, as in the example in the link.
 

You have 37 characters if I include one character to end the two strings. Now, some special rules. Only use lower case letters and shift to upper case at the beginning of a string or after a "space". Use 5 bits to represent each character ("a" to "z", space and end-of-string). Pack the special characters as one long series of 5 bit values in memory. So, it seems 37x5 or 185 bits is near a minimum. Again, you need some special rules and decoding to really reduce the required memory to an absolute minimum. Very weird but possible. However, I don't see getting to 70 bits. Do you mean bytes instead of bits?
 

Actually the problem I've been having with microC compiler is, when I write the program with LCD, I barely can use 5/6 texts and it shows not enough RAM or it may show not enough ROM. But one of my friend uses other compiler, BASCOM. He can add more than 10/12 texts as the size I used in my case. Non only this, he uses the same pattern as I used for the texts. Also after the program written, some RAM or ROM are still free in BASCOM. Same Program, Same MCU, Same Texts, only difference is in the compiler. Then how its possible?

I really don't understand how its possible.
 

You face that problem if you use PIC16F due to bank switching problem. It is better to use PIC18F. If you have to use PIC16F then CopyConst2Ram() function solves the problem. I have always used CopyConst2Ram() in programs for PIC16F and I never had problems.
 

@milan.rajik:
You must be using a microcontroller with a lot of RAM if you are copying ROM contents to RAM. That's pure waste of RAM space.
In any case, strings are held in ROM, not in RAM if declared as constants.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top