Displaying real-time data through LCD


As of now, I can display text through a 4x20 LCD ("Hello World!"). However, I need to display real-time data which is computed every 2secs.

In the sample codes that I have seen (and have used), the character is sent one at a time:

lcd_puts(const char *s){ while(*s) lcd_write(*s++); }

and the input is a predefined string:

in main function: lcd_puts("Hello World!");

My question is, how can I modify my code to display real-time data (int or float)?

I'm thinking of something like the printf function which will be called everytime data needs to be displayed: printf("Reading: %d",data);

But how can I implement this if the data is a predefined string and if the data is sent one char at a time?

Thank you!

Reply to
Loading thread data ...

sprintf(); itoa(); math to break the number down to characters.

Reply to

Either use sprintf() to create a string which you can send character by character or check your compiler manuals how to implement your own putchar(). Most compilers allow you to create your own putchar() function, tailored to your hardware. All other standard C functions that print something, like puts(), printf() etc., will eventually call putchar().


Reply to
Meindert Sprang

Hopefully lcd_write has all the correct handling for the delays for writing to the lcd, and more importantly a TIMEOUT and error return. So that if the LCD fails or its connector 'falls off' the code does not get stuck there!

If you have a spare timer consider using a timer interupt to o/p the next character from a buffer to the display. }

Do you need full float capability for the data that will be displayed? Do you really need on a small display to show 6 or more decimal places?

Are the figures you are going to display going to have a maximum number of digits (integer and/or fraction part)? If so consider rolling your own integer conversion and doing a fixed point over function to display two effective 'integers'.

Know the positions of your data numbers and exactly their min/max sizes. Always get data to print on certain boundaries.

Others have said how you can create your own put_char() and using functions like sprintf and itoa as well.

Do some tests for your library and target, as I remember you saying you are using some form of Zilog mcu, do you have enough Flash/RAM space to use printf/sprintf functions?

printf/sprintf functions and associated functions are large users of memory on most compliers as they have the ability to display a lot more formats than you will require on a 4 x 20 LCD.

In some cases you will not have room on the display anyway.

Look at a HD44780 data sheet also for how to address the display RAM so you ONLY update the data portion of a line with the new numbers, not rewrite the whole line or display.

If you hunt around the GNUH8 site mentioned below there is a 'C' LCD example (written for a different micro), that may well help.

Paul Carpenter          | paul@pcserviceselectronics.co.uk
    PC Services
 Click to see the full signature
Reply to
Paul Carpenter

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.