Need advice with LCD 2x16


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    574

    Default Need advice with LCD 2x16

    Hi again ! For the start I want to thank you all for helping me so many times ! It's a great forum this one ! All my good thoughts for each of you !
    I made for one friend one thermometer, with two DS18B20 and LCD 2x16 display.
    I search all over the forum but I don't find the answer : how can I keep the value on display in the same position, even the number of characters change, from 3 (18,7) to 2 (9,4) ? I want to keep both temperatures value on same column. Hope the picture help to understand...
    Now I use this command for display :
    Code:
    LcdOut $FE, $80, "IN  :  ", Sign1," ", DEC (Temperature1 / 100), ".", DEC Temperature1 dig 1, " ",223,"C " 
    LcdOut $FE, $C0, "OUT :  ", Sign2," ", DEC (Temperature2 / 100), ".", DEC Temperature2 DIG 1, " ",223,"C "
    Thanks in advance !Name:  lcd_2x16.jpg
Views: 1488
Size:  103.2 KB

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Need advice with LCD 2x16

    From the manual
    Note that there is a command to move the cursor to the beginning of the second line of a 2-line display. For most LCDs, the displayed characters and lines are not consecutive in display memory - there can be a break in between locations. For most 16x2 displays, the first line starts at $0 and the second line starts at $40. The command:
    LCDOUT $FE, $80 + 4
    sets the display to start writing characters at the forth position of the first line. 16x1 displays are usually formatted as 8x2 displays with a break between the memory locations for the first and second 8 characters. 4- line displays also have a mixed up memory map, as shown in the table above.
    So set the "static" text to start where you want it and let the VARs follow.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    574


    Did you find this post helpful? Yes | No

    Default Re: Need advice with LCD 2x16

    Thanks for reply !
    I made this change :
    Code:
    LcdOut $FE, $C0, "OUT :  ", Sign2," "
    LcdOut $FE, $C0 + 9, DEC (Temperature2 / 100), ".", DEC Temperature2 DIG 1, " ",223,"C "
    and the position of first character of second temperature don't move. But I want to keep the position of the last character ; maintaining the alignment to the right !
    Attached Images Attached Images  

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Need advice with LCD 2x16

    You could add a leading zero if the value is less than 10 or if the value is less than 10 the position is X else the position is Y.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    574


    Did you find this post helpful? Yes | No

    Default Re: Need advice with LCD 2x16

    Quote Originally Posted by mackrackit View Post
    ... if the value is less than 10 the position is X else the position is Y.
    I think this is the answer ! I will try.

  6. #6
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    574


    Did you find this post helpful? Yes | No

    Default Re: Need advice with LCD 2x16

    I use this code :
    Code:
     OWIn DQ2, 2, [temperature2.byte0, temperature2.byte1]  
    
    If Temperature2.15 then       
      Temperature2= ~Temperature2 +1
      Twist2 = 1
    Endif
     
    Dummy2 = 625 * Temperature2
    TempC2 = DIV32 10 
    TempC2 = (Temperature2 & $7FF) >> 4
    Float2 = ((Temperature2.Lowbyte & $0F ) * 25 )>>2
    Temperature2 = TempC2*100 + Float2
    
    If Twist2 then
      V2= 10000 - Temperature2               
      Twist2 = 0
     else
      V2= 10000 + Temperature2
    EndIf
    
    If V2 >= 10000 then                           
      Temperature2=V2-10000                   
     else                                   
      Temperature2=10000-V2                   
    EndIf
    How can I say "if temperature2 > 9.99 'C or temperature2 < -9.99 'C" ?

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Need advice with LCD 2x16

    Convert the temperature to an absolute value.
    From the manual
    4.17.4. ABS
    ABS returns the absolute value of a number. If a byte is greater than 127 (high bit set), ABS will return 256 - value. If a word is greater than 32767 (high bit set), ABS will return 65536 - value.
    B1 = ABS B0
    Then you are back to IF < 10.....Just remember your sign...
    Dave
    Always wear safety glasses while programming.

  8. #8
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    574


    Did you find this post helpful? Yes | No

    Default Yes !

    I have good results, based on this "$FE, $14 - Move cursor right one position" :
    Code:
    if (temperature2/100) =>10 then
    LcdOut $FE, $c0, "OUT :  ", Sign2," ", DEC (Temperature2 / 100), ".", DEC Temperature2 dig 1, " ",223,"C " 
    else
    LcdOut $FE, $C0, "OUT :  ", Sign2," ", $14, DEC (Temperature2 / 100), ".", DEC Temperature2 dig 1, " ",223,"C " 
    endif
    Thanks !!!

  9. #9
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default Re: Need advice with LCD 2x16

    If you wanted to move over an extra character to maintain alignment, why not just add an extra blank after SIGN2?

    Code:
     
    if (temperature2/100) =>10 then
    LcdOut $FE, $c0, "OUT : ", Sign2," ", DEC (Temperature2 / 100), ".", DEC Temperature2 dig 1, " ",223,"C " 
    else
    LcdOut $FE, $C0, "OUT : ", Sign2,"  ", DEC (Temperature2 / 100), ".", DEC Temperature2 dig 1, " ",223,"C " 
    endif
    Moving the cursor can give misleading information unless you clear the display first. $C0 sets the cursor position to the beginning of the 2nd line, it does not erase what was written previously.

    Let's say it is displaying 25C and the reading changes to 7C. If you move over 1 position, the 2 will still be there, giving 27C.
    Last edited by Demon; - 26th April 2011 at 07:17. Reason: Cause the code alignment gets all messed up when I clicked POST
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  10. #10
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    574


    Did you find this post helpful? Yes | No

    Default Re: Need advice with LCD 2x16

    Thank you !
    I try my code in ISIS and work ok ; it' possible, in 'real life' to work bad...but I do not have -yet- the hardware.
    Please remove .txt from simulation file.
    Attached Files Attached Files

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