Can we suppress leading zero's in LCDOUT?


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2009
    Posts
    19

    Default Can we suppress leading zero's in LCDOUT?

    I'm trying to print a value in a BYTE sized VAR to a specific place on the LCD.
    (a standard 16x2, and using DT's Anypin.php)

    I need to get the number right-justified and w/o leading zero's.

    I currently have a 0-255 number comming from the ADC on AN0.

    (later I will need to do some math and expand the the result to Xnum-per-mV)

    I'm currently doing something like this:

    Code:
    MYNUMBER VAR BYTE
    MYNUMBER = 0
    ...
    ADCIN 0, MYNUMBER
    ...
    LCDOUT $FE, $83, DEC MYNUMBER
    and it prints out "127 " instead of " 127" on the LCD.

    My number needs to be printed before (in front of) some text that remains on the LCD during these numeric updates, like " 127-Dingles".

    I tried DEC5 and get the digits in the right place but they have leading zero's (instead of spaces)

    Is there a way to format my number right-justified and suppress the leading zero's?
    Last edited by PICn-It; - 16th December 2009 at 00:14.

  2. #2


    Did you find this post helpful? Yes | No

    Default this may help

    Hi there
    Just thought this may help you a little more...

    [HTML]http://www.emesystems.com/BS2math4.htm[/HTML]

    Good luck :-)

    Dennis

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hi PICn-It,
    From your code:
    Code:
    LCDOUT $FE, $83, DEC MYNUMBER
    make it so
    LCDOUT $FE, $83, DEC MYNUMBER,"-Dingles"
    EDIT: I see what you are doing now, have not tried this but . . .
    LCDOUT $FE, $80, DEC MYNUMBER, $84,"Dingles"
    DEC automaticaly supresses leading zeros unless followed by a number
    Last edited by Archangel; - 16th December 2009 at 06:34.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  4. #4
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by PICn-It View Post
    I'm trying to print a value in a BYTE sized VAR to a specific place on the LCD.
    (a standard 16x2, and using DT's Anypin.php)

    I need to get the number right-justified and w/o leading zero's.

    I currently have a 0-255 number comming from the ADC on AN0.

    (later I will need to do some math and expand the the result to Xnum-per-mV)

    I'm currently doing something like this:

    Code:
    MYNUMBER VAR BYTE
    MYNUMBER = 0
    ...
    ADCIN 0, MYNUMBER
    ...
    LCDOUT $FE, $83, DEC MYNUMBER
    and it prints out "127 " instead of " 127" on the LCD.

    My number needs to be printed before (in front of) some text that remains on the LCD during these numeric updates, like " 127-Dingles".

    I tried DEC5 and get the digits in the right place but they have leading zero's (instead of spaces)

    Is there a way to format my number right-justified and suppress the leading zero's?

    At my best guess, this is what you are asking.

    You need the print always to the right.

    Code:
    <font color="#000000">MYNUMBER <font color="#000080"><b>VAR BYTE
    </b></font>MYNUMBER = <font color="#FF0000">0
    
    </font><font color="#000080"><b>ADCIN </b></font><font color="#FF0000">0</font>, MYNUMBER
    
    
    <font color="#000080"><b>LCDOUT </b></font><font color="#FF0000">$FE</font>, <font color="#FF0000">$83
    
    
    </font><font color="#000080"><b>IF </b></font>MYNUMBER &gt; <font color="#FF0000">99 </font><font color="#000080"><b>THEN 
        LCDOUT DEC3 </b></font>MYNUMBER <font color="#000080"><i>' three digits + &quot;-Dingles&quot;
    
        </i><b>ELSE 
           IF </b></font>MYNUMBER &gt; <font color="#FF0000">9  </font><font color="#000080"><b>THEN    </b><i>' one space + two digits + &quot;-Dingles&quot;
              </i><b>LCDOUT </b></font><font color="#008000">&quot; &quot;</font>, MYNUMBER
       
              <font color="#000080"><b>ELSE
                 LCDOUT </b></font><font color="#008000">&quot;  &quot;</font>,<font color="#000080"><b>DEC1 </b></font>MYNUMBER   <font color="#000080"><i>' two spaces + one digit + &quot;-Dingles&quot;
    
           </i><b>ENDIF
    ENDIF
    
    LCDOUT </b></font><font color="#008000">&quot;-Dingles&quot;
    
    
    
    
    
    
    </font>
    Last edited by sayzer; - 16th December 2009 at 08:13.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  5. #5
    Join Date
    Nov 2009
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer View Post
    At my best guess, this is what you are asking.

    You need the print always to the right.

    Code:
    <font color="#000000">MYNUMBER <font color="#000080"><b>VAR BYTE
    </b></font>MYNUMBER = <font color="#FF0000">0
    
    </font><font color="#000080"><b>ADCIN </b></font><font color="#FF0000">0</font>, MYNUMBER
    
    
    <font color="#000080"><b>LCDOUT </b></font><font color="#FF0000">$FE</font>, <font color="#FF0000">$83
    
    
    </font><font color="#000080"><b>IF </b></font>MYNUMBER &gt; <font color="#FF0000">99 </font><font color="#000080"><b>THEN 
        LCDOUT DEC3 </b></font>MYNUMBER <font color="#000080"><i>' three digits + &quot;-Dingles&quot;
    
        </i><b>ELSE 
           IF </b></font>MYNUMBER &gt; <font color="#FF0000">9  </font><font color="#000080"><b>THEN    </b><i>' one space + two digits + &quot;-Dingles&quot;
              </i><b>LCDOUT </b></font><font color="#008000">&quot; &quot;</font>, MYNUMBER
       
              <font color="#000080"><b>ELSE
                 LCDOUT </b></font><font color="#008000">&quot;  &quot;</font>,<font color="#000080"><b>DEC1 </b></font>MYNUMBER   <font color="#000080"><i>' two spaces + one digit + &quot;-Dingles&quot;
    
           </i><b>ENDIF
    ENDIF
    
    LCDOUT </b></font><font color="#008000">&quot;-Dingles&quot;
    
    
    
    
    
    
    </font>
    Ahh, I see. I was hoping there would be some compiler directive/keyword/function-switch to use in PBP, something like printf in C but this is fine, whatever works ...right?.

    Since I need a posible 5-digit number perhaps turning the IF/THEN into a CASE statement would work here? something like this:

    Code:
    MYNUMBER VAR BYTE
    MYNUMBER = 0
    ...
    ADCIN 0, MYNUMBER
    ...
    ...
    SELECT CASE MYNUMBER
    
           CASE IS > 9999
                LCDOUT $FE, $83, DEC5 MYNUMBER          ' 5 digits
           CASE IS > 999
                LCDOUT $FE, $83, " ", DEC4 MYNUMBER     ' 1 space and 4 digits
           CASE IS > 99
                LCDOUT $FE, $83, "  ", DEC3 MYNUMBER    ' 2 spaces and 3 digits
           CASE IS > 9
                LCDOUT $FE, $83, "   ", DEC2 MYNUMBER   ' 3 spaces and 2 digits
           CASE ELSE
                LCDOUT $FE, $83, "    ", DEC1 MYNUMBER  ' 4 spaces and 1 digit
    END SELECT
    Thanks for response
    Last edited by PICn-It; - 16th December 2009 at 15:42.

  6. #6
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    PICn-It,

    MYNUMBER VAR BYTE


    With that, you can get max. 255.

    ----------------------------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  7. #7
    Join Date
    Nov 2009
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer View Post
    PICn-It,

    MYNUMBER VAR BYTE


    With that, you can get max. 255.

    ----------------------------------------------
    Yes, good catch.

    In my code, currently I can't figure out how to steady up the 10-bit ADC reading, so I temporarily REM'd those lines:
    Code:
    ADC_BITS 10
    MYNUMBER VAR WORD
    and temporarily put in:
    Code:
    ADC_BITS 8
    MYNUMBER VAR BYTE
    while I work out the display screens and presentation. The CASE statement based on your IF/THEN code posted above seems to work great, thank you.
    Last edited by PICn-It; - 16th December 2009 at 16:11.

Similar Threads

  1. Timer + rc5
    By naga in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 19th November 2009, 07:56
  2. Suppress leading zeros
    By Adrian in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 24th June 2008, 21:45
  3. Help GPS read with serin
    By leinske in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 5th September 2007, 02:33
  4. Crystalfontz LCD
    By jman12 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 9th February 2007, 15:04
  5. having problems with Hantronix 20x4 lcd
    By Rhatidbwoy in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 22nd December 2005, 12:22

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