I want to design a circuit such that the microcontroller can toggle a GPIO pin and shut the whole system (including microcontroller itself) down. And when the user presses a momentary button, the power is brought back up again.
Is this possible?
This example uses a Maxim MAX1835 step-up regulator, but could be applied to others as well that have a shutdown pin.
The circuit is normally powered down. When the user presses the pushbutton, the battery is fed into the -SHDN pin, enabling the regulator and turning on the 3.3V to the microcontroller. The microcontroller then puts a logic 1 on the POWER ON lead, holding the power on after the user releases the pushbutton. When the microcontroller wants to shut itself off, it sets the POWER ON lead to 0.
One way of doing this is to enter a deep sleep mode on the microcontroller.
Many microcontrollers support being woken up by an external interrupt, such as an edge on an IO pin.
Yes, this is certainly possible, but how you achieve this depends on what kind of load you're going to be switching on and off.
It's probably as simple as just using a relay connected to the output PIN of the microcontroller (via a transistor and protection diode), and a push button switch connected to a pin configured as an input.
Here is a simple example circuit diagram:
When using a momentary push button switch, be careful of debounce though, you'll need to implement a delay in your microcontroller code to ensure that you check the status of the push button over a period of time (e.g. 1ms) before switching your relay back on. If you don't, then the microcontroller might pick up multiple signals and switch your relay several times in a very short space of time, and you'll find that your button works intermittently.
UPDATE I just saw your edit about powering the microcontroller down as well. Can you give some more information about what your actually trying to do? It's difficult to answer your question without understanding the whole system.
If you want to shut the microcontroller down as well, then you'd need some way of getting power back to the microcontroller. Maybe you could use the relay to power everything including the microcontroller, that way the microcontroller can switch itself off, but not back on. Then your push button could be connected across your relay switch, to effectively short it out giving it enough time to power up and hold the relay open itself.