In my experience accidentally leaving the _MCLR pin floating causes erratic behaviour such as yours. Make sure it is tied to +5V to prevent the PIC from randomly resetting.
aja
- 298
- 2
- 5