#include <16f877A.h> //requirement
#fuses hs,nowdt, noprotect, brownout, nolvp //requirement
#use delay(clock=20000000) //requirement
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7, parity=N) //whats this for?
void main()
{
int reg=0; // initialize register
set_tris_a(255); // set port a as input
set_tris_b(0); // set pin b as output
do
{
start:
if(input(PIN_A0)==0 && input(PIN_A1)==1) //check for A=0 B=1
{ delay_ms(5); //if A=0 B=1 then delay
if(input(PIN_A0)==0 && input(PIN_A1)==1) //if no change goto start
{ goto start; }
else goto a0b0; //goto a0b0
a0b0: //check for A=0 B=0
if(input(PIN_A0)==0 && input(PIN_A1)==0)
{ delay_ms(5); //if A=0 B=0 then delay
if(input(PIN_A0)==0 && input(PIN_A1)==0) //if no change goto a0b0
{ goto start;}
else goto a1b0;
}
else if(input(PIN_A0)==0 && input(PIN_A1)==1)
{goto start;}
else goto a0b0;
a1b0:
if(input(PIN_A0)==1 && input(PIN_A1)==0)
{ delay_ms(5);
if(input(PIN_A0)==1 && input(PIN_A1)==0)
{ goto start;}
else goto a1b1;
}
else if(input(PIN_A0)==0 && input(PIN_A1)==0)
{goto start;}
else goto a1b0;
a1b1:
if(input(PIN_A0)==1 && input(PIN_A1)==1)
{ reg++; //increment register
if(reg>0) //check register
{output_bit(PIN_D5, 1);} //if register is >0 Output=HIGH
else
{ output_bit(PIN_D5, 0);}
delay_ms(1000);
goto start;
}
else if(input(PIN_A0)==1 && input(PIN_A1)==0)
{goto start;}
else goto a1b1;
}
else
{goto start2;}
start2:
if(input(PIN_A0)==1 && input(PIN_A1)==0)
{ delay_ms(5);
if(input(PIN_A0)==1 && input(PIN_A1)==0)
{ goto start; }
else goto a20b0;
a20b0:
if(input(PIN_A0)==0 && input(PIN_A1)==0)
{ delay_ms(5);
if(input(PIN_A0)==0 && input(PIN_A1)==0)
{ goto start;}
else goto a0b1;
}
else if(input(PIN_A0)==1 && input(PIN_A1)==0)
{goto start;}
else goto a20b0;
a0b1:
if(input(PIN_A0)==0 && input(PIN_A1)==1)
{ delay_ms(5);
if(input(PIN_A0)==0 && input(PIN_A1)==1)
{ goto start;}
else goto a21b1;
}
else if(input(PIN_A0)==0 && input(PIN_A1)==0)
{goto start;}
else goto a0b1;
a21b1:
if(input(PIN_A0)==1 && input(PIN_A1)==1)
{ reg--; //decrement register
if(reg>0) //check register
{output_bit(PIN_D5, 1);} //if register is >0 Output=HIGH
else
{ output_bit(PIN_D5, 0);}
delay_ms(1000);
goto start;
}
else if(input(PIN_A0)==0 && input(PIN_A1)==1)
{goto start;}
else goto a21b1;
}
else goto start;
}while(1);
}