You are on page 1of 7

Republic of Yemen

Embedded Systems Lab


University of science
&Technology

Faculty of Engineering

Project Exam

Preparation of Students: Supervision :


Ali Mohameed Bahameem. Dr. Jehead Alabbadi.
Project Temperature monitoring system with the PIC16F877A

introduction:

This tutorial is to help us on how to design, build, and code with Micro C, a
temperature montoring system using the PIC16F877A Microcontroller. This
circuit is built to read the input temperature with the help of the LM35
temperature sensor. This temperature is converted into an analog value
using the microcontroller , which performs a certain task depending the
temperature value.

When the tempearture is beyond the threshold temperature, the fan will
automatically turn ON and the heater will turn OFF, and when the
temperature is below the threshold value, the fan will turn OFF and the
heater will turn ON. The temperature value including the sstatus of the fan
and heater are all being displayed with the help of the Liquid Crystal
Display.
Black diagram :

Project components:
1) rrllortnocorci4aC4CF6aCPP a.
2) An LM35 Tempearture sensor.
3) 2 relays .
4) a fan .
5) a heater .
6) tow capacitors and a crystal oscillator: used to produce an input clock
frequency into the microcontroller.
7) 10K resistor and a pushbutton to reset Microcontroller when need.
8) a 5V dc input voltage source.
9) (2) 10K potentiometers: One to vary the LCD contrast and the other
one to vary the measured voltage.
Code Program :
/* Written By Eng. Ali bahameem

Temperature monitoring with the PIC16F877A MCU

*/

sbit LCD_RS at RB0_bit;

sbit LCD_EN at RB1_bit;

sbit LCD_D4 at RB2_bit;

sbit LCD_D5 at RB3_bit;

sbit LCD_D6 at RB4_bit;

sbit LCD_D7 at RB5_bit;

//

sbit LCD_RS_Direction at TRISB0_bit;

sbit LCD_EN_Direction at TRISB1_bit;

sbit LCD_D4_Direction at TRISB2_bit;

sbit LCD_D5_Direction at TRISB3_bit;

sbit LCD_D6_Direction at TRISB4_bit;

sbit LCD_D7_Direction at TRISB5_bit;

//

float temperature;

float Displaytemp;

char temp[4];

//
void main(){

TRISB=0X00; //all PORTB as output

TRISA=0x0F; //PORTA0 as input

TRISC=0X00; // PORTC as output

//

Lcd_Init(); //initialise the LCD

ADC_Init(); //initialise ADC

//

Lcd_Cmd(_LCD_CLEAR); //clear the LCD

Lcd_Cmd(_LCD_CURSOR_OFF); //cursor off

//

Lcd_Out(1,1,"temperature"); //3

Lcd_Out(2,1,"sensor"); //4

Lcd_Out(3,-3,"Designed by"); //3

Lcd_Out(4,-3,"Eng. Ali bahameem"); //1

delay_ms(3500);

//

Lcd_Cmd(_LCD_CLEAR);

Lcd_Cmd(_LCD_CURSOR_OFF);

//

while(1){

temperature=ADC_Read(RA0);
floattostr(Displaytemp,temp);

Lcd_Out(1,2,"temperature=");

Displaytemp=(temperature*50*10)/1023;

Lcd_Out(2,12,Ltrim(temp));

//

Lcd_Out(2,16,"C");

delay_ms(500);

if(Displaytemp<22){

PORTC.F0=1; //HEATER ON

PORTC.F1=0; //FAN OFF

Lcd_Out(3,-3,"HEATER ON");

Lcd_Out(3,-3,"FAN OFF");

if(Displaytemp>22 && Displaytemp<25){

PORTC.F0=0; //HEATER OFF

PORTC.F1=0; //FAN OFF

Lcd_Out(3,-3,"HEATER OFF");

Lcd_Out(3,-3,"FAN OFF");

if(Displaytemp>25){

PORTC.F0=0; //HEATER OFF


PORTC.F1=1; //FAN ON

Lcd_Out(3,-3,"HEATER OFF");

Lcd_Out(3,-3,"FAN ON");

You might also like