Greeting!!!
The problem i am facing is something many product designers would have faced and solved. So any one can help me look at it in a better would would help me come up with a understandable solution. Please I am not looking for anyone to give out codes and spoon feed ...its boring then.
I am making a device that has a micro controller(could be any one) this device is going to run a code for the function I implement.
Also this device has a power button like most commercial devices have. When I press the power button if the device is ON(functioning)
it turn itself off(or goes to sleep mode). and If off(in sleep mode) it turn itself on.
Ideally this could be done easily using interrupt where we have a flag that toggles state and this flag is check to call the sleep instruction.
the c code for this could be like
ISR routine:
Code:
{
if (system_status_flag == 'ON')
{
system_status_flag = 'OFF';
sleep_routine();
}
else
{
system_status_flag = 'ON'
}
} // end of ISR routine
main routine:
Code:
void main(){
do_initialization();
while(1)
{
do_processing();
.
.
.
}
}
//end main functionality
The problem comes when I want to reset my system on power on(or waking up from sleep) so that the SP(stack pointer), PC(program counter) Status_flag and other critical register take the default value and program execution begins from the beginning or atleast to the
user it appears to be doing so.
It like when you press your TV remote button to turn TV off it goes to stand by and pressing power button puts the
TV back in action as if it has just started.
there is an option of using GOTO and making the program jump to the first line but as far as I understand GOTO jumps have
a scope of jumping to some line in very function where GOTO is present and cant make your program jump to main from ISR routine
also if it was possible would jumping from ISR to first line on main would the SP and other registers will not refresh to have the default values!!!!
I hope I have put the problem in simplest possible words with code example to help it.