Please Help, A/D converter
Posted: Fri Dec 08, 2006 5:33 am
I am using the pic 16f877a and for some reason the a/d is giving us random values when there is not an input. Here is the code that I am using. Maybe someone can help me with this problem.
option_reg = 0x06;
TRISA = 0xff;
clear_wdt();
adcon1 = 0x02;
adcon0 = 0x80;
adcon0 = 0x81; // bsf ADON
delay_ms(20);
adcon0 |= 0x04;
delay_ms(20);
while(adcon0 & 0x04)
;
PORTD = 0xff;
PORTE = 0xff;
int TEMPERATURE = 0x00;
// holds the 10bit result in a 16bit variable
TEMPERATURE = (adresh|(adresl<<8));
option_reg = 0x06;
TRISA = 0xff;
clear_wdt();
adcon1 = 0x02;
adcon0 = 0x80;
adcon0 = 0x81; // bsf ADON
delay_ms(20);
adcon0 |= 0x04;
delay_ms(20);
while(adcon0 & 0x04)
;
PORTD = 0xff;
PORTE = 0xff;
int TEMPERATURE = 0x00;
// holds the 10bit result in a 16bit variable
TEMPERATURE = (adresh|(adresl<<8));