void main()
{
TRISA = 0xFF;
TRISB = 0xFF; // Set PORTB as Input
TRISC = 0xFF;
TRISD = 0x00; // Set PORTD as Input
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
CMCON = 0x07;
ADCON1 = 0b10000110;
// or
// ADCON1 = 0b10000111;
while(1)
{
if(PORTB =0x14) // If RA0 is Toggled
{
TRISD = 0x00; // Set PORTB as Output
PORTD = 0x06; // Toggle On;
}
else if (PORTB= 0x10) //0x04 - 100
{
TRISD = 0x00 ;
PORTD= 0x24 ;
//hall_state = 5;
}
else if (PORTB= 0x18) //0x06 - 110
{
TRISD = 0x00 ;
PORTD= 0x21 ;
//hall_state = 6;
}
else if (PORTB= 0x08 ) //0x02 - 010
{
TRISD = 0x00 ;
PORTD= 0x09;
//hall_state = 1;
}
else if (PORTB= 0x0C) //0x03 - 011
{
TRISD = 0x00 ;
PORTD= 0x18;
//hall_state = 2;
}
else if (PORTB= 0x04)
//0x01 - 001
{
TRISD = 0x00 ;
PORTD = 0x12;
//hall_state = 3;
}
else
{
PORTD= 0x00;
}
}
}