Momentary switch power: press to turn on, microcontroller can turn itself off
Here is a possible solution for you:







simulate this circuit &ndash; Schematic created using CircuitLab

The pin A0 from the microcontroller is a pin capable of both digital output and analog input. This pin is configured as input during start.

This circuit is wired so that the gate voltage of M1 (aka analog input A0 of the microcontroller) maps to this:


\$0\mathrm{V}\$: circuit is turned off, or turning this entire circuit off.
\$\frac{1}{2}V_{cc}\$: circuit is running, button not pressed.
\$V_{cc}\$: Button is pressed.


Power on: The button SW1 is pressed down and +5V is present at the gate of M2, pushing M2 on and in turn push M1 on, turning this entire circuitry on. Microcontroller start and wait until the voltage of pin A0 drop to \$\frac{1}{2}V_{cc}\$ and start the program.

Power off: When pin A0 is pulled to +5V for several seconds and released, switch pin A0 into digital output and output a logic 0, turning M2 off and in turn cutting off M1, turning this circuit off.