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 Temperature Sensor and 18f4520

Status
Not open for further replies.
Hi paulfjujo

Pardon me for my ignorance on the ADC.

i have the following code for writing to the LCD as below:

Code:
/* Write text data in term of 4-bit at a time to LCD */
void W_data_4bit (char x)
{
	LCD_RW = 0;			// Logic ‘0’
	LCD_RS = 1;			// Logic ‘1’
	LCD_TEMP = x;			// Store text data
	LCD_TEMP >>= 4;	        // Send upper nibble of text data
	LCD_E = 1;				// Logic ‘1’
	LCD_DATA = LCD_TEMP;
	Delay1KTCYx(1);			// 1ms delay
	LCD_E = 0;				// Logic ‘0’
	Delay1KTCYx(1);			// 1ms delay
	LCD_TEMP = x;			// Store text data
	LCD_TEMP &= 0x0f;		// Send lower nibble of text data
	LCD_E = 1;				// Logic ‘1’
	LCD_DATA = LCD_TEMP;
	Delay1KTCYx(1);			// 1ms delay
	LCD_E = 0;				// Logic ‘0’
	Delay1KTCYx(1);			// 1ms delay
}

I understand it has to be sent in a byte to the LCD for display and my ADC values has to be in ASCII code.
Hence my coding below to send out the ASCII code for display

Code:
itoa(t,Buffer);   // Convert number in variable t to a string and store in variable Buffer

for (i = 0; i < 4; i++) 
{
      W_data_4bit(Buffer[i]);
}

Unfortunately, my LCD is not displaying anything so i suspect my coding somewhere is wrong but i cant pinpoint where is the mistake.

I understand it is tedious but are you able to help me look through for errors ?
Thank you very much.
 
Last edited:

hello,

you wrote

I had done a simple program displaying "Hello World" and it is OK so i assumed the hardware connections are fine.


so you allready display TEXT on your LCD, is it true ?

if yes, do a simple test by sending on the 1rst Line of LCD
.... to solve your probleme step by step


void Tempo(long val)
{
while(val>0){val--;}
}


void main()
{
....

Init_LCD();
while(1)
{
W_ctr_4bit(0x80);
W_data_4bit('1');
W_data_4bit('0');
W_data_4bit('2');
W_data_4bit('3');

// don't forget to put a big delay to see something!
Tempo(200000L);
}
} // main


you must see 1023 on your LCD
 

Hi paulfjujo

Yes, i am able to see "Hello World" when it is stored as a const rom char MESS[12] = "Hello World"

I am rather new to programming so my explanations may not be as clear and concise.
I seek your understanding but pls do guide me along. Thanks.

I will try out your short test when i get home after work and i will post my results after that.

For info, this was the sample prog i used to output my "Hello World" which is also the one i tweaked to output my temperature reading.

Code:
const rom char MESS[12] = "Hello World"; 

void main(){
 	ADCON1 = 0x0F;			// Set Port A & E as digital I/O
	TRISA = 0b11110001;		// bit 1, 2 & 3 of Port A as output
	TRISD = 0;				// Port D as output
	Init_LCD();				// Init LCD 4-bit interface, multiple line
	for (i  = 0; i < 11; i++)		// Output message to LCD 
		W_data_4bit(MESS[i]);	// Write individual character to LCD
	while(1);				// Endless loop
}
 

Hi paulfjujo

I am unable to see the 1023 on the LCD, it doesnt shows anything..
So may i ask what is wrong here ?
 

hello,


All is based on your affirmation: it's working with Hello World test....

It doesn't works with 1023 !!!
I don't undertsand why, because caracteres are in ROM area like you message Hello World.
The only difference with your working example ,is that you didn't used ligne positionning on LCD
Just writing after init_LCD..
try again to wrtite 1023 without using "W_ctr_4bit(0x80);" in the loop
maybe this function point outside of memory area display.


The other difference i saw in your previous test
is using RAM buffer
Code:
W_data_4bit(Buffer[i]);
instead of ROM buffer like
Code:
const rom char MESS[12] = "Hello World";
 

Hi paulfjujo

I have got my LCD working now. I forgot the most impt TRISD out statement.
Thanks for the guidance.

Now im trying to make it look proper by trying to show the temperature as 25.x instead of just a whole number 25.
How am i able to do that ?
 

Store your adc result to floating point variable instead of integer variable. If number is 25.345 then multiply it with 1000 to get 25345 then subtract 25000 from 25345 to get 345 then convert 25 and 345 to string and display on lcd.
 

Hi Jayanth

Lets say i just want to put the temperature at 25.3, so i will multiply by 10 to get 253.

Code:
unsigned float t=0;

val = ADRESH & 0xff;		
t = ((val/255.0) * 500); 	

t = t *10;   // 253
t = ??        // So how do i subtract 250 here since it wont be 250 everytime ??

itoa(t,Buffer);	// Using my method to show on LCD, how do i convert to 25 and 3 to ascii and then show on LCD ??

for (i = 0; i < 4; i++) 
{
	W_data_4bit(Buffer[i]);	    
	Delay1KTCYx(5);			
}

I can understand the method but i have difficulty adapting it in terms of coding.
Are you able to help me ?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top