temperature monitoring using PIC microcontroller



Code
#include 16f877a.h
#device adc=10 // Set ADC resolution to 10Bit
#fuses XT,NOLVP,NOWDT,NOPROTECT
#use delay(clock=4000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,ERRORS)
#include “flex_lcd.c”

#define LOAD PIN_B7
#define THRES 30.0 // load switching threshold in Celsius

int16 digital_reading; // ADC resolution is 10Bit, an 8Bit integer is not enough to hold the reading
float temp;

void main()

/* ADC Initialization */
setup_adc(ADC_CLOCK_INTERNAL); // initialize ADC with a sampling rate of Crystal/4 MHz
setup_adc_ports(RA0_ANALOG); // set PIN_A0 as analog input channel
set_adc_channel(0); // point ADC to channel 0 for ADC reading
delay_ms(1); // ADC module is slow, needs some time to adjust.

/* Peripherals Configurations */
lcd_init(); // Turn LCD ON, along with other initialization commands
output_low(LOAD); // the load is initially OFF
lcd_gotoxy(1,1); // point LCD cursor to col1 row1
lcd_putc(“Temperature is:”); // print on LCD

while(1) // infinite loop

digital_reading = read_adc(); // capture current temperature reading
delay_us(100); // 0.1ms delay for ADC stabilization
temp = digital_reading * 0.4883; // convert reading to Celsius
lcd_gotoxy(1,2); // point LCD cursor to col1 row2
printf(lcd_putc,”%2.1f C”,temp); // print value on LCD

if(temp=THRES) output_high(LOAD); // Control Load
else output_low(LOAD);

delay_ms(1000); // 1 second delay between readings


Post time: Jul-05-2017
INQUIRY NOW
  • * CAPTCHA: Please select the Key

WhatsApp Online Chat !