PIC18F Rotary Encoder Code Help XC8
Your code looks complex.

If the encoder frequency is not too high it's just a matter of keeping track of the count using an up-down counter and two general purpose input pins.







simulate this circuit &ndash; Schematic created using CircuitLab

Figure 1. 2-bit rotary encoder waveforms.

The program logic is very simple. 


Track the current state of 'A'. If the state changes to 'high' then:
Look at input 'B'. If 'B' is low then count up. If 'B' is high then count down.
Update the 'lastState' of 'A'.


Pseudo code

void loop(){
  if(A &amp;&amp; not prevA){
    if(B){
      cnt--;
    } else {
      cnt++;
    }
  } else {
  prevA = A;
}


You'll probably need to debounce the inputs to prevent spurious triggering.