Mywk
Newbie level 5
PIC16F716 ADC With LM35CZ (Updated)
Hey Guys, I'm trying to read the temperature out of a LM35CZ, it outputs the amount of Celsius degrees in mV (Example 20Cº = 0.20V).
Here is the schematics, simulation in Proteus seems OK:
**broken link removed**
I'm using the following code, I'm using CCS C:
Works in Proteus, however, this is what happens in reality:
If temperature is below 13C the LED is ON, if above, OFF, when it should be more than 21 ON, less OFF, so what could be wrong?
Thanks In Advance!
Hey Guys, I'm trying to read the temperature out of a LM35CZ, it outputs the amount of Celsius degrees in mV (Example 20Cº = 0.20V).
Here is the schematics, simulation in Proteus seems OK:
**broken link removed**
I'm using the following code, I'm using CCS C:
Code:
#include <16F716.h>
#device adc=8
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT
#use delay(clock=4000000)
void main(void)
{
set_tris_b(0);
output_high(PIN_B1); // Power On
int16 reading;
float temp;
setup_adc_ports(PIN_A0);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
delay_us(20);
while(1)
{
reading = read_adc();
temp = 5* reading * 100/255;
if(temp > 21)
output_high(PIN_B2);
else
output_low(PIN_B2);
delay_ms(1000);
}
}
Works in Proteus, however, this is what happens in reality:
If temperature is below 13C the LED is ON, if above, OFF, when it should be more than 21 ON, less OFF, so what could be wrong?
Thanks In Advance!
Last edited: