It is odd, this comes up here semi regularly, but I have used many, many pics in commercial products and don't think I have ever seen this behaviour.
Checklist:
- Decoupling (100n right at the power pin) plus some bulk cap somewhere on the board.
- Groundplane.
- IO not connected directly to the outside world (Always causes trouble), at least use some series resitance and clamp diodes, opto isolation is better).
- Relay drivers have catch diodes and sane track routing.
- Switching power nets do not run runder the pic.
- Power supply does not glitch when switching load (For example if the load has a huge input capacitor and shares the power with the pic....).
A lovely gotcha for newbies with some of the smaller pics is that they sometimes have 2 ground pins, this is not an invitation to use the pic as part of a ground net on a single sided board (Yes, I have really see that done)!
Regards, Dan.