Hello all, just dabbling with a bit of debounce code. Following along in the book "PIC MCU Programming" by Bert van Dam. I would highly recommend it for anyone who is feeling challenged by the disconnect between programming and the hardware interface of PIC's - this book seemed to break it down relatively well. Common gripe of most of these books remains with this one of having to get the specific chip being used in the book for maximum effectiveness - luckily there was a choice of three chips that were similar enough, so I found one that was reasonably priced and easy enough to source. Enough soapbox.
My current issue is understanding this bit of code I wrote to solve one of the questions in the book. The goal was to turn on a LED after pressing a momentary switch and on the third press, to turn it off. Essentially ignoring one button press (the second press). The code is JAL (just another language). I wrote the following code, it compiled with no errors, but does not produce the desired result. My first guess is that it is happening too fast to catch, but it is inside a forever loop so I then thought to include the debounce statement for each test of the switch. Still not working as expecting - any hints?


My current issue is understanding this bit of code I wrote to solve one of the questions in the book. The goal was to turn on a LED after pressing a momentary switch and on the third press, to turn it off. Essentially ignoring one button press (the second press). The code is JAL (just another language). I wrote the following code, it compiled with no errors, but does not produce the desired result. My first guess is that it is happening too fast to catch, but it is inside a forever loop so I then thought to include the debounce statement for each test of the switch. Still not working as expecting - any hints?


