You probably want a power supervisor there, that will detect the falling power supply voltage, and generate an interrupt for the micro to tell it the power is on it's way out. As a bonus many also include, almost for free, a precision brownout detector, and as well a reset generator with a well defined trip level, and also often a watchdog system that can restart the microcontroller if it stops giving the watchdog reset for a while. Some also include a battery backup section that drives an external RAM and both provides power to it from an external cell, either primary or secondary, along with the right control signals to minimise RAM standby current.