I am attempting to design a temporary backup for a PIC MCU using a supercapacitor. The goal is that the MCU can detect when power is lost, perform its cleanup tasks, and then shutdown completely by disconnecting from the supercapacitor. I have never worked with supercapacitors or MOSETS (as I've never had a need) but I came up with this initial design. I am sure there are many problems with it and I am hoping I can get some feedback and guidance on what I am missing/need to change. This is the circuit.

My thought process was:
1. When the MCU turns on, it enables Q1 and Q2 via RD0 and RC0, respectively. Q2 is acting as a sensor for the main power via the emitter into RC1. When this drops (which the MCU will detect via a falling edge interrupt) it will know main power is lost and start shutting down. Q1 is also enabled so that the supercapacitor is also connected.
2. After the shutdown is completed, it will turn off Q1 by bring RD0 low, thereby disconnecting the supercapacitor from the circuit.
3. D1 is to prevent the supercapacitor from feeding back into the LM7805
4. D2 is to prevent the LM7805 from feedback backwards into the MOSEFT
5. C3 & C4 are the recommended decoupling capacitors from the datasheet
6. R1 is to limit the current into RC1 to 20mA
7. D3 is to ensure that Q2 is only detecting power from the LM7805 and not from the supercapacitor
As I said, I am sure there are multiple problems here so any help/guidance is greatly appreciated. TIA.

My thought process was:
1. When the MCU turns on, it enables Q1 and Q2 via RD0 and RC0, respectively. Q2 is acting as a sensor for the main power via the emitter into RC1. When this drops (which the MCU will detect via a falling edge interrupt) it will know main power is lost and start shutting down. Q1 is also enabled so that the supercapacitor is also connected.
2. After the shutdown is completed, it will turn off Q1 by bring RD0 low, thereby disconnecting the supercapacitor from the circuit.
3. D1 is to prevent the supercapacitor from feeding back into the LM7805
4. D2 is to prevent the LM7805 from feedback backwards into the MOSEFT
5. C3 & C4 are the recommended decoupling capacitors from the datasheet
6. R1 is to limit the current into RC1 to 20mA
7. D3 is to ensure that Q2 is only detecting power from the LM7805 and not from the supercapacitor
As I said, I am sure there are multiple problems here so any help/guidance is greatly appreciated. TIA.


