diff --git a/rotary_encoder_stat.c b/rotary_encoder_stat.c new file mode 100644 index 0000000..56efe6d --- /dev/null +++ b/rotary_encoder_stat.c @@ -0,0 +1,25 @@ +#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; + } + +}