LCDOUT command followed by variable data


+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    961

    Default LCDOUT command followed by variable data

    Hi,

    This must be recurrent subject but/and I can't recall how to handle this.

    My project is about displaying time and adapting the output format to the number of digits to display adjusting mainly the number of spaces.

    Since each LCDOUT command is 47 WORDs heavy, I'd like to avoid having to repeat this command all over my program.

    This is a piece of my current code where one can see that I need to repeat the LCDOUT command often to fit the placement of characters.

    Code:
    ' Display time in "0:00:00" format
    IF Hours > 0 THEN    ' " 0:00:00"
        LCDOUT $FE,$2," ",DEC Hours,":",DEC2 Minutes,":",DEC2 Seconds
        RETURN
    ENDIF
    
    IF Minutes > 9 THEN ' "   00:00"
        IF LapDisplay THEN 'Lap is displayed
            IF Lap > 9 THEN 'Lap is 2 characters wide
                LCDOUT $FE,2,DEC2 Lap," ",DEC Minutes,":",DEC2 Seconds
            ELSE 'Lap is 1 character wide
                LCDOUT $FE,2,DEC1 Lap,"  ",DEC Minutes,":",DEC2 Seconds
            ENDIF
        ELSE 'no Lap display
            LCDOUT $FE,2,"   ",DEC Minutes,":",DEC2 Seconds
        ENDIF
        RETURN
    ENDIF
    
    IF Minutes >= 0 THEN    ' "    0:00"
        IF LapDisplay THEN
            IF Lap > 9 THEN
                LCDOUT $FE,2,DEC2 Lap,"  ",DEC Minutes,":",DEC2 Seconds
            ELSE
                LCDOUT $FE,2,DEC1 Lap,"   ",DEC Minutes,":",DEC2 Seconds
            ENDIF
        ELSE
            LCDOUT $FE,2,"    ",DEC Minutes,":",DEC2 Seconds
        ENDIF
        RETURN
    ENDIF

    How can I set a number of SPACEs by the mean of a variable?

    Is there another way to achieve this?
    Roger

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,716


    Did you find this post helpful? Yes | No

    Default Re: LCDOUT command followed by variable data

    I assume you are trying to achieve something like this where the minutes/seconds remain at a fixed location regardless of the other formatted field widths in either lap mode or not
    Name:  Screenshot 2026-03-12 154522.png
Views: 3
Size:  26.8 KB

    its quite simple if you use a frame buffer for the lcd line and designate a frame address for each element to show, the fixed elements [that never change] can be set once off at code startup. you then just need to update each changeable element according to the rules/mode that currently apply when necessary. the display is updated from the buffer when necessary. its not only much faster it uses considerably less code space


    Code:
           LCDBUFF VAR BYTE[12]
           lsecD0 var byte ext
           lminD0 var byte ext
           lhrsD0 var byte ext
           lapdD0 var byte ext
           lsecD1 var byte ext
           lminD1 var byte ext
           lhrsD1 var byte ext
           lapdD1 var byte ext
           LapDisplay VAR BYTE
           Lap VAR BYTE
     clear
    
    
    asm
    lsecD1 =  _LCDBUFF + 8
    lsecD0 =  _LCDBUFF + 9
    lminD1 =  _LCDBUFF + 5
    lminD0 =  _LCDBUFF + 6
    lhrsD0 =  _LCDBUFF + 3
    lhrsD1 =  _LCDBUFF + 4
    lapdD1 =  _LCDBUFF
    lapdD0 =  _LCDBUFF + 1
    endasm
        arraywrite LCDBUFF,["LL h:mm:ss",0]
        GOSUB ResetTime
        GOSUB StartTimer
        GOSUB update
        pause 2000  
        hserout [ "Ready",13,10]  
        Minutes = 8
        LapDisplay = 0
        Seconds = 55
        hours = 9
    
    
    
    
    main:
        IF MinutesChanged THEN  
        LapDisplay =   !LapDisplay 
        MinutesChanged =0
        ENDIF 
        IF SecondsChanged THEN     
            lap=lap+1
            led=!led
            GOSUB update
            LCDout $FE,2, str LCDBUFF ;
            SecondsChanged = 0
        ENDIF
    goto main
       
       
    update:        
        lsecD1 = seconds dig 1 + "0"    ;leading zero
        lsecD0 = seconds dig 0 + "0"    
        lminD1 = Minutes dig 1 + "0"    ;leading zero
        lminD0 = Minutes dig 0 + "0"
        IF   LapDisplay THEN 
              if (lap dig 1 ) then           ;two digits left justify
                lapdD1 = lap dig 1 + "0"
                lapdD0 = lap dig 0 + "0"
              else                           ;one digits left justify
                lapdD1 = lap dig 0 + "0"
                lapdD0 = " " 
              endif
              lhrsD1 = " " 
              lhrsD0 = " " 
              IF   lminD1 == "0"  THEN   lminD1 = " " ;NO leading zero
        ELSE
              lhrsD1 = ":" 
              lhrsD0 = Hours dig 0 + "0"
              lapdD1 = " " 
              lapdD0 = " " 
        ENDIF
     return
    Warning I'm not a teacher

Similar Threads

  1. LCDOUT with a LONG Variable
    By MarkEngineer in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 16th January 2015, 17:31
  2. Newbie - LCDOUT command
    By SOTASOTA in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th December 2010, 00:45
  3. LCD without LCDOUT command
    By Josuetas in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 28th August 2007, 15:22
  4. LCDout Command causes Interrupt!!??
    By Tom Gonser in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 31st March 2005, 05:18
  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 : 2

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