that big honkin 470uf cap is probably the culprit ... depending on how much power your PIC circuit draws, it could continue to power the chip for several seconds after you turn the AC off.
better place for the switch would be after the 5v regulator.
i recommend something in the range of 1-10uf on the output of the regulator, in addition to the 0.1uf you have already.
Also, putting a diode in reverse bias from Vout to Vin on the reg will ensure the Reg is not damage because of capacitive loads on the circuit when swithing on and off
Also, a 0.1uF Tantalum capacitor will help smooth out any transients (it really helps out for timing sensitive applications). It's best place as close as possible to the PIC's Vss and Vdd
As noted by justDIY, it is probably due to the low current draw of the PIC not discharging the 470uF cap. You could put a 1K resistor across the 470uF cap to properly discharge it on power off.
Thanks gramo for your diagram and for the useful information.
After making a complete PIC product with the 5V power supply (included transformer) where to place the ON/OFF switch.
If I place near the regulator, after switch OFF, the transformer is working all the time.
If I place the switch in the transformer side I cannot reset the PIC smoothly it takes long time to reset.
(If the user switches OFF from the AC outlet it will be a big problem because the PIC won’t reset)
As noted by justDIY, it is probably due to the low current draw of the PIC not discharging the 470uF cap. You could put a 1K resistor across the 470uF cap to properly discharge it on power off.
Use an LED as a power on indicator and that will drain the capacitor (you want it to draw about 20mA). Also, turn on Brown Out Reset (in config) on your pic chip, this will ensure that the chip will reset when the supply voltage drops below 4V.
Oh, the reset that I said is not the reset that you meant
If your circuit doesn't draw much current, can you use smaller value of the filter capacitor? Also, turn on the brown off reset.
The typical power up timer period of PIC16F877A is 72 ms, 132 ms msx. Can the time be set? What happen if the power supply system takes more than 132 ms to achieve 4 V? As I know, some boost regulator takes some time to be boosted up (but not 132 ms long).
This could be easily solved by using a DPST switch with sufficient voltage issolation to switch both the mains HOT wire and the 7805's positive output at the same time. If you're paranoid about passing both mains and regulated voltage through the same switch you can always use two seperate SPST switches physically ganged together.