A simple clear is to jump to the beginning of the program if pin 5 = xxx
with very little work , you do what you want for clearing registers ...

Now, If your program fails, then it's a programming problem ... not a hardware problem.

Remenber chips never do errors ...

Alain