LCD BARgraphs


Closed Thread
Results 1 to 40 of 233

Thread: LCD BARgraphs

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default LCD BARgraphs

    LCD BARgraphs
    LCDbar_INC.bas
    is an Include file that makes it easy to create BARgraphs on your LCD display.

    Features:
    • Can be placed anywhere on the screen.
    • Can be any width (whole characters)
    • Can be scaled anywhere between 0 and 32768.
    • Three styles to choose from.  {lines, boxed, blocks}
    • Just 1 Command does it all. (Well, sort of)
    Click here for Larger Video (225kbps)


    Code:
    @   BARgraph   Value, Row, Col, Width, Range, Style  
      
    Value: The Value of the BARgraph  (0 to Range).If Range = 100 and Value is 50, then            
              half of the BARgraph will be filled in.   Value MUST be a WORD sized variable¹  
    
    Row: LCD Row to place the BARgraph (1 to 4)   can be either a constant or a  
              variable¹.  
    
    Col: LCD Column to place the BARgraph (0 to LCDsize² - 1)   can be either a constant  
              or a variable¹. 
    
    Width: Width of the BARgraph in charaters. (1 to LCDsize²)   can be either a constant  
              or a variable¹. 
    
    Range: The "full-scale" range of the BARgraph  (0 to 32768) MUST be a constant.  
              Variables will not work here. 
    
    Style: Selects which Style will be used for the BARgraph  (lines, boxed, blocks)   can  
              be either a constant or a variable¹.  
    
    Note ¹ - Variables must be preceeded with a 
                 underscore.   ie.  _Temperature    
    Note ² - LCDsize is the number of Chars in 1 line of 
                 the LCD, for "4x16" it's 16
    Added 10/18/05 - If using a 4x20 display, you can use this define to let the program know the addressing is different.   Thanks, CocaColaKid!
    Code:
    DEFINE  LCD4X20  1
    Attached Files Attached Files
    Last edited by mackrackit; - 15th September 2011 at 09:08.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default How to use LCDbar_INC.bas

    This is so simple to use.

    Here's an example of a BARgraph that follows an A/D input.




    Code:
    ; Initialize your hardware and LCD first.
    
    DEFINE ADC_BITS 8               ' Number of bits in ADCIN result
    ADCON1.7 = 1                    ' Right Justify AD result
    
    INCLUDE "LCDbar_INC.bas"        ' Include the BARgraph routines
    
    Value  VAR  WORD                ' Must be a WORD even though AD is 8bit
    
    LCDOUT $FE, 1  ' Clear Screen
    
    Loop1:
        ADCIN  0, Value
        LCDOUT $FE,2,"Value=",DEC Value,"   "
        ; syntax- BARgraph   Value, Row, Col, Width, Range, Style
        @         BARgraph  _Value,   2,   0,    16,   255,  lines
    GOTO Loop1
    
    Attached Files Attached Files
    Last edited by mackrackit; - 15th September 2011 at 09:16.
    DT

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Another example

    This is just like the previous example except that it places both the Value and the BAR on the same line.


    Code:
    ; Initialize your hardware and LCD first.
    
    DEFINE ADC_BITS 8               ' Number of bits in ADCIN result
    ADCON1.7 = 1                    ' Right Justify AD result
    
    INCLUDE "LCDbar_INC.bas"        ' Include the BARgraph routines
    
    Value  VAR  WORD                ' Must be a WORD even though AD is 8bit
    
    LCDOUT $FE, 1  ' Clear Screen
    
    Loop1:
        ADCIN  0, Value
        LCDOUT $FE,2,DEC Value," "
        ; syntax- BARgraph   Value, Row, Col, Width, Range, Style
        @         BARgraph  _Value,   1,   4,    12,   255,  lines
    GOTO Loop1
    
    Last edited by mackrackit; - 15th September 2011 at 09:25.
    DT

  4. #4
    Join Date
    May 2004
    Posts
    30


    Did you find this post helpful? Yes | No

    Default

    Very good job, Darrel ! I like very much ! But you forget the "vertical bargraph" !

    Don Mario

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Talking

    Quote Originally Posted by Don Mario
    Very good job, Darrel ! I like very much ! But you forget the "vertical bargraph" !

    Don Mario
    Hi, DON

    Just turn your LCD 90° cckw !!!

    hi,hi,hi ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6
    Join Date
    May 2004
    Posts
    30


    Did you find this post helpful? Yes | No

    Default

    Thanks ! It's a very good advice ! But I'm seriuos ! Don't forget the vertical bar !

    Don Mario

  7. #7
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: LCD BARgraphs

    Quote Originally Posted by Acetronics View Post
    Hi, DON
    Just turn your LCD 90° cckw !!!
    Alain
    Did a vertical graphing tachometer over time with a single custom char (far right in the video).



    Just got to matrix rotate the byte and shift every byte in the custom char every frame to make room for the next vertical byte.
    (this one has odometer effect on the elapsed timer as well

  8. #8
    vbcoder's Avatar
    vbcoder Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks Darrel. It gives me an amazing look for my project. Can you tell me if I use 2x16 Alpha LCD. How many bars that I can get per line?

  9. #9
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi vbcoder,

    You're welcome.

    There are 3 bars per character, so you can get 48 per line on a 2x16.
    <br>
    DT

  10. #10
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Question aren't characters in a 5x7 Matrix arranged ???

    Quote Originally Posted by Darrel Taylor View Post
    Hi vbcoder,

    You're welcome.

    There are 3 bars per character, so you can get 48 per line on a 2x16.
    <br>

    Hi, Darrel

    I know it's YOUR Bargraph example ... but 5 bars can be used with "general programming" ...

    May be a Typo from yours ???



    Translated and modified from a Stamp application :

    ' This program generates a horizontal bargraph
    ' with a 2x16 Intelligent LCD Display HD 44780 / KS 0062.

    DEFINE OSC 20
    DEFINE LCD_EBIT 1

    Led var Portb.5
    Scale var Portb.2

    ' ** Variables **

    BarVal Var Word ' Value to be graphed.
    Bars Var Byte ' Number of full |||/||||| bars to draw.
    Balance Var Byte ' Balance left after all |||/|||||s are drawn.
    Padding Var Byte ' Number of spaces to fill width.
    Balf Var Byte ' Is a 'Balance' character needed? (1=yes, 0=no).
    Temp Var Byte
    Fullbar Var Byte
    Maxbar Var Byte


    ' ** Constants **

    BWdth Con 16
    Basebar Con 0 ' ASCII value of 0 bar (blank).





    IF NOT Scale THEN

    Fullbar = 3
    ELSE
    Fullbar = 5

    ENDIF

    Maxbar = BWdth*Fullbar ' Max bar counts.



    ' Transfer the bit patterns that make up the bars into the LCD's CGRAM.
    ' The vertical bars are made up of 8 identical bit patterns

    ' A | bar consists of 0, 5 times $10, 0
    ' A || bar consists of 0, 5 times $14, 0
    ' A ||| bar consists of 0, 5 times $15, 0

    ' We repeat each pattern 8 times.

    IF Fullbar = 3 THEN

    Lcdout $FE,64,0,0,0,0,0,0,0,0 'Motif 0
    Lcdout $0,$10,$10,$10,$10,$10,$10,$0 'Motif 1
    Lcdout $0,$14,$14,$14,$14,$14,$14,$0 'Motif 2
    Lcdout $0,$15,$15,$15,$15,$15,$15,$0 'Motif 3


    ELSE


    Lcdout $FE,64,0,0,0,0,0,0,0,0 'Motif 0
    Lcdout $0,$10,$10,$10,$10,$10,$10,$0 'Motif 1
    Lcdout $0,$18,$18,$18,$18,$18,$18,$0 'Motif 2
    Lcdout $0,$1C,$1C,$1C,$1C,$1C,$1C,$0 'Motif 3
    Lcdout $0,$1E,$1E,$1E,$1E,$1E,$1E,$0 'Motif 4
    Lcdout $0,$1F,$1F,$1F,$1F,$1F,$1F,$0 'Motif 5

    ENDIF

    Goto OverBargraph


    ' The value in 'Bar_Val' is displayed as a horizontal bar graph
    ' from the current cursor location with a total width (in characters) set by the WIDTH constant.
    ' Each character position can represent a maximum value of 3/5 using the Fullbar character |||.
    ' The routine calculates how many full bars to use by dividing by 3/5.
    ' If there is a remainder after dividing by 3/5, the routine joins on a partial-bar character
    ' ( | or || or ||| or |||| or ||||| ) to represent the balance.
    ' Then it pads out the remainder of the bar width with spaces to erase any leftover bars



    Bargraph:

    Bars = (BarVal min MaxBar) / Fullbar ' One full bar for each 3/5 graph units.
    Balance = (BarVal min Maxbar) //Fullbar ' Balance is the remainder after a division by 3/5.
    Balf = Balance min 1
    Padding = BWdth - (Bars + Balf) ' Number of spaces to fill bar width.

    LCDOut Rep Fullbar\Bars,Rep (Balance + Basebar)\Balf,Rep " " \Padding

    Return

    OverBargraph:

    For BarVal = 0 to Maxbar

    Lcdout $FE,$80
    Gosub Bargraph
    Lcdout $FE, $C0, #BarVal," "
    Pause 300

    Next BarVal



    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  11. #11
    Join Date
    Jun 2007
    Location
    TÜRKİYE
    Posts
    3


    Did you find this post helpful? Yes | No

    Smile Thank

    gerçekten güzel uygulama teşekkür ediyorum.

    [email protected]

    TÜRKİYE

  12. #12
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  13. #13
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Me neither!

    But I did catch the "Thank" part.
    So in case that's what it was...

    You're welcome zaferakbay.
    Hope you get good use out of it.
    <br>
    DT

  14. #14
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Ok let's try in split words..
    gerçekten = Actually, honestly,indeed, literrally, positively,properly,really,simply, truly

    güzel = attractive beautiful, bonny, bracing, cherub,comely,dreamy,elegant,enjoyable,fair,fine,g allant,glorious,graceful,grand,handsome,lovely,nic e...

    uygulama = application, execution,implementation,practice

    teşekkür = *** can't be found *****

    ediyorum = *** can't be found ****
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  15. #15
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    hmmm,

    positively glorious application
    properly elegant implementation
    honestly beautiful execution
    really dreamy practice

    Hey, works for me

    As long as those last 2 words aren't
    Stink, Pile or S___
    <br>
    DT

  16. #16
    ciberman37's Avatar
    ciberman37 Guest


    Did you find this post helpful? Yes | No

    Default error in LCDbar.inc.bas

    The compiler signalise error in line 29, no is alabel?


  17. #17
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Line 29 is GOTO overBAR, and overBAR: is the last line in the include file.

    Check the end of the file and make sure overBAR is there. If not, you may have received a partial download. Try downloading it again.
    <br>
    DT

  18. #18
    Join Date
    Sep 2008
    Location
    Stockholm
    Posts
    80


    Did you find this post helpful? Yes | No

    Default

    What kind of licence did u put on your code Darrel ?

    I currently making a little project for a contest in a swedish electronics forum, and I really would like to use a LCD bargraph, and the rules states that I only can use includes that are "GPL or more free.", can I use this, or do I have to write something much more ugly myself ?

  19. #19
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Glenn View Post
    What kind of licence did u put on your code Darrel ?
    As long as you don't say you wrote it ... you can do whatever you want with it.

    For Free!
    <br>
    DT

  20. #20
    Join Date
    Jan 2009
    Posts
    4


    Did you find this post helpful? Yes | No

    Default

    Hi darrel.. Really nice work.Congrats.
    I intend to write lcd bar vu-meter and bar voltmeter codes. I did for voltmeter but not for bar vu-meter. And I need help for this. MCU is 16f876 and 2x16 lcd.. I need some help to convert reading from frequency to the bars. Can you help me ?

Similar Threads

  1. Is this code not initialising the LCD properly?
    By Platypus in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 30th January 2010, 19:14
  2. 16f688 LCD what have I done wrong
    By spitfiredriver in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 8th August 2009, 19:54
  3. Play with LCD on PICDEM
    By The IceMan in forum mel PIC BASIC
    Replies: 5
    Last Post: - 22nd August 2008, 16:56
  4. Need help with LCD number display.
    By Steve Matson in forum mel PIC BASIC
    Replies: 8
    Last Post: - 26th June 2007, 23:07
  5. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30

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