LCD Bargraph

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)
@   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

If using a 4x20 display, you can use this define to let the program know the addressing is different. * Thanks, CocaColaKid!

DEFINE  LCD4X20  1

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

; 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

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

; 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

Files to Download:Files to download:
LCD_Bar_INC
LCD_Bar_Demo_AD
LCD_Bar_Demo_2

Page last modified on March 05, 2018, at 09:29 PM