Joining variables and displaying on an LCD


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 2007
    Location
    Mississauga, Ontario, Canada
    Posts
    29

    Default Joining variables and displaying on an LCD

    I'm having trouble trying to convert numbers into strings, joining them together and displaying on an LCD display.

    Essentially what's going on is that I receive a data stream via RF and from that stream I'm trying to extract bits and pieces of information and then formatting them to display on an LCD.
    Long story short, I'm extracting three numbers representing the tens, units, and decimals - for example numbers 2, 5 and 7 and assigning them to variables (such as TempTens, TempUnits and TempDecimals)
    I'm trying to display this info on an LCD display to be shown as "25.7"

    Sure, I could issue a command
    LCDOUT $fe, $c0, #TempTens, #TempUnits,".",#TempDecimals
    but I'm wondering if there is a way of merging the three variables into a string and then displaying the whole thing so that my LCDOUT command doesn't get cluttered.

    Any help would be appreciated.

  2. #2
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Navaidstech View Post
    I could issue a command
    LCDOUT $fe, $c0, #TempTens, #TempUnits,".",#TempDecimals
    but I'm wondering if there is a way of merging the three variables into a string and then displaying the whole thing so that my LCDOUT command doesn't get cluttered.
    You could make it a string variable, but it would add an extra step, and would add clutter to another line. So it would really be more clutter. I realize neatness counts, but in this case your current code is very readable. And hey, you're the only person that's going to be bothered by it. No one else will know its there.
    Last edited by ScaleRobotics; - 28th April 2009 at 15:36.

  3. #3
    Join Date
    Aug 2007
    Location
    Mississauga, Ontario, Canada
    Posts
    29


    Did you find this post helpful? Yes | No

    Default

    I see your point, and it DOES make sense.

    My only problem is that this variable will be distributed in numerous locations on the LCD screen. Had it only been one location, I wouldn't be too concerned about clutter and such.
    So essentially, as you have mentioned, I need to create a string variable. I tried a few things last night (it was getting late and I tried doing it while wearing a Visual Basic hat) but couldn't get it to work.
    Last edited by Navaidstech; - 28th April 2009 at 17:56.

  4. #4
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Ok, that makes sense. Here is the easy way. It is still not making it a string though. Let me ponder the string route.......

    Code:
    LCDOUT (lcd command to move cursor to desired position goes here)
    gosub printtemp
    
    
    printtemp:
         LCDOUT $fe, $c0, #TempTens, #TempUnits,".",#TempDecimals 
    return

  5. #5
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Sorry, the above code should be:

    Code:
    LCDOUT $fe, ($c0 + 4)    'moves cursor to 4th character position on bottom line
    gosub printtemp
    
    
    printtemp:
         LCDOUT #TempTens, #TempUnits,".",#TempDecimals  'remove line/cursor info 
    return
    Last edited by ScaleRobotics; - 28th April 2009 at 21:54.

  6. #6
    Join Date
    Aug 2007
    Location
    Mississauga, Ontario, Canada
    Posts
    29


    Did you find this post helpful? Yes | No

    Default

    You know... you might have something going here. I'll explore this option as well.

    Now that I think of it, the original way might work as well. I'm just worried about the size of the program (trying to fit everything on a F628) but now that I think about it, just because a variable looks long and messy on the Microcode screen, doesn't mean it will take that much space on a chip, right?


  7. #7
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    That's right, looks can be deceiving.

    I did a couple tests with Darrel's "How much code could a code hog ...." thread at
    http://www.picbasic.co.uk/forum/showthread.php?t=2418
    This was done with a 18F chip:

    it turns out that both lines use the same amount of space:
    Code:
    Lcdout $fe, ($c0 +4),"98.7"
    
    LCDOUT $fe, ($c0 +4), #TempTens, #TempUnits,".",#TempDecimals
    And, if you use the gosub (in post #5) 3 times, rather than use the above line (three times), you will use about 2/3 the code space. And that's not considering forming the data into a string.
    Last edited by ScaleRobotics; - 29th April 2009 at 01:51.

  8. #8
    Join Date
    Aug 2007
    Location
    Mississauga, Ontario, Canada
    Posts
    29


    Did you find this post helpful? Yes | No

    Default

    Good stuff. Thank you for running the tests for me.
    Looks like I'll have to go with the original plan as you have suggested.
    No worries... I simply thought there would be a different way of doing it but I'll just have to get creative here and make efficient use of code space.

    Thank you very much for all your help.

Similar Threads

  1. WRITECODE stores wrong 14-bit word values in FlashMEM
    By BobPigford in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 26th June 2009, 05:35
  2. SLOW Serin2 and Serout2
    By dragons_fire in forum General
    Replies: 3
    Last Post: - 26th June 2009, 03:38
  3. Displaying messages with only 7 (or 4) LEDs on a stick...
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 20th May 2007, 09:35
  4. Gps with 16f628
    By dragons_fire in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 8th June 2006, 04:38
  5. reading, writing, and displaying from eeprom
    By Rhatidbwoy in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th January 2006, 23:05

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts