enum phase[_]status{
phase[_]no[_]move= 0,
phase[_]dec,
phase[_]inc,
phase[_]bad
};
u8 volatile PhaseShift;
cONst u8 table[_]Phase[16]=
{
phase[_]no[_]move,phase[_]dec,phase[_]inc,phase[_]bad,
phase[_]inc,phase[_]no[_]move,phase[_]bad,phase[_]dec,
phase[_]dec,phase[_]bad,phase[_]no[_]move,phase[_]inc,
phase[_]bad,phase[_]inc,phase[_]dec,phase[_]no[_]move,
};
U8 whell[_]scan(void)
{
static s8 PhaseCount = 0;
PhaseShift <<= 2;
if((REG32(P4SIN) & (1<<3))) PhaseShift |= 0x01;
if((REG32(P1SIN) & (1<<2))) PhaseShift |= 0x02;
PhaseShift &= 0x0f;
if(table[_]Phase[PhaseShift] == phase[_]inc) PhaseCount++;
if(table[_]Phase[PhaseShift] == phase[_]dec) PhaseCount--;
if(PhaseCount > 3)
{
PhaseCount -= 4;
return phase[_]inc;
}
else if(PhaseCount < -3)
{
PhaseCount += 4;
return phase[_]dec;
}
return phase[_]no[_]move;
}