Why do my variables in the MPLAB IDE Watch view have the wrong value?
See also the FAQ “Why do floating-point variables in MPLAB IDE have the wrong value?” If this is not applicable the reason may be that the compiler has cached the variable into a register and MPLAB IDE is reading the variable’s original memory location. The compiler can reduce the code size required to access a variable by storing it in a register. This cannot always be done, but it can have significant benefits. To make matters worse, the register chosen may be different at different points in the code. Unfortunately for those compiler/debugger combinations that still use COFF for debugging (all compilers except PIC32) will have this problem as COFF does not support the ability to track variables in more than one location. This does not affect the operation of the code and often you will see the Watch view indicate a wrong result, but the program operate correctly.