Thread: Need to display numbers that are passed as Literal ASCII characters to LCD

  1. #1
    Registered User
    Join Date
    Mar 2014
    Posts
    2

    Question Need to display numbers that are passed as Literal ASCII characters to LCD

    What shall I learn in order to send values from 0.00 to 5.00?

    I'm working with they Hitachi 16x2 LCD display.
    I've been sending/displaying literal values on it all day. Meaning,

    Code:
    SendCharater(unsigned char val)
    where the variable val corresponds to the LCD character table.

    I can also send Hello World to the display, like so:

    Code:
    void    putsXLCD(unsigned char *buffer){
        while(*buffer)                  // Write data to LCD up to null
        {
            while( BusyXLCD() );      // Wait while LCD is busy
            SendCharacter(*buffer); // Write character to LCD
            buffer++;               // Increment buffer
        }
        return;
        }
    I could type in putsXLCD("5.00") in order to display it on the LCD, but how do I implement this automatically for values, e.g. 0.00 to 5.00?
    It appears I can only pass literal values through the function SendCharacter, meaning that in order to display "0" I have to pass the value 0x30 (the hex value of "0" on the LCD Table).

    My current thought process:
    Much like passing "Hello World" in the function putsXLCD(), I need to assign a pointer that points at each value in the "array" that I need to send. E.g., I need to send 3.24, so I need to point to "3", fetch the corresponding hex value in the LCD table, in this case 0x34, and the pass this 0x34 into the SendCharacter function, and so on. So, if this is the case, how can I fetch the corresponding hex value?
    Last edited by JC Lee; 03-20-2014 at 03:01 PM.

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    I could type in putsXLCD("5.00") in order to display it on the LCD, but how do I implement this automatically for values, e.g. 0.00 to 5.00?
    Does your compiler support "stdio.h"? If so, perhaps you could use "sprintf()" to "print" the numbers into a character array (string), and just output that string.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Look to see if "ftoa" is supported if sprintf fails to work or exist.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  4. #4
    Registered User
    Join Date
    Nov 2012
    Posts
    157
    i did a project where standard libraries could not to be used and managed to do it by "breaking"(??) the number into individual digits and placing digit by digit onto the LCD, this of course required a check for each number (0-9), which isn't so bad as well as a check for the decimal point .
    However if 'sprintf()' is an option for you, i would recommend you use as has been previously advised.

  5. #5
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Similar to africanwizz, a few months ago I was working on an embedded project and we simply ran out of room. Simplest way to free up space was to replace sprintf() with a simple conversion function similar to ftoa() but even simpler because I knew the constraints of the number, like you do, so I didn't have to be as generic as ftoa(). The printf() family of functions are large and complicated and simply by replacing sprintf() I got the firmware space required. So, maybe try a few different solutions, it's not a waste of time.

  6. #6
    Registered User
    Join Date
    Mar 2014
    Posts
    2

    Lightbulb

    Thanks for the input. I can't seem to pass a float through sprinft, but decimals and strings I can. I wonder why... I'm using XC8 compiler for MPLAB and the manual shows it's supported.

    So now I'm using ftoa which works well.

  7. #7
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    I have used sprintf with XC8 before. Can you post your code?

    You typed sprinft instead of sprintf: That is not in your code, right?
    Fact - Beethoven wrote his first symphony in C

  8. #8
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Also, your printf function outputs to where your want to -> All you would have to do is put your SendCharacter function into putch and you have printf

    Look for "How Do I Use Printf to Send Text to a Peripheral" in manual - http://ww1.microchip.com/downloads/e...Doc/52053B.pdf

    If you are using the LCD as your main output, setting it up for printf is what you would want to me doing
    Fact - Beethoven wrote his first symphony in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to display extended ASCII characters in LINUX
    By mocatz187 in forum C Programming
    Replies: 6
    Last Post: 01-23-2010, 12:34 AM
  2. ASCII Display
    By campebell2004 in forum C Programming
    Replies: 6
    Last Post: 04-25-2006, 11:13 AM
  3. ASCII Characters
    By GreenCherry in forum Game Programming
    Replies: 6
    Last Post: 10-13-2002, 01:51 AM
  4. All the ASCII characters
    By Shadow12345 in forum C++ Programming
    Replies: 5
    Last Post: 05-20-2002, 01:20 PM
  5. ascii characters
    By Denethor2000 in forum C++ Programming
    Replies: 3
    Last Post: 03-20-2002, 05:26 AM

Tags for this Thread