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.

Disclaimer: Electricity is always dangerous. Proper skill is required to work with electricity. Do work at your own risk. The author will not be responsible for any misuse or harmful act or any mistake you make. The contents of this website are unique and copyright protected. Kindly don’t do any nonsensical act copying and claiming it as yours. Most of the articles published here are kept open-source to help you. Take the knowledge for free and use it, but if you are interested you can buy the ready resources offered here. If you need any help or guide feel free to comment below, the author will try to help you. Also, there can be affiliation links in the article. Which will not affect you anyway, but helps the author with some commission. So please don’t take it otherwise. Thanks.

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.


Also let me know what you want to get as the next article, comment below!


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.

1 Comment

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

Excellent Article!
Many Thanks!

Leave a Reply

Avatar placeholder

Your email address will not be published.