#include <18f4550.h>
#device adc=10
#fuses HS,XT,NOPUT,NOPROTECT,NOMCLR
#use delay(clock=12M)
#use fast_io(a)
#use fast_io(d)
#include <lcd.c>
#include <math.h>
int16 NtcBeta=4050, ReadNtc=0;
float ResNtc=0,Vntc=0,Temp1,Temp2;
#int_ad
void LecturaSondas()
{
set_adc_channel(0);
delay_us(20);
ReadNtc = Read_ADC(ADC_READ_ONLY);
Vntc = 5.0 * ReadNtc / 1024.0;
ResNtc = Vntc * 10000.0 / ( 5.0 - Vntc ) ;
Temp1
= (1.0 / (((log(ResNtc
/20000.0) * (1.0 / NtcBeta
) )) + (1 / 298.15))) - 273.15;
Read_ADC(ADC_START_ONLY);
set_adc_channel(1);
delay_us(20);
ReadNtc = Read_ADC(ADC_READ_ONLY);
Vntc = 5.0 * ReadNtc / 1024.0;
ResNtc = Vntc * 10000.0 / ( 5.0 - Vntc ) ;
Temp2
= (1.0 / (((log(ResNtc
/20000.0) * (1.0 / NtcBeta
) )) + (1 / 298.15))) - 273.15;
Read_ADC(ADC_START_ONLY);
}
void main()
{
set_tris_b(0x00);
set_tris_a(0b00000011);
lcd_init();
enable_interrupts(INT_AD);
enable_interrupts(GLOBAL);
setup_port_a(AN0_TO_AN1);
setup_adc(ADC_CLOCK_INTERNAL);
clear_interrupt(INT_AD);
while(1)
{
lcd_gotoxy
(1,1); printf(Lcd_putc
,"Temp1 %02.2f",Temp1
); lcd_gotoxy
(1,2); printf(Lcd_putc
,"Temp2 %02.2f",Temp2
);
}
}