#define ENCA(add,bit) bit_is_set(add,bit)
#define ENCB(add,bit) bit_is_set(add,bit)
#define state1 0
#define state2 1
#define state3 3
#define state4 2
long ctr;
unsigned char clockx,clocky,clockz1,clockz2;
void go_count(char bit1, char bit2);
void encoder(){
if(ENCA(PINA,2)) clockx=1; else clockx=0;
if(ENCB(PINA,3)) clocky=2; else clocky=0;
clockz1=clockx+clocky;
do {
if(bit_is_set(PINA,2)) clockx=1; else clockx=0;
if(bit_is_set(PINA,3)) clocky=2; else clocky=0;
clockz2=clockx+clocky;
} while(clockz1==clockz2);
go_count(clockz1,clockz2);
}
void go_count(char bit1, char bit2)
{
if(bit1==state1 && bit2==state2 ) {ctr++;print_str(" clock ");}
else if(bit1==state4 && bit2==state3) {ctr--;print_str(" anti ");}
else if(bit1==state2 && bit2==state3) {ctr++;print_str(" clock ");}
else if(bit1==state3 && bit2==state2) {ctr--;print_str(" anti ");}
else if(bit1==state3 && bit2==state4) {ctr++;print_str(" clock ");}
else if(bit1==state2 && bit2==state1) {ctr--;print_str(" anti ");}
else if(bit1==state4 && bit2==state1) {ctr++;print_str(" clock ");}
else if(bit1==state1 && bit2==state4) {ctr--;print_str(" anti ");}
}