Best ways to display leading zeros with LCDOUT?


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2013
    Posts
    1,078

    Default Best ways to display leading zeros with LCDOUT?

    Hello, sometimes it is needed to display defined number of zeros in front of variable, when using LCDOUT. So say when you have to display 15, you display 15, but when you have to display 7, you display 07
    In case of 2 digit variable it is quite easy:

    Code:
    IF X>=10 then Y=X DIG 1  
    ELSE
    Y=0
    ENDIF
    X= X DIG 0
    LCDOUT $FE, $C0, #Y, #X
    But what if I need to display 1-2-3-4 leading zeros?
    Add that many extra variables and handling routines?

  2. #2
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: Best ways to display leading zeros with LCDOUT?

    I create a buffer for the transmission. For example, I'm using a Nextion where if I wanted to display RPM, I name the Nextion Number object "rpm". To send it, ASCii characters "rpm.val=1234" then $FF, $FF, $FF. I create a NexBuf[16] VAR BYTE to hold each character byte.

    Here is my Send_RPM subroutine:
    Code:
    Send_RPM:                                       ;Send Current RPM Value to Nextion
        tRPM = RPM                                  ;Create a Temporary Variable We Can Modify
        ARRAYWRITE NexBuf,["rpm.val="]              ;Start Nextion Command Sequence, Occupies NexBuf[0] >> [7]
        IF tRPM > 1000 THEN                         ;If RPM is 4 Digits
            b0 = tRPM / 1000                        ;Get the Xxxx Value
            NexBuf[8] = b0 + $30                    ;Convert it to ASCii
            tRPM = tRPM - (b0 * 1000)               ;Subtract the Xxxx Value from tRPM
            IF tRPM < 100 THEN                      ;2nd Digit = 0
                NexBuf[9] = $30                     ;If New tRPM < 100, Add Zero Fill (ASCii)
                IF tRPM < 10 THEN                   ;3rd Digit = 0
                    NexBuf[10] = $30                ;If tRPM < 10, Add Zero Fill (ASCii)
                ENDIF                           ;IF tRPM < 10
            ENDIF                               ;IF tRPM < 100
        ELSE                                        ;tRPM < 1000
            NexBuf[8] = $30                         ;If tRPM < 1000, Xxxx = Zero (ASCii)
        ENDIF                                   ;IF tRPM > 1000
        IF tRPM > 100 THEN                          ;If RPM is 3 Digits
            b0 = tRPM / 100                         ;Get the xXxx Value
            NexBuf[9] = b0 + $30                    ;Convert it to ASCii
            tRPM = tRPM - (b0 * 100)                ;Subtract the xXxx Value from tRPM
            IF tRPM < 10 THEN                       ;3rd Digit = 0
                NexBuf[10] = $30                    ;If tRPM < 10, Add Zero Fill  (ASCii)
            ENDIF                               ;IF tRPM < 10
        ELSE                                        ;tRPM < 100
            NexBuf[9] = $30                         ;If tRPM < 100, it's Zero (ASCii)
        ENDIF                                   ;IF tRPM > 100
        IF tRPM > 10 THEN                           ;If RPM is 2 Digits
            b0 = tRPM / 10                          ;Get the xxXx Value
            NexBuf[10] = b0 + $30                   ;Convert it to ASCii
            tRPM = tRPM - (b0 * 10)                 ;Subtract the xxXx Value from tRPM
        ELSE                                        ;tRPM < 10
            NexBuf[10] = $30                        ;If tRPM < 10, it's Zero (ASCii)
        ENDIF                                   ;IF tRPM > 10
        NexBuf[11] = tRPM + $30                     ;Convert xxxX Value to ASCii & Add to Buffer                
        FOR b0 = 12 TO 14                           ;Generate "End of Message" Sequence: $FF, $FF, $FF
            NexBuf[b0] = $FF                        ;Load it to Buffer
        NEXT b0                                 ;FOR b0 = 12 TO 14
        NexBuf[15] = 0                              ;Tells Us To Turn UART TX INT Off
        RotX = 0                                    ;NexFlags.RotX -- Clear RotX Flag
        GOTO Start_TX                           ;No RETURN Needed, Using GOTO Command
    I'm using the UART TX Interrupt to keep feeding NexBuf through the pipeline (not LCDOOUT). But I hope this at least gives you some ideas.

  3. #3
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Best ways to display leading zeros with LCDOUT?

    Thanks, your code give me another idea - just create an array, write variable to via DIG, and read and display array in sequence, that should work imo...

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: Best ways to display leading zeros with LCDOUT?

    Why not use the DEC modifier on a word variable?

    For example if wVar=123 then DEC5 will display 00123 since it is padding zeros.

    Ioannis

  5. #5
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Best ways to display leading zeros with LCDOUT?

    Thanks, haven't thought about that

Similar Threads

  1. Winstar OLED Display Problem with lcdout comands
    By bubbleless in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 31st December 2019, 06:53
  2. VFD Display Brightness & Lcdout
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 28th August 2016, 11:09
  3. Can we suppress leading zero's in LCDOUT?
    By PICn-It in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 16th December 2009, 17:09
  4. Suppress leading zeros
    By Adrian in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 24th June 2008, 22:45
  5. LCDout Command w/ LCD 4x40 display
    By beto in forum mel PIC BASIC Pro
    Replies: 25
    Last Post: - 21st January 2005, 02: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