//----------------------------------------------------
// read encoder
encoder = PORTB;
//----------------------------------------------------
// check for any change of X encoder pins
newX = (encoder & 0b11000000);
if(newX != lastX) // if changed
{
// now check direction (if newA != oldB)
if(newX.F7 != lastX.F6) x_value++;
else x_value--;
lastX = newX;
}
//----------------------------------------------------
// check for any change of Y encoder pins
newY = (encoder & 0b00110000);
if(newY != lastY) // if changed
{
// now check direction (if newA != oldB)
if(newY.F5 != lastY.F4) y_value++;
else y_value--;
lastY = newY;
}
//----------------------------------------------------