isaac12345
Member level 2
Hi,
I'm trying to read the value of a TMP36 temperature sensor with the help of an ADC of the pic16f877a. Below is my code. I'm using the CCS C compiler.
The problem is that the ADC returns such a value that the PIC goes into the IF statement and switches off the pin, even if the temperature read by the TMP36 is less than 45C. Is this problem due to some configuration of the ADC that I've missed?
I'm trying to read the value of a TMP36 temperature sensor with the help of an ADC of the pic16f877a. Below is my code. I'm using the CCS C compiler.
Code:
#include "16F877A.h"
#device ADC=10
#use fast_io(A)
void main() //********************************************
{
int adc_value;
int temperature;
set_tris_a(1); //setting port A to output
set_adc_channel(0); //channel 0 selected or pin RA0 selected for adc
setup_adc(ADC_CLOCK_DIV_8);
setup_adc_ports(RA0_ANALOG);
output_high(PIN_D1);
adc_value=read_adc(); //read value off adc
temperature= adc_value/2; //convert adc raw value into temperature in degree celsius
if(temperature>=45) //if temperature is more than specified limits, switch off pin D0
output_low(PIN_D1);
}
The problem is that the ADC returns such a value that the PIC goes into the IF statement and switches off the pin, even if the temperature read by the TMP36 is less than 45C. Is this problem due to some configuration of the ADC that I've missed?