unexpected resets
All good suggestions from kinjalgp. Is the reset line only used during power-up, or are there additional external trigger sources?
Unexpected pulses on the reset line, even those having very short durations, can reset the micro in the erratic way you mention. You should first try to determine whether the spikes are actually coming off the reset line or are being generated by power supply dips. Look at the positive supply with a scope, if you see the same type of short spikes that appear on the reset line, you have some larger power supply de-coupling issues to deal with.
If you determine the problem is on the reset line, either use #4 above, or try using a noise discriminator circuit (if there are additional external reset sources). The following circuit is from an old RCA CMOS manual. Input pulses having a duration greater than t1 produce an output pulse of duration t2, shorter input pulses are ignored. t1 = R1C1 and t2 = R2C2. The diodes speed up the recovery time of the circuit. Hope this helps. - CAL