Shop OBEX P1 Docs P2 Docs Learn Events
Move LCD Character - 27979 — Parallax Forums

Move LCD Character - 27979

JBWolfJBWolf Posts: 405
edited 2013-02-13 10:51 in Propeller 1
Hello,
I am interested in figuring out the easiest way to move a character on the LCD so I can insert another.
LCD = Parallax 4x20 LCD pn# 27979

I am using the DS1620 digital thermometer to get temperature data.
The result given back from the DS1620 is a 3-digit decimal. A typical value would be "792", which equals 79.2 degrees.
I need to place the decimal for aesthetic reasons.

I have found 2 ways to approach this...
1) Try to move the 3rd character on the LCD one position to the right.
2) Divide the variable by 10 to place a decimal point.

Here is my first attempt:
LCD.tx(17)                                      ' No Cursor Mode
LCD.tx(22)                                      ' Turn ON BackLight
LCD.tx(173)                                     ' Move to Center of LCD Screen
LCD.str(string("DegF ="))                       ' Display Text
  Repeat 
     Degrees := long[temperature]
     LCD.tx(180)                                ' Move to end of Text
     LCD.dec(Degrees)                           ' Display Temperature Data                  
     LCD.tx(182)                                ' Move to Second digit of temp data to place decimal
     LCD.tx(46)                                 ' ASCII Decimal
     waitcnt(clkfreq + cnt)

This code does not create the desired effect and instead erases the 2nd character.... ie 792 becomes 7.2
I have looked through the 'fullduplexserial.spin' and also the LCD manual, but cannot find a way to place the cursor so it moves characters.
If there is not a way to move characters using fullduplexserial, I assume FLOAT is the best way?
I read the propeller manual regarding the FLOAT command, however I did not find enough information to apply it for my needs.
This will be my first time using FLOAT.

Can someone help me with dividing the 'degrees' variable by 10 to place a decimal in the proper place?
I am using multiple cogs and pointers... cog0 launches cog1 & cog2 then monitors input buttons, cog1 monitors the DS1620 temperature probe and moves results to a LONG variable, cog2 runs the LCD and displays the temperature data.
cog2 copies the temperature data to a local variable for display with Degrees := long[temperature]... it is this local 'Degrees' variable I would like to divide by 10.

I appreciate any help :)

Comments

  • JBWolfJBWolf Posts: 405
    edited 2013-02-11 23:23
    Come to think of it.... I havent yet accounted for triple or single digit temperatures which will absolutely happen... absodefinutely.
    Which means if there isn't a way to back-space one position on the LCD and insert a character which pushes characters to the right... the only viable solution will be to divide by 10.
  • SRLMSRLM Posts: 5,045
    edited 2013-02-11 23:33
    I think option 2 is better. It allows for you to decouple your code from the particular display that you may have. Something like this would work:
    LCD.dec(Degrees/10)
    LCD.tx('.')
    LCD.dec(||Degrees//10)
    
  • JBWolfJBWolf Posts: 405
    edited 2013-02-11 23:35
    Wow interesting.... what does the || do? Are those 'blank' spaces that hop over characters?
    And what does // do?
  • JBWolfJBWolf Posts: 405
    edited 2013-02-11 23:41
    Wow again... it works perfectly!
    Can you please explain the || and // for me?
    I would like to understand for future references.

    Thanks so much for the very fast (and super simple) resolution! :)
  • SRLMSRLM Posts: 5,045
    edited 2013-02-11 23:52
    It's in the Propeller manual, but || is the absolute value operator, and // is the modulus (integer division remainder) operator.

    You need the absolute value in there, otherwise for negative numbers you get something like "-32.-5"
  • JBWolfJBWolf Posts: 405
    edited 2013-02-11 23:57
    Ah, Thanks again.
    The temp probe is outside.... in Wisconsin, negatives are in the repertoire.
  • JonnyMacJonnyMac Posts: 9,191
    edited 2013-02-13 09:44
    In order to keep numbers neatly aligned you'll want a right-justified decimal method -- I have that in my personal version of the serial LCD driver (see attached). You still need to do the division and modulus trick; like this
    lcd.rjdec(temp / 10, 4, " ")
      lcd.tx(".")
      lcd.hex(||temp // 10, 1)
    


    Notice the little trick at the end, too -- .hex is faster than .dec for single digits.
  • lonesocklonesock Posts: 917
    edited 2013-02-13 10:08
    JonnyMac wrote: »
    I...
    lcd.hex(||temp // 10, 1)
    
    Notice the little trick at the end, too -- .hex is faster than .dec for single digits.
    Faster still might be:
    lcd.tx( (||temp // 10) + "0" )
    
    Jonathan
  • JonnyMacJonnyMac Posts: 9,191
    edited 2013-02-13 10:51
    Faster still might be:
    Code:
    lcd.tx( (||temp // 10) + "0" )

    Yep!
Sign In or Register to comment.