PIC16F876 - read analog values
Posted: Mon Dec 07, 2015 10:25 am
Hello,
I am trying to read the tempreture using a TMP36 sensor on a PIC16F876.I use MPLab and a XC8 compiler to compile my code. I simply don't know what are the values that I should put in the ADC registers.
Here is a code I found for the PIC16F877 but it does not work on my microcontroller.
Can you please tell me what modifications should I do to this code so that it works properly on the PIC16F876?
Thank you
I am trying to read the tempreture using a TMP36 sensor on a PIC16F876.I use MPLab and a XC8 compiler to compile my code. I simply don't know what are the values that I should put in the ADC registers.
Here is a code I found for the PIC16F877 but it does not work on my microcontroller.
- Code: Select all
ADCON1bits.ADFM = 1; //Result right justified
ADCON1bits.PCFG = 0; //Setting all the analog ports as Analog inputs
ADCON0bits.ADON = 1; //Turns on ADC module
ADCON0bits.CHS = 0; //Selects channel 0 ( AN0 )
int ADCResult;
while(1)
{
__delay_us(25); //Waits for the acquisition to complete
ADCON0bits.GO = 1; //Starts ADC conversion
while (ADCON0bits.nDONE) continue; //wait till ADC conversion is over
ADCResult = (ADRESH<<8) + ADRESL ;
}
Can you please tell me what modifications should I do to this code so that it works properly on the PIC16F876?
Thank you