how to detect power failure and make micro-controller save data in EEPROM
This is the principle diagram you need. Values for R1 and R2 depends on the power supply voltage and the maximum input voltage of your CPU pins.
The value of C1 depends on how much current your circuit is using and how long you need to keep the power up and to what level. Adding a regulator after that cap can greatly improve your time allowing you to use smaller capacitors.
To calculate the value of C (Your obvious next question) we need all the data Tony Steward is asking for. 







simulate this circuit &ndash; Schematic created using CircuitLab