0% found this document useful (0 votes)
52 views

Lm35 Temperature Sensor Programme

This document contains code for a PIC microcontroller to read the temperature from an analog sensor and display the temperature and heating time on an LCD. It initializes the LCD, sets the pin definitions, reads the analog temperature value, converts it to Celsius, and displays the temperature on the first row of the LCD. If the temperature is below 100C, it displays "HEATING" on the second row. Otherwise, it increments the heating time counters and displays the time in minutes and seconds on the second row.

Uploaded by

sr3sh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Lm35 Temperature Sensor Programme

This document contains code for a PIC microcontroller to read the temperature from an analog sensor and display the temperature and heating time on an LCD. It initializes the LCD, sets the pin definitions, reads the analog temperature value, converts it to Celsius, and displays the temperature on the first row of the LCD. If the temperature is below 100C, it displays "HEATING" on the second row. Otherwise, it increments the heating time counters and displays the time in minutes and seconds on the second row.

Uploaded by

sr3sh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <16f877A.

h>

#fuses HS,NOPROTECT,NOWDT,PUT

#use delay(clock=4000000) //change here according to ur clock speed

#include <lcd.c>

#define LCD_ENABLE_PIN PIN_B6 //change here according to ur pin from PIC to LCD

#define LCD_RS_PIN PIN_B7 // ''

#define LCD_RW_PIN PIN_B1 // ''

#define LCD_DATA4 PIN_B5 // ''

#define LCD_DATA5 PIN_B4 // ''

#define LCD_DATA6 PIN_B3 // ''

#define LCD_DATA7 PIN_B2 // ''

int count_time=0, count_time_s=0, count_time_m=0;

long val=0;

float temp=0;

float overall_delay_time, c;

void main()

setup_adc_ports(RA0_ANALOG);

setup_adc( ADC_CLOCK_INTERNAL );

set_adc_channel(0);

lcd_init();

while(true)

//////////////////////sensor programm start here////////////////////////////////

val=read_adc(); //read ADC store in val

delay_ms(100);
temp = (val/1023.0)*5*100; //convert val to temperature in celcius

lcd_init();

lcd_gotoxy(0,0); //set cursor at 1st row 1st column

printf(lcd_putc,"temp = %4.2f",temp);

if(temp<100)

count_time_s=0;

count_time_m=0;

lcd_gotoxy(0,1); //set cursor at 1st row 1st column

printf(lcd_putc,"time = HEATING");

else

count_time++;

/*

make sure overall delay in the code is 1 second

so sount_time_s increase by 1 every second. otherwise,

change value of 'overall_delay_time' <-------- TAKE NOTE

for example, if overall delay in the code is 500ms:

long overall_delay_time=0.5; <-------- IMPORTANT

*/

overall_delay_time=1; //if overall delay is 1 second

c=1/overall_delay_time;

count_time_s=count_time/c;

if(count_time_m<30) //if less than 30 minutes, count_time_m increase by 1 after 60 second

{
if (count_time>=(60*c))

count_time_m++; //count_time_m increase by 1 every 60 second

count_time=0; //reset count_time_s to ZERO after 60 second

lcd_gotoxy(0,1); //set cursor at 1st row 1st column

printf(lcd_putc,"time=%dm%ds",count_time_m,count_time_s);

else

lcd_gotoxy(0,1); //set cursor at 1st row 1st column

printf(lcd_putc,"DONE");

while(1){} // program END and do nothing

delay_ms(400);

//////////////////////sensor programm end here//////////////////////////////////

You might also like