// include in library Conversions
unsigned int t;
float temp;
char text[15]; // add a buffer for float conversion
void main(){
ADCON1 = 0x00;// Set all PORTA pins as analog
TRISA = 0xFF; // PORTA is input
TRISB = 0x00; // PORTB is output
PORTA=0; //clear PORTA
PORTB=0; //clear PORTB
PORTC=0; //clear PORTC
UART1_Init(9600);
Delay_ms(100);
while(1) {
PORTB=0; //clear PORTB
PORTC=0; //clear PORTC
t=ADC_Read(0);
Delay_ms(100);
temp=(float)t*500.0/1023.0;
delay_us(100);
FloatToStr(temp, text); // fill the buffer
UART1_Write_Text(text); //Output temperature values
delay_us(100);
if(temp>35){
PORTB.RB0=1;
UART1_Write_Text("_H");
}
else if(temp<10)
{
PORTB.RB0=0;
UART1_Write_Text("_L");
}
else
{
PORTB.RB0=0;
UART1_Write_Text("_N");
}
Delay_ms(400);
}