I don't understand why my routine doesn't work. The left and right buttons (S1 and S3 in schematic) always function normally, but sometimes S2 (center) functions normally, and sometimes it functions as button S1. In the circuit, all resistors are 10K, all diodes are actually 1N914, and all capacitors are 2.2uF tantalum. I have attached source code to the function that is problematic. I'm not sure what strategy to use to rectify my problem, but I'm trying to eliminate the debouncing effects via software and capacitors in parallel with the buttons and if possible, I want to avoid redoing my circuit.
Any ideas what I can do to my code or whether I should add/remove parts to my circuit without changing PCB layout?
Also, the middle button is equivalent to the left and the right button pressed simultaneously.