Flemming Steffensen wrote: "Any idear what
might be at play here?"
Sure. The "bug" is that you have your main
thread of execution and an interrupt sharing a variable with no access
synchronization whatsoever. If you just want to fix it, turn off
interrupts while you're testing the value of RotCount. If you want to
understand it, you'll have to do what you haven't bothered to do yet, which is
to look at the assembly output. You'll find that the comparison is done in
two steps, one for the high byte and one for the low byte. Consider what
happens when the interrupt fires in between these two steps and the first part
of the comparison is done with the value before the increment and the
second part is done after the increment.