#include "mc8051fun.h" static uint8_t lastb=0xff; static uint8_t hist=0x00; int8_t rotary_encoder_stat(uint8_t b) { if (b==0x00) return 0; if (b==lastb) return 0; lastb=b; hist = (hist << 2) | b; switch (hist){ case 0b11011011: return 1; case 0b11100111: return -1; default: return 0; } }