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.

LM35 interface to pic and LCD

Status
Not open for further replies.

engr.waqas

Full Member level 3
Full Member level 3
Joined
Jul 21, 2009
Messages
172
Helped
13
Reputation
26
Reaction score
10
Trophy points
1,298
Location
karachi,Pakistan
Activity points
2,342
pic lm35

I want to connect LM35 temp sensor with pic 18f452 and display reading on LCD,when i simulate it on proteus i get strange symbols (like #,! etc) instead of reading of temp sensor .
plz help ,my C coding in mplab is
#include <P18f452.h>

#define rs PORTBbits.RB0
#define rw PORTBbits.RB1
#define en PORTBbits.RB2
void lcdcmd( char );

void MSDelay(unsigned int);
void main (void)
{

// a to d
long lbyte=0,hbyte=0,bin=0;

TRISD=0;
TRISAbits.TRISA0=1;
TRISAbits.TRISA2=1;
ADCON0=0x81; //fosc/64,channel 0,A\D is on
ADCON1=0xC5; //right justified,fosc/64,AN0=analog,AN3=vref+
while (1)
{
MSDelay(1); // give A to D time to sample
ADCON0bits.GO=1;//start converting
while(ADCON0bits.DONE==1); //wait for EOC
lbyte=ADRESL; // save low byte
hbyte=ADRESH; // save high byte
lbyte>>=2;
lbyte&=0x3F;
hbyte<<=6;
hbyte&=0xC0;

bin=lbyte|hbyte;


//display on LCD


TRISB=0;
TRISD=0;

en=0;
MSDelay(250);
lcdcmd(0x38);
MSDelay(250);
lcdcmd(0x0E);
MSDelay(15);
lcdcmd(0x01);
MSDelay(15);
lcdcmd(0x06);
MSDelay(15);
lcdcmd(0x86);
MSDelay(15);

PORTD=bin;
rs=1;
rw=0;
en=1;
MSDelay(1);
en=0;
MSDelay(15);
}
}
void lcdcmd( char value)
{
PORTD=value;
rs=0;
rw=0;
en=1;
MSDelay(1);
en=0;
}

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

pic and lcd

I think it would be better if you change the location of TRISB and TRISD to be before the "while(1)" loop.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top