Initial commimt
This commit is contained in:
parent
d7cd9b8d4d
commit
c73d714dae
25
rotary_encoder_stat.c
Normal file
25
rotary_encoder_stat.c
Normal file
@ -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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user