Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Design of Digitial Temperature Monitoring System using PIC16F877A.

Status
Not open for further replies.

ah_loon

New Member
Hi,

I am designing a digital temperature monitoring system using PIC16F877A and sensor (PT100). I am required to measure and display the temp on a 16x2 LCD. I am using MPLab with Hi-Tech C-Compiler. I have a code but it does not seems to work. I need help on the codings.
 
Post what you done Like code and how you have the hardware setup and we can help you
 
Post what you done Like code and how you have the hardware setup and we can help you

Hi be80be,

My codes as follow,

#include<pic.h>

//===============configuration==============================
__CONFIG (0x3F32);

//===============define IO port=============================
#define lcd PORTC // for LCD Display
#define keypad PORTD // for input from keypad
#define RS RA2
#define E RA5
#define CHANNEL0 0b10000001 // AN0 sensor 1
#define buzzer RB5 // for the buzzer
#define redled RB4 // Red LED for temp over spec
#define orangeled RB1 // Orange LED for warning
#define yellowled RB2 // Yellow LED for indication sensor working

//==============FUNCTION PTOTOTYPE=========================
void e_pulse(void);
void delay(unsigned short i);
void send_char(unsigned char data);
void send_config(unsigned char data);
void lcd_goto(unsigned char data);
void lcd_clr(void);
void dis_num(unsigned long data);
void increment(unsigned long data);
void read_adc(void);
unsigned short read_temp(void);

//====================MAIN================================
unsigned short result;
unsigned short temp,tempA;

void main(void)
{
ADRESH=0; //clear A/D result
ADRESL=0; //clear A/D result

//setting ADCON1 Register
ADCON1=0b11000101; // A/D result right justified,
// configure RA2 and RA5 as digital I/O

TRISA=0b11011011; //configure PORTA I/O direction
TRISB=0b00000000; //configure PORTB as output
TRISC=0b00000000; //configure PORTC as output

PORTA=0;
PORTB=0;

while(1)
{
send_config(0b00000001); //clear display at lcd
send_config(0b00000010); //Lcd Return to home
send_config(0b00000110); //entry mode-cursor increase 1
send_config(0b00001100); //diplay on, cursor off and cursor blink off
send_config(0b00111000); //function set

lcd_goto(0); //cursor start from beginning

//display character on LCD
send_char(' ');
send_char('T');
send_char('E');
send_char('M');
send_char('P');
send_char('.');
send_char('A');
send_char('=');

while(1) //infinity loop
{
//sensor A
ADCON0=CHANNEL0; //CHANNEL1=0b10001001
lcd_goto(8);

read_adc();

temp=read_temp();
dis_num(temp/10);
send_char('.');
dis_num(temp%10);
send_char(0b11011111);
send_char('C');
send_char(' ');
send_char(' ');

tempA=temp;

if((tempA<900)) // *****************************************
{ // temperature within range of -50 to 90deg
redled=0; // yellow led will be on
orangeled=0; // *****************************************
yellowled=1;
buzzer=0;
}

else if((tempA>800)) // ******************************************
{
redled=0; // temperature reaching spec of 90deg (+/-10)
orangeled=1; // yellow led & orange led will turn on
yellowled=1; // ******************************************
buzzer=0;
}

else if((tempA>900)) // ******************************************
{ // temperature over the max spec of 90deg
redled=1; // all the leds and buzzer will turn on
orangeled=1; // ******************************************
yellowled=1;
buzzer=1;
}

else if((tempA>-400)) // *********************************************
{ // temperature reaching spec of -50deg (+/-10)
redled=0; // yellow led & orange led will turn on
orangeled=1; // *********************************************
yellowled=1;
buzzer=0;
}

else if((tempA>-50)) // **********************************************
{ // temperature over the min spec of -50deg
redled=1; // all the leds and buzzer will turn on
orangeled=1; // **********************************************
yellowled=1;
buzzer=1;
}

delay(2000);

}

}

}



//==================subroutine LCD setting ==========================

void send_config(unsigned char data)
{
RS=0;
lcd=data;
delay(500);
e_pulse();
}

void e_pulse(void)
{
E=1;
delay(500);
E=0;
delay(500);
}

void send_char(unsigned char data)
{
RS=1;
lcd=data;
delay(500);
e_pulse();
}


void lcd_goto(unsigned char data)
{
if(data<16)
{
send_config(0x80+data);
}
else
{
data=data-20;
send_config(0xc0+data);
}
}


void lcd_clr(void)
{
RS=0;
send_config(0x01);
delay(600);
}


void dis_num(unsigned long data)
{
unsigned char hundred_thousand;
unsigned char ten_thousand;
unsigned char thousand;
unsigned char hundred;
unsigned char tenth;

hundred_thousand = data/100000;
data = data % 100000;
ten_thousand = data/10000;
data = data % 10000;
thousand = data / 1000;
data = data % 1000;
hundred = data / 100;
data = data % 100;
tenth = data / 10;
data = data % 10;

if(hundred_thousand>0)
{
send_char(hundred_thousand + 0x30); //0x30 added to become ASCII code
send_char(ten_thousand + 0x30);
send_char(thousand + 0x30);
send_char(hundred + 0x30);
send_char(tenth + 0x30);
send_char(data + 0x30);
}

else if(ten_thousand>0)
{
send_char(ten_thousand + 0x30); //0x30 added to become ASCII code
send_char(thousand + 0x30);
send_char(hundred + 0x30);
send_char(tenth + 0x30);
send_char(data + 0x30);
}
else if(thousand>0)
{
send_char(thousand + 0x30); //0x30 added to become ASCII code
send_char(hundred + 0x30);
send_char(tenth + 0x30);
send_char(data + 0x30);
}
else if(hundred>0)
{
send_char(hundred + 0x30); //0x30 added to become ASCII code
send_char(tenth + 0x30);
send_char(data + 0x30);
}
else if(tenth>0)
{
send_char(tenth + 0x30); //0x30 added to become ASCII code
send_char(data + 0x30);
}
else send_char(data + 0x30); //0x30 added to become ASCII code
}

void increment(unsigned long data)
{
unsigned short j;
for(j=10;j>0;j--)
{ lcd_goto(32);
data=data+1;
dis_num(data);
delay(10000);
}

}

//==================subroutine ADC=========================

void read_adc(void)
{
unsigned short i;
unsigned long result_temp=0;
for(i=2000;i>0;i-=1) //looping 2000 times for getting average value
{
ADGO = 1; //ADGO is the bit 2 of the ADCON0 register
while(ADGO==1); //ADC start, ADGO=0 after finish ADC progress
result=ADRESH;
result=result<<8; //shift to left for 8 bit
result=result|ADRESL; //10 bit result from ADC

result_temp+=result;
}
result = result_temp/2000; //getting average value

}

unsigned short read_temp(void)
{
unsigned short temp;
temp=result;
return temp;

}

//==================subroutine DELAY==========================
void delay(unsigned short i)
{
for(;i>0;i--);
}
 
Please use the code tags...

while(1)
{
send_config(0b00000001); //clear display at lcd
send_config(0b00000010); //Lcd Return to home
send_config(0b00000110); //entry mode-cursor increase 1
send_config(0b00001100); //diplay on, cursor off and cursor blink off
send_config(0b00111000); //function set

lcd_goto(0); //cursor start from beginning

Wrong way round.... function set first at least twice with a 15ms delay between them.
 
Last edited:
Interface PIC16F877A with VB for Display of ADC Readings

Sorry i did a mistake
 
Last edited:
send_config(0b00000001); //clear display at lcd
send_config(0b00111000); //Funtion set
delayMs(15);
send_config(0b00111000); //Funtion set
delayMs(5);
send_config(0b00001100); //diplay on, cursor off and cursor blink off
send_config(0b00001100); //entry mode-cursor increase 1
send_config(0b00000001); //Clear display cursor home

Correct way round delays after the function set
 
Correct way round delays after the function set

Hi Roger,
Thanks for the help. I did try out your codes and reference around with the same format.
But after I admend the codes, my LCD is still not showing any characters. Instead only the first row with black cursors and second row blank.
 
Sorry!! When I pasted the last code I managed to leave the "Clear display" line in at the beginning... Lose that first line..

Hi Roger,

Yup, i did left out the first line before. But the LCD is still not displaying. It is still only showing black bars on the first line and blank on the second.

my codes for the LCD is as follow,
//LCD Configuration
send_config(0b00111000); //Funtion set
delay(15);
send_config(0b00111000); //Funtion set
delay(5);
send_config(0b00001100); //diplay on, cursor off and cursor blink off
send_config(0b00001100); //entry mode-cursor increase 1
send_config(0b00000001); //Clear display cursor home

I do not know what else is wrong.
 
The display is not initializing.... I'll drop the code into ISIS and find out whats up


Right... Even the code you pasted in post 3 works in ISIS ( I'm assuming a pic16f877a running at 4mHz .. let me know if its not )
 
The display is not initializing.... I'll drop the code into ISIS and find out whats up


Right... Even the code you pasted in post 3 works in ISIS ( I'm assuming a pic16f877a running at 4mHz .. let me know if its not )

i connect a 20MHz crystal to the PIC. after looking around, i managed to get the lcd working. thanks alot for the help.
are you familar with the PT100 sensor? As i am having trouble getting the readings now.
 
The display is not initializing.... I'll drop the code into ISIS and find out whats up


Right... Even the code you pasted in post 3 works in ISIS ( I'm assuming a pic16f877a running at 4mHz .. let me know if its not )

Hi Ian,
I am trying to display a simple welcome string first before looping start the test. I tried but unable to do so. Could you help me on this?
My codes as follow,
//LCD Settings
send_config(0b00000001); //clear display at lcd
send_config(0b00000010); //Lcd Return to home
send_config(0b00000110); //entry mode-cursor increase 1
send_config(0b00001100); //diplay on, cursor off and cursor blink off
send_config(0b00111000); //function set

lcd_clr(); //clear LCD
delay(1000); //delay
lcd_goto(0); //initial display
send_string("Welcome to ..."); //Display "Welcome" on lcd
delay(1000);

while(1)
{
lcd_clr();
lcd_goto(0); //cursor start from beginning

//display character on LCD
send_char(' ');
send_char('S');
send_char('P');
send_char('E');
send_char('C');
send_char('.');
send_char('.');
send_char('=');
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top