PIC16F887 ADC channel 7 (AN7) does not work. I randomly tried channel 0 (AN0), channel 6 (AN6) and channel 13 (AN13) all worked. I am not sure if all other channel would work. It would be wise to test all other channels when fixing channel 7. Below is the code with channel 7 selected and did not work. The code is written using mikroC PRO.
unsigned int adc_out_decimal;
void main()
{
ANSEL = 0B10000000;
ANSELH = 0x00;
TRISE.RE2= 1;
TRISB = 0x00;
PORTB = 0x00;
while(1)
{
adc_out_decimal = ADC_Read(7);
if (adc_out_decimal <= 512)
{
PORTB = 0x55;
}
else
{
PORTB = 0xAA;
}
delay_ms(50);
}
}
unsigned int adc_out_decimal;
void main()
{
ANSEL = 0B10000000;
ANSELH = 0x00;
TRISE.RE2= 1;
TRISB = 0x00;
PORTB = 0x00;
while(1)
{
adc_out_decimal = ADC_Read(7);
if (adc_out_decimal <= 512)
{
PORTB = 0x55;
}
else
{
PORTB = 0xAA;
}
delay_ms(50);
}
}