Code:
'****************************************************************
'* Creates a variable sized BAR-graph anywhere on the screen *
'****************************************************************
'* Name : LCDbar_INC_MOD2.bas *
'* Author : Darrel Taylor *
'* Notice : Copyright (c) 2005 *
'* Date : 9/8/2005 *
'* Version : 1.0 *
'* Notes : Maximum Range is 32768 *
'* : Range must always be a Constant *
'* : Value must always be a WORD variable *
'* : *
'* Modified : By SteveB on 11/23/2012 *
'* : The original include has been modified to *
'* : accomodate a flaw in Newhaven OLEDs firmware. *
'* : By using the define below, it will adjust the *
'* : custom CGRAM character locations used to 1-3 *
'* : (vs. 0-2). *
'* : *
'* : If using a flawed Newhaven Display add the *
'* : following define statement: *
'* : *
'* : DEFINE NEWHAVEN_DISPLAY 1 *
'* : *
'* Modified : By SteveB on 11/27/2012 *
'* : This modification introduces the ability to *
'* : display the bargraph from Right-to-Left. *
'* : *
'****************************************************************;
;@ BARgraph Value, Row, Col, Width, Range, Style, RtoL
;
;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ą.
;
;RtoL: MUST be a constant
; When set to 0, Bar will display Left-to-Right
; When set to 1, Bar will display Right-to-Left
;
;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
; ; default
BAR_width VAR BYTE : BAR_width = 16 ; Width of the BARgraph 16
BAR_range VAR WORD : BAR_range = 100 ; Range of Values (0-100) 100
BAR_row VAR BYTE : BAR_row = 1 ; Row location (1-4) 1
BAR_col VAR BYTE : BAR_col = 0 ; Column location (0-15) 0
BAR_value VAR WORD : BAR_value = 0 ; Current BAR value 0
BAR_style VAR BYTE : BAR_style = 1 ; 1=lines, 2=boxed, 3=blocks 1
BAR_RtoL VAR BYTE : BAR_RtoL = 0
; --- Temporary vars ----
BARtemp VAR WORD
Remainder VAR WORD
BARloop VAR BYTE
LastCharset VAR BYTE : LastCharset = 0
LastRtoL VAR BYTE : LastRtoL = 0
Limit1 VAR WORD
GOTO overBAR ; Skip over Subroutines
ThreeBARS CON EXT ; Identify the Custom Characters
TwoBARS CON EXT
OneBAR CON EXT
CharLoc3 CON EXT
CharLoc2 CON EXT
CharLoc1 CON EXT
ASM
ifdef NEWHAVEN_DISPLAY
ThreeBARS = 1
TwoBARS = 2
OneBAR = 3
else
ThreeBARS = 0
TwoBARS = 1
OneBAR = 2
endif
CharLoc3 = 40h +(ThreeBARS*8)
CharLoc2 = 40h +(TwoBARS*8)
CharLoc1 = 40h +(OneBAR*8)
lines = 0x10000001 ; Define the Styles
boxed = 0x10000002
blocks = 0x10000003
ENDASM
; --- lines Style custom chars ----
CharsetLines:
LCDOut $FE,CharLoc3,REP $15\9 ; Custom char 3 lines |||
IF BAR_Rtol = 0 THEN
LCDOut $FE,CharLoc2,REP $14\9 ; Custom char 2 lines ||
LCDOut $FE,CharLoc1,REP $10\9 ; Custom char 1 line |
ELSE
LCDOut $FE,CharLoc2,REP $05\9 ; Custom char 2 lines ||
LCDOut $FE,CharLoc1,REP $01\9 ; Custom char 1 line |
ENDIF
RETURN
; --- boxed Style custom chars ----
CharsetBoxed:
LCDOut $FE,CharLoc3,$1F,REP $15\7,$1F ; III
IF BAR_Rtol = 0 THEN
LCDOut $FE,CharLoc2,$1C,REP $14\7,$1C ; II
LCDOut $FE,CharLoc1,REP $10\9 ; I
ELSE
LCDOut $FE,CharLoc2,$07,REP $05\7,$07 ; II
LCDOut $FE,CharLoc1,REP $01\9 ; I
ENDIF
RETURN
; --- blocks Style custom chars ----
CharsetBlocks:
LCDOut $FE,CharLoc3,REP $1F\9
IF BAR_Rtol = 0 THEN
LCDOut $FE,CharLoc2,REP $1C\9
LCDOut $FE,CharLoc1,REP $10\9
ELSE
LCDOut $FE,CharLoc2,REP $07\9
LCDOut $FE,CharLoc1,REP $01\9
ENDIF
RETURN
; ----- Show the BAR graph -----------------------------------------------------
ShowBAR:
IF BAR_width = 0 then BARdone
if LastCharset <> BAR_style OR LastRtoL <> BAR_RtoL then ; If for change
LastCharset = BAR_style
LastRtoL = BAR_RtoL
SELECT CASE BAR_style ; Load the new custom chars
CASE 1 : GOSUB CharsetLines
CASE 2 : GOSUB CharsetBoxed
CASE 3 : GOSUB CharsetBlocks
END SELECT
endif
@ ifdef LCD4X20
LOOKUP BAR_row,[$80,$80,$C0,$94,$D4],BARtemp
@ else
LOOKUP BAR_row,[$80,$80,$C0,$90,$D0],BARtemp
@ endif
LCDOUT $FE, BARtemp + BAR_col ; Move cursor to start of the BAR
BARtemp = BAR_value * BAR_width ; calc the char position
BARtemp = DIV32 BAR_range
Remainder = R2
IF BAR_RtoL = 0 THEN
LCDOUT REP ThreeBARS\(BARtemp) ; send 3 bars
ELSE
IF BARtemp < BAR_width THEN
LCDOUT REP " "\(BAR_width - BARtemp - 1) ; Clear up to BARtemp-1
ENDIF
ENDIF
IF BARtemp < BAR_width THEN
Limit1 = BAR_range * 6
Limit1 = DIV32 10
if Remainder >= Limit1 then
LCDOUT TwoBARS ; send 2 bars
else
Limit1 = BAR_range * 3
Limit1 = DIV32 10
if Remainder >= Limit1 then ; 30%
LCDOUT OneBAR ; send 1 bar
else
LCDOUT " " ; no bars
endif
endif
ENDIF
IF BAR_RtoL = 0 THEN
IF BARtemp < BAR_width THEN
LCDOUT REP " "\(BAR_width - BARtemp - 1) ; clear till the end
ENDIF
ELSE
LCDOUT REP ThreeBARS\(BARtemp) ; send 3 bars
ENDIF
BARdone:
RETURN
ASM
; --- The main macro for creating BARgraphs ------------------------------------
BARgraph macro Value, Row, Col, Width, Range, Style, RtoL
MOVE?CW Range, _BAR_range ; Range MUST be a constant
MOVE?WW Value, _BAR_value ; Value MUST be a WORD variable
if (Row < 5) ; Row is a constant
MOVE?CB Row, _BAR_row
else ; Row is a variable
MOVE?BB Row, _BAR_row
endif
if (Col < 16) ; Is Col a constant ?
MOVE?CB Col, _BAR_col
else ; NO, it's a variable
MOVE?BB Col, _BAR_col
endif
if (Width <= 40)
MOVE?CB Width, _BAR_width
else
MOVE?BB Width, _BAR_width
endif
if ((Style >= lines) & (Style <= blocks)) ; Is Style a valid constant ?
MOVE?CB Style, _BAR_style
else ; NO, treat it like a variable
MOVE?BB Style, _BAR_style
endif
MOVE?CB RtoL, _BAR_RtoL
L?CALL _ShowBAR
endm
ENDASM
overBAR:
Bookmarks