What is the "switch connected to the copetition port" supposed to do? There are very specific pins that you're permitted to use without voiding your warranty.
If you're talking about putting the controller in autonomous mode, then it's likely that your autonomous routine is doing something to cause the code error. The typical reasons for that to happen are:
- an infinite loop in the program that keeps the software from getting to the put_data function.
- a faulty Interrupt Service Routine that fails to clear the source of the interrupt