I have a question. How to know maximum stack of my program and stack overflow? beacause my program can lock when power have unstatable.
Hi, The stack behaviour 8051 based core is little bit different from others. Here stack is used for: 1. Storing return address from function as well as ISR 2. Saving and Restoring Registers used in interrupt, if no register bank is defined for storing default register bank 3. Saving and restoring intermideate results All local and global variables as well as function arguments will be stored on seperate memory (RAM). Stack will be allocated from idata which is 255 byte long, so there is a very little chance to have overflow in stack. But one can find out manually the stack usage by filling idata with 0xFF and observe the max. usage. There is not way to detect overflow runtime. -SP
Thank you very much. I will try it. If I assume that stack pointer point to wrong address in unstable power, how to know stack pointer be right or wrong?
See also: http://www.keil.com/support/docs/192.htm
If I assume that stack pointer point to wrong address in unstable power, how to know stack pointer be right or wrong? That assumption is unfounded. If you have unstable power, a wandering stack pointer is the very least of your problems. Once the power becomes unstable (i.e. drops below the minimum allowed by the datasheet of your micro), anything can happen. You don't want to go there. You're asking the wrong question. You should be asking yourself how to stabilize your power source, or how to survive any remaining instability. Forget the stack pointer, learn about power watchdogs and proper reset generation instead.