I have a question. How to know maximum stack of my program and stack overflow? beacause my program can lock when power have unstatable.
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.