This is a very common error to them who works with microcontrollers. In this article, I’ll show you ways to solve this Not Enough ROM/RAM error. The high-level MCUs are capable of handling the memory mapping properly. But the lower level MCUs are not especially PIC10F,12F,16F series. But we need to use these low-level MCUs in various products to keep the price minimum. That is why we frequently face this error. Here is the solution you can try.


Electricity poses inherent risks. Adequate skills are crucial for handling it safely. Undertake tasks at your own risk; the author disclaims responsibility for misuse, harm, or errors. Website content is unique and copyrighted; refrain from unauthorized copying. Most articles are open-source for your benefit. Feel free to use the knowledge freely, and consider purchasing available resources. For assistance or guidance, comment below; the author aims to help. Some articles may contain affiliate links, having no impact on you but supporting the author with a commission. Thank you for your understanding.


Table of Contents

What is the RAM & ROM of microcontrollers?

No, I’ll not describe it here, you can read it from this link. But you should know that there are RAM and ROM in each microcontroller. ROM is used to store the program you wrote (the machine file although) and RAM is used to store the variables and data. Now, that is another section to learn but let’s go to the point.

Reason for Not Enough ROM error!:

There are several reasons for this. Also, there are solutions to them. Sometimes, little precaution will help reduce your time consumption for a project. Otherwise, it may take hours, days, weeks even months to find the problem and solve it. I’m working with microcontrollers since 2008, but still, I face this problem. But it takes less time than it took before. Anyway, let’s find the reason and ways to solve that.

1. Using too much ASCII values:

What are the ASCII values? It’s what you are reading right now. I mean the texts. While using LCDs or similar displays or writing codes for UARTs, we need to use ASCIIs. But as you know that the variables are stored in the RAM, so using so many ASCII values will consume lots of RAM as well as ROM.

Not Enough ROM/RAM error

Here in this code, we used the TEXT or ASCII values. This simple one-line code is consuming 15% of RAM and 14% of ROM. Now, let’s check what happens if we use more of this.

Not Enough ROM/RAM error

Only 9 of this consumed 93% RAM. If so, then what else you can do with this MCU? No more calculation can be used with this!!!

Not Enough ROM/RAM error

Done! There is no way to add more code here. But we never use a MCU only for this simple task. We need to do a lot of work with MCU like this one. So? How can we solve that?


Convert the ASCII into a constant value. And print each digit one by one. Let’s see!

Not Enough ROM/RAM error

Wow!!!, only 9% of RAM is consumed. And if we add more of this?

Not Enough ROM/RAM error

Same 9%, but the ROM consumption is increasing. That actually gives us enough scope to add more code and do more tasks with this microcontroller. But keep that in mind, we converted the ASCIIs into constants, so it will consume ROM because constants are stored in ROM. So you must utilize this feature carefully.

The code: This code is for LCD only and for the UART, there is another one in the end of this article.

void Lcd_COut(char row, char col, const char *cptr)
    char chr = 0;             //first, it is used as empty string
    Lcd_Out(row, col, &chr);  //nothing to write but set position.
    for ( ; chr = *cptr ; ++cptr ) Lcd_Chr_CP(chr); //out in loop

Don’t miss the following steps, you’ll find more resources that will surprise you.

2. Using wrong variable types:

We know there are several types of variables such as int, char, float, long, double, short, etc. When a microcontroller calculates among different variable types, it needs extra memories. Also, you need a value that can not exceed 255 but you declared that as long which is 32bit wide, then it must take extra RAM to calculate such a variable. Let’s see an example:

Not Enough ROM/RAM error
Here, we declared the result as long. But we know that the range will not exceed 2500 which is in the unsigned int range.

Now, if we change the type, then the result:

Not Enough ROM/RAM error

It took 2% less RAM. Now we go a little further. We know that the value of a is constant. Now, if we declare a as constant, then:

Not Enough ROM/RAM error

Wow!!!, it took only 3% RAM and 1% ROM. So? Did you find the tricks?

3. Using calculations in extended form:

We need to use lots of calculations in the code. But there are some limitations to this as well. Let’s check the examples:

Not Enough ROM/RAM error

Maybe we need to use a float to calculate with. But if you check carefully, it takes 18% while we are using this way. And if we write this way?

Not Enough ROM/RAM error

It takes only 4% keeping the result the same. Now, the choice is yours. Besides, the a can be declared as a constant. That will give you a dramatic result.

4. Using Extra code lines:

Sometimes, we write extra lines whether that could be written directly. Let’s check this example:

Not Enough ROM/RAM error

As you see, here we used another variable txt just to separate the digits of the first variable ‘value’. But we could write this way which results same but works efficiently.

Not Enough ROM/RAM error

So? Did you find the tricks? If not, practice both.

RAM to ROM copy for UART function:

Like the LCD_COut function, this can be used for UART write which will reduce RAM consumption dramatically.

void UART_Write_CText(const char *cptr)
    char chr;
    for ( ; chr = *cptr ; ++cptr ) UART1_Write(chr);

This article can be helpful for you too: How to remove noise/garbage from the HD44780 LCD display


There are lot more ways you can get the error we discussed in this article. But the most common ones we have already learned today. I’ll add more points to this article in the future while I face that individual problem. So don’t forget to come back and check this article again after a while.

If this article helps you a little, kindly share this with others so that they can come back from a coma situation looking for the solution to the error we learned to solve.

For Professional Designs or Help:



Mithun K. Das; B. Sc. in EEE from KUET; Head of R&D @ M's Lab Engineering Solution. "This is my personal blog. I post articles on different subjects related to electronics in the easiest way so that everything becomes easy for all, especially for beginners. If you have any questions, feel free to ask through the contact us page." Thanks.


RK Hamy · 04/12/2021 at 5:44 pm

Excellent Article!
Many Thanks!

M H N · 20/05/2023 at 12:23 am

This article helps me a lot. Thanks for sharing those trics.

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *