Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Display Temperature on 16X2 LCD using pic18

Status
Not open for further replies.

pcusman

Newbie level 3
Joined
May 31, 2011
Messages
3
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Activity points
1,298
Hi to all .
I am making a temperature sensor using LM 35 DZ , pic 18f452 and c18 compiler in mplab ide v 8.4

PROBLEM :-( : LCD not displaying TEMPERATURE (decimal) value .. Although Characters are displayed easily ..Please can someone do some sort of conversion from binary to ascii or whatever is required .

THANK YOU IN ADVANCE

Proteus file attached also : View attachment pic_LCD.rar

Code:
#include<p18f452.h>

#define ldata PORTD
#define rs PORTBbits.RB0
#define rw PORTBbits.RB1
#define en PORTBbits.RB2

# pragma config OSC=HS
# pragma config WDT=OFF
# pragma config LVP=OFF

void lcdcmd (unsigned char value);
void lcddata (unsigned char value);
void MSDelay (unsigned int itime);


void main(void)

{
unsigned char L_BYTE,H_BYTE,Bin_TEMP;
unsigned char temp1,temp2;

//TRISC=0;
TRISD=0;
TRISB=0;
TRISAbits.TRISA0=1;
TRISAbits.TRISA2=1;

ADCON0=0x81;
ADCON1=0xC5;

en=0;
MSDelay(250);
lcdcmd(0x38);
MSDelay(250);
lcdcmd(0x0E);
MSDelay(15);
lcdcmd(0x01);
MSDelay(15);
lcdcmd(0x06);
MSDelay(15);
lcdcmd(0x86);
lcdcmd(0x01);
MSDelay(15);
MSDelay(15);
lcddata('T');
MSDelay(15);
lcddata('E');
MSDelay(15);
lcddata('M');
MSDelay(15);
lcddata('P');
MSDelay(15);
lcddata(':');
MSDelay(15);
lcddata(Bin_TEMP);  
MSDelay(15);
lcddata(temp1);
MSDelay(15);
lcddata(temp2);  

  


while(1)
{
////***********************************////////
ADCON0bits.GO=1;
while(ADCON0bits.DONE == 1)
L_BYTE=ADRESL;
H_BYTE=ADRESH;
L_BYTE>>=2;
L_BYTE&=0x3F;
H_BYTE<<=6;
H_BYTE&=0Xc0;
Bin_TEMP=L_BYTE | H_BYTE;

temp2=0x00;
temp1=0x00;
MSDelay(250);

temp1 = Bin_TEMP/10;
temp1 =temp1 + 48;
MSDelay(250);

temp2 = Bin_TEMP % 10;
temp2 =temp2+48;

//PORTB=Bin_TEMP;

////***********************************////////

//conversion=(5.0*Bin_TEMP)/1024.0;
 // display result of ADC in LCD
// print_float(conversion);
//MSDelay(250);
//MSDelay(250);
//MSDelay(250);MSDelay(250);MSDelay(250);MSDelay(250);

}

}

void lcdcmd (unsigned char value)
{
ldata =value;
rs=0;
rw=0;
en=1;
MSDelay(1);
en=0;

}

void lcddata (unsigned char value)
{
ldata = value;
rs=1;
rw=0;
en=1;
MSDelay(1);
en=0;

}

void MSDelay (unsigned int itime)
{
unsigned int i;
unsigned int j;
for(i=0;i<itime;i++)
for(j=0;j<135;j++);
}
 

You missed
cmd(0x80) //or any cursor location
lcddata(temp1);
lcddata(temp2);

just after ascii conversion.

---------- Post added at 14:59 ---------- Previous post was at 14:36 ----------

some other hints:
You can change the justification in ADC so that no need of many << , >>, AND etc to select the MSB 8 bits out of 10bit ADC result. Change justification and then you will get the MSB 8 bits in ADRESH and LSB 2 bits in ADRESL (then take it directly from ADRESH.)


I can see some unwanted delays in your program (250ms).

Dont get confused if your LCD showing some thing other than numbers, then just remember, the 8 bit value exceeds 99.
 
Last edited:
  • Like
Reactions: zia

    zia

    Points: 2
    Helpful Answer Positive Rating
Bravo ! , finally i can display temperature , thanks a lot vinodstanur

any idea how to write write the "degree" symbol ,, what should i write inside lcddata().
 
for that you just search in google image search "ascii table" and find the ascii equivalent of that symbol. Then just call with that number.
Like lcddata(number);
 
Last edited:
Can anyone guide me how this code can be altered to get temperature to one decimal place instead of whole number
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top