0

My program has several images, I want to do something like a menu with LCD and a keypad. It was working fine untill the moment that I got two erros:

> Recursion or cross-calling of 'lcd_write'
> Not enough RAM for call stack

I read something about a stack overflow. How can I solve this problem?

I´m using PIC16F877a and mikroC for PIC v6 Compiler.

mafap
  • 371
  • 3
  • 18
  • 40

2 Answers2

0

The method to solve this problem is - go back to the last compilable version, see what changes you have introduced that result in another call to lcd_write, restructure your program so that eliminate that call because it results in recursion. An example would be putting the lcd write data into a buffer instead of writing it immediately, and writing it later when you find something in the buffer.

Recursion is bad in an embedded environment because it uses the call stack by an unknown-at-compile-time amount, and small micros such as the PIC often have hardware call stacks of 8 (eg PIC16F877a) or even as small as 2 levels.

Embedded Gurus has a good explanation of problems with call stacks.

Martin
  • 2,442
  • 14
  • 15
  • I read it before and in the end I just got this "If you are still stuck after trying all these, then you really are in a pickle." lol I just introduced a if/else statment and the erros started. Like lcd_write I have this error in all my functions – mafap Jun 04 '13 at 16:14
0

Go to the last compilable version, compile it succesfully, then go to the view Tab, then "Statistics"

In this menu you can see the call function tree and see where the stack is at it's limit. Got the same problem with the same controller and re-structured my I2C LCD functions so that they don't call a function in another called function.

If you really can't optimize your code, consider upgrading to a PIC18.

Jean-francois
  • 316
  • 1
  • 9