Dang it, NSA ... I knew about the shadow registers, but I had somehow forgotten that PCLATH is among them and that it's also saved automatically when an interrupt is triggered. Anyway, after re-reading that tiny detail in the datasheet, I realized I didn't have to back up and restore the value of PCLATH. All I had to do is clear it as soon as the interrupt routine was entered. And that kept the problem as solved and also made the code simpler and faster. Thanks for your previous post.
Anyway, here goes a very deliberate rant from my part:
Do not ever, never ever ever freaking NEVER! use the "bsf PORTC, RCx" instruction!!!! (or its equivalent "bcf" counterpart) ... I somehow thought that it would be easier if I were to just use PORTC instead of LATC for changing pin outputs ... Big mistake. A very strange bug that took me hours to trace was caused because of that.
From the datasheet:
Reading the PORTC register reads the status of the pins, whereas writing to it will write to the PORT latch. All write operations are read-modify-write operations. Therefore, a write to a port implies that the port pins are read, this value is modified and then written to the PORT data latch (LATC)
What was happening when I used said instruction (instead of the plain "bsf LATC, RCx") is that all of the pins in the port were somehow affected. It's like they all "blinked" when that instruction was executed, and it was wreaking havoc with my circuit and the rest of the logic.
I thought it was easier and simpler to always use PORTC for reading and writing to the pins so that things would be kept uniform and easier to read ... I was wrong...
Anyway, here goes a very deliberate rant from my part:
Do not ever, never ever ever freaking NEVER! use the "bsf PORTC, RCx" instruction!!!! (or its equivalent "bcf" counterpart) ... I somehow thought that it would be easier if I were to just use PORTC instead of LATC for changing pin outputs ... Big mistake. A very strange bug that took me hours to trace was caused because of that.
From the datasheet:
Reading the PORTC register reads the status of the pins, whereas writing to it will write to the PORT latch. All write operations are read-modify-write operations. Therefore, a write to a port implies that the port pins are read, this value is modified and then written to the PORT data latch (LATC)
What was happening when I used said instruction (instead of the plain "bsf LATC, RCx") is that all of the pins in the port were somehow affected. It's like they all "blinked" when that instruction was executed, and it was wreaking havoc with my circuit and the rest of the logic.
I thought it was easier and simpler to always use PORTC for reading and writing to the pins so that things would be kept uniform and easier to read ... I was wrong...
