413
void main(void) { // Initialize LCD pins TRISCbits.TRISC0 = 0; TRISCbits.TRISC1 = 0; TRISCbits.TRISC2 = 0; TRISDbits.TRISD4 = 0; TRISDbits.TRISD5 = 0; TRISDbits.TRISD6 = 0; TRISDbits.TRISD7 = 0; // Initialize DS18B20 pin as input DS18B20_TRIS = 1; lcd_initialize(); while(1) { if(ds18b20_read(&raw_temp)) { // Convert raw value to temperature in Celsius temperature = (float)raw_temp * 0.0625; // Format temperature as a string sprintf(temp_str, "Temp: %2.1f C", temperature); // Display temperature on LCD lcd_command(0x80); // Set LCD cursor position lcd_string(temp_str, 16); // Display temperature string } else { lcd_command(0x80); lcd_string("Sensor Error!", 12); // Display error message } __delay_ms(1000); // Update every second } }