> a) Well, there's a diode across the relay if that's what you mean That will protect individual components, such as the driver transistor, from the back-EMF when the relay turns off, but doesn't prevent a spike getting on to Vdd and MCLR or other pins/components. A relay is a "dirty" component which should have either a well-buffered (at least the PIC's supply should be) or its own supply. It would pay to look at it just to see if there is any undesirable noise in the circuit even if you find the ultimate cause to be somewhere else > b) Even if the read-modify-write problem would occur, I don't > think it's the reason of the bug. The PIC just executes code that it > shouldn't be able to execute (you know, like an if condition that > test as false, but is executed anyway). I'm sure I'm missing something > very obvious, but I can't seem to see it Consider this - hour many hours do you think I wasted here because "it just simply couldn't be the code" ? http://www.piclist.com/techref/scenix/sxrmw.htm and http://www.piclist.com/techref/readmodwrite.htm Obviously you've spent more time on your code than I have and I don't intend this as a suck-eggs or condescending reply but .... look at it this way. The PIC is doing what you're telling it to do or the circuit is behaving the way you've set it up to. I just know that if you break it down logically and methodically, the veil will lift as if by magic. My apologies for not providing you with a specific answer, really -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist