Have an input pin tied to the power source before the cap;

When the power is OFF, you can detect it while the cap is still powering the PIC.

This way, you can save your variables before the cap is completely gone.


------------------------------