Lcd bargraph - diyAudio
Go Back   Home > Forums > Source & Line > Analog Line Level

Analog Line Level Preamplifiers , Passive Pre-amps, Crossovers, etc.

Please consider donating to help us continue to serve you.

Ads on/off / Custom Title / More PMs / More album space / Advanced printing & mass image saving
Reply
 
Thread Tools Search this Thread
Old 21st January 2011, 01:38 PM   #1
Leon08 is offline Leon08  Germany
Banned
 
Join Date: Sep 2010
Location: at Home
Default Lcd bargraph

I found a nice library for LCD bargraphs and wanted to use it in some project.But it was not written in JAL, so I tried to convert it, but something is not working.
Anyway here is what I have:
This is for Bascom AVR
Quote:
'************************************************* ***************
'* Creates a variable sized BAR-graph anywhere on the screen *
'************************************************* ***************
'* Name : LCDbar_INC.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 *
'* : *
'************************************************* ***************
; 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
; --- Temporary vars ----
BARtemp VAR WORD
Remainder VAR WORD
BARloop VAR BYTE
LastCharset VAR BYTE : LastCharset = 0
Limit1 VAR WORD
GOTO overBAR ; Skip over Subroutines
ThreeBARS CON 0 ; Identify the Custom Characters
TwoBARS CON 1
OneBAR CON 2
ASM
lines = 0x10000001 ; Define the Styles
boxed = 0x10000002
blocks = 0x10000003
ENDASM
; --- lines Style custom chars ----
CharsetLines:
LCDOut $FE,$40,REP $15\8 ; Custom char 0 - 3 lines |||
LCDOut $FE,$48,REP $14\8 ; Custom char 1 - 2 lines ||
LCDOut $FE,$50,REP $10\8 ; Custom char 2 - 1 line |
RETURN
; --- boxed Style custom chars ----
CharsetBoxed:
LCDOut $FE,$40,$1F,REP $15\6,$1F ; III
LCDOut $FE,$48,$1C,REP $14\6,$1C ; II
LCDOut $FE,$50,REP $10\8 ; I
RETURN
; --- blocks Style custom chars ----
CharsetBlocks:
LCDOut $FE,$40,REP $1F\8
LCDOut $FE,$48,REP $1C\8
LCDOut $FE,$50,REP $10\8
RETURN
; ----- Show the BAR graph -----------------------------------------------------
ShowBAR:
IF BAR_width = 0 then BARdone
if LastCharset <> BAR_style then ; If the Style has changed ?
LastCharset = BAR_style
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
For BARloop = 0 to BAR_width -1
SELECT CASE BARtemp
CASE IS > BARloop
LCDOUT ThreeBARS ; send 3 bars |||
CASE IS < BARloop
LCDOUT " " ; clear to end of BARwidth
CASE IS = BARloop
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
END SELECT
NEXT BARloop
BARdone:
RETURN
ASM
; --- The main macro for creating BARgraphs ------------------------------------
BARgraph macro Value, Row, Col, Width, Range, Style
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
L?CALL _ShowBAR
endm

ENDASM
overBAR:
And this the same for mikrobasic

Quote:
Module LCD_BarGraph_16_Module
' Written by picmicroman for mikrobasic
' Based on darrel taylor code work
' Define styles
Const Lines = 1
Const Boxes = 2
Const Blocks = 3
' Define Bar numbers
Const Boarder = 3
Const OneBar = 2
Const TwoBars = 1
Const ThreeBars = 0
' 4X20 LCD
Const Row As Byte[5] = ($80,$80,$C0,$94,$D4)
' If 4X16 LCD is used, comment the above line
' and uncomment the following line...
'Const Row As Byte[5] = ($80,$80,$C0,$90,$D0)
' Global Variables here
Dim BAR_Style, BAR_Loop As Byte
Dim Remainder As Word
Dim BAR_Temp As LongInt
' --- Lines Style custom chars ----
Sub Procedure CharSetLines
Dim Fvar As Byte
LCD_Cmd($40) ' Go to CGRAM location 64
For Fvar = 0 To 7
LCD_Chr_CP($15) ' Custom char 0 - 3 lines |||
Next Fvar

LCD_Cmd($48) ' Go to CGRAM location 72
LCD_Chr_CP($15)
For Fvar = 0 To 5
LCD_Chr_CP($14) ' Custom char 1 - 2 lines ||:
Next Fvar
LCD_Chr_CP($15)
LCD_Cmd($50) ' Go to CGRAM location 80
LCD_Chr_CP($15)
For Fvar = 0 To 5
LCD_Chr_CP($10) ' Custom char 2 - 1 line |::
Next Fvar
LCD_Chr_CP($15)
End Sub
' --- Boxes Style custom chars ----
Sub Procedure CharSetBoxes
Dim Fvar As Byte
LCD_Cmd($40) ' Go to CGRAM location 64
LCD_Chr_CP($1F)
For Fvar = 0 To 5
LCD_Chr_CP($15) ' Custom char 0 - 3 lines III
Next Fvar
LCD_Chr_CP($1F)
LCD_Cmd($48) ' Go to CGRAM location 72
LCD_Chr_CP($1D)
For Fvar = 0 To 5
LCD_Chr_CP($14) ' Custom char 1 - 2 lines II:
Next Fvar
LCD_Chr_CP($1D)
LCD_Cmd($50) ' Go to CGRAM location 80
LCD_Chr_CP($15)
For Fvar = 0 To 5
LCD_Chr_CP($10) ' Custom char 2 - 1 line |::
Next Fvar
LCD_Chr_CP($15)
End Sub
' --- blocks Style custom chars ----
Sub Procedure CharSetBlocks
Dim Fvar As Byte
LCD_Cmd($40) ' Go to CGRAM location 64
For Fvar = 0 To 7
LCD_Chr_CP($1F) ' Custom char 0 - 3 block |||
Next Fvar
LCD_Cmd($48) ' Go to CGRAM location 72
LCD_Chr_CP($1D)
For Fvar = 0 To 5
LCD_Chr_CP($1C) ' Custom char 1 - 2 lblock ||:
Next Fvar
LCD_Chr_CP($1D)
LCD_Cmd($50) ' Go to CGRAM location 80
LCD_Chr_CP($15)
For Fvar = 0 To 5
LCD_Chr_CP($10) ' Custom char 2 - 1 line |::
Next Fvar
LCD_Chr_CP($15)
End Sub
' --- Dots boarder custom chars ----
Sub Procedure CharSetDots
Dim Fvar As Byte
LCD_Cmd($58) ' Go to CGRAM location 88
LCD_Chr_CP($15) ' Draw a three dots . . .
For Fvar = 0 To 5
LCD_Chr_CP($00)
Next Fvar
LCD_Chr_CP($15) ' Draw a three dots . . .
End Sub
' --- custom chars ----
Sub Procedure Char_Set(Dim Style As Byte)
BAR_Style = Style ' Remeber last used CharSet
Select Case Style ' Load new custom chars if style is changed
Case 1
CharSetLines
Case 2
CharSetBoxes
Case 3
CharSetBlocks
Case Else
CharSetLines
End Select
End Sub
' --- custom chars are loaded from here at start up ----
Sub Procedure LCD_BarGraph_Init
' Bar graph is initialized to lines at start up
BAR_Style = Lines ' 1 = Lines, 2 = Boxed, 3 = Blocks
Char_Set(BAR_Style) ' Load custom chars when PIC is 1st powered on
CharSetDots ' Load boarder dots
End Sub
' --- Bar Graph complicated calculation are isolated here ----
Sub Procedure Calculate(Dim BAR_Value As Word,
Dim BAR_Width As Byte,
Dim BAR_Range As Word)
BAR_Temp = BAR_Value * BAR_Width
Remainder = BAR_Temp Mod BAR_Range
BAR_Temp = BAR_Temp DIV BAR_Range
End Sub
' --- Bar Graph is drawn here ----
Sub Procedure LCD_BarGraph_Draw(Dim BAR_Value As Word,
Dim BAR_Row As Byte,
Dim BAR_Col As Byte,
Dim BAR_Width As Byte,
Dim BAR_Range As Word,
Dim Style As Byte)

Dim Limit As Word
If BAR_Width = 0 Then ' If BAR_Width = 0, do nothing
Exit
End If
If Style <> BAR_Style Then ' If style changed, the load the
Char_Set(Style) ' new style to LCD CGRAM....
End If
BAR_Temp = Row[BAR_Row] ' Define at which row the bar is
LCD_Cmd(BAR_Temp + BAR_Col - 1) ' Move cursor to bar grpah start
Calculate(BAR_Value, BAR_Width, BAR_Range) ' Make complicated calculations
For BAR_Loop = 0 To (BAR_Width - 1)
If BAR_Temp > BAR_Loop Then
LCD_Chr_CP(ThreeBars) ' Send 3 bars
End If
If BAR_Temp < BAR_Loop Then
LCD_Chr_CP(Boarder) ' Clear to end of bar width
End If
If BAR_Temp = BAR_Loop Then
Limit = BAR_Range * 6
Limit = Limit Div 10
If Remainder >= Limit Then
LCD_Chr_CP(TwoBars) ' Send 2 bars
Else
Limit = BAR_Range * 3
Limit = Limit Div 10
If Remainder >= Limit Then
LCD_Chr_CP(OneBar) ' Send 1 bar
Else
LCD_Chr_CP(Boarder) ' No bars sent
End If
End If
End If
Next Bar_Loop
End Sub
End.
And this is my conversion for JAL v2, but it does not work.
Quote:
-- Module LCD_BarGraph_16_Module
-- Written by picmicroman for mikrobasic then changed for jal
-- Based on darrel taylor code work
-- How to use
-- Value Row, Col, Width, Range , Style
-- LCD_BarGraph_Draw( Value , 1 , 1 , 16 , 255 , Lines )
--
-- LCD_BarGraph_Draw( Value , 2 , 1 , 16 , 255 , Boxes )
--
-- LCD_BarGraph_Draw( Value , 3 , 1 , 16 , 255 , Blocks)
-- 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.
-- LCD Row to place the BARgraph (1 to 4)
-- can be either a constant or a variable.
-- LCD Column to place the BARgraph (0 to LCDsize - 1)
-- can be either a constant or a variable.
-- LCDsize is the number of Chars in 1 line of the LCD, for "4x16" it's 16
-- Width of the BARgraph in charaters. (1 to LCDsize)
-- can be either a constant or a variable.
-- Range is 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.

-- Define styles
Const byte Lines = 1
Const byte Boxes = 2
Const byte Blocks = 3
-- Define Bar numbers
Const byte Boarder = 3
Const byte OneBar = 2
Const byte TwoBars = 1
Const byte ThreeBars = 0
-- 4X20 LCD
-- Const Byte Row[5] = {0x80,0x80,0xC0,0x94,0xD4}
-- If 4X16 LCD is used, comment the above line
-- and uncomment the following line...
Const Byte Row[5] = {0x80,0x80,0xC0,0x90,0xD0}
-- Global Variables here
Var byte BAR_Style, BAR_Loop
Var word Remainder
Var sdword BAR_Temp
-- Lines Style custom chars ----
Procedure CharSetLines is
Var byte Fvar
_lcd_write_command(0x40) -- Go to CGRAM location 64
while (Fvar < 1) | (Fvar < 8) loop
lcd_write_char(0x15) -- Custom char 0 - 3 lines |||
Fvar = Fvar + 1
end loop

_lcd_write_command(0x48) -- Go to CGRAM location 72
lcd_write_char(0x15)
while (Fvar < 1) | (Fvar < 6) loop
lcd_write_char(0x14) -- Custom char 1 - 2 lines ||:
Fvar = Fvar + 1
end loop
-- lcd_write_char(0x15)
_lcd_write_command(0x50) -- Go to CGRAM location 80
lcd_write_char(0x15)
while (Fvar < 1) | (Fvar < 6) loop
lcd_write_char(0x10) -- Custom char 2 - 1 line |::
Fvar = Fvar + 1
end loop
lcd_write_char(0x15)
End procedure
-- Boxes Style custom chars ----
Procedure CharSetBoxes is
Var byte Fvar
_lcd_write_command(0x40) -- Go to CGRAM location 64
lcd_write_char(0x1F)
while (Fvar < 1) | (Fvar < 6) loop
lcd_write_char(0x15) -- Custom char 0 - 3 lines III
Fvar = Fvar + 1
end loop
lcd_write_char(0x1F)
_lcd_write_command(0x48) -- Go to CGRAM location 72
lcd_write_char(0x1D)
while (Fvar < 1) | (Fvar < 6) loop
lcd_write_char(0x14) -- Custom char 1 - 2 lines II:
Fvar = Fvar + 1
end loop
lcd_write_char(0x1D)
_lcd_write_command(0x50) -- Go to CGRAM location 80
lcd_write_char(0x15)
while (Fvar < 1) | (Fvar < 6) loop
lcd_write_char(0x10) -- Custom char 2 - 1 line |::
Fvar = Fvar + 1
end loop
lcd_write_char(0x15)
End procedure
-- blocks Style custom chars ----
Procedure CharSetBlocks is
Var byte Fvar
_lcd_write_command(0x40) -- Go to CGRAM location 64
while (Fvar < 1) | (Fvar < 8) loop
lcd_write_char(0x1F) -- Custom char 0 - 3 block |||
Fvar = Fvar + 1
end loop
_lcd_write_command(0x48) -- Go to CGRAM location 72
lcd_write_char(0x1D)
while (Fvar < 1) | (Fvar < 6) loop
lcd_write_char(0x1C) -- Custom char 1 - 2 lblock ||:
Fvar = Fvar + 1
end loop
lcd_write_char(0x1D)
_lcd_write_command(0x50) -- Go to CGRAM location 80
lcd_write_char(0x15)
while (Fvar < 1) | (Fvar < 6) loop
lcd_write_char(0x10) -- Custom char 2 - 1 line |::
Fvar = Fvar + 1
end loop
lcd_write_char(0x15)
End procedure
-- Dots boarder custom chars ----
Procedure CharSetDots is
Var byte Fvar
_lcd_write_command(0x58) -- Go to CGRAM location 88
lcd_write_char(0x15) -- Draw a three dots . . .
while (Fvar < 1) | (Fvar < 6) loop
lcd_write_char(0x00)
Fvar = Fvar + 1
end loop
lcd_write_char(0x15) -- Draw a three dots . . .
End procedure
-- custom chars ----
Procedure Char_Set(byte in Style) is
BAR_Style = Style -- Remeber last used CharSet
if Style == 1 then -- Load new custom chars if style is changed
CharSetLines
elsif
Style == 2 then
CharSetBoxes
elsif
Style == 3 then
CharSetBlocks
Else
CharSetLines
End if
End procedure
-- custom chars are loaded from here at start up ----
Procedure LCD_BarGraph_Init is
-- Bar graph is initialized to lines at start up
BAR_Style = Lines -- 1 = Lines, 2 = Boxed, 3 = Blocks
Char_Set(BAR_Style) -- Load custom chars when PIC is 1st powered on
CharSetDots -- Load boarder dots
End procedure
-- Bar Graph complicated calculation are isolated here ----
Procedure Calculate(Word in BAR_Value,
Byte in BAR_Width,
Word in BAR_Range) is
BAR_Temp = BAR_Value * BAR_Width
Remainder = BAR_Temp % BAR_Range
BAR_Temp = BAR_Temp / BAR_Range
End procedure
-- Bar Graph is drawn here ----
Procedure LCD_BarGraph_Draw(Word in BAR_Value,
Byte in BAR_Row,
Byte in BAR_Col,
Byte in BAR_Width,
Word in BAR_Range,
Byte in Style) is

Var Word Limit
If (BAR_Width == 0) Then -- If BAR_Width = 0, do nothing
return
End If
If Style != BAR_Style Then -- If style changed, the load the
Char_Set(Style) -- new style to LCD CGRAM....
End If
BAR_Temp = Row[BAR_Row] -- Define at which row the bar is
_lcd_write_command(BAR_Temp + (BAR_Col - 1)) -- Move cursor to bar grpah

Calculate(BAR_Value, BAR_Width, BAR_Range) -- Make complicated calculations
While (BAR_Loop <1) | (Bar_Loop < (BAR_Width - 1)) loop
If BAR_Temp > BAR_Loop Then
lcd_write_char(ThreeBars) -- Send 3 bars
End If
If BAR_Temp < BAR_Loop Then
lcd_write_char(Boarder) -- Clear to end of bar width
End If
If BAR_Temp == BAR_Loop Then
Limit = BAR_Range * 6
Limit = Limit / 10
If Remainder >= Limit Then
lcd_write_char(TwoBars) -- Send 2 bars
Else
Limit = BAR_Range * 3
Limit = Limit / 10
If Remainder >= Limit Then
lcd_write_char(OneBar) -- Send 1 bar
Else
lcd_write_char(Boarder) -- No bars sent
End If
End If
End If
BAR_Loop = BAR_Loop + 1
end loop
End procedure
Maybe here is a smart guy, who can say me what I'm doing wrong?

Last edited by Leon08; 21st January 2011 at 01:42 PM.
  Reply With Quote
Old 25th January 2011, 01:49 PM   #2
Leon08 is offline Leon08  Germany
Banned
 
Join Date: Sep 2010
Location: at Home
O.K, here the new version.Now it works, but there is some unexpected behaviour.
First: the bar is shown on the wrong line.
Second: Although there is no command to change the column "lcd_cursor_position(BAR_Row, BAR_Col)" here , it does change it.Actually it is not a fault, it must change the column to work, but I don't understand how it happens.


Quote:
-- Module LCD_BarGraph_16_Module
-- Written by picmicroman for mikrobasic then changed for jal
-- Based on darrel taylor code work
-- How to use:
-- LCD_BarGraph_Init -- Init LCD bar graph
-- Value Row, Col, Width, Range , Style
-- LCD_BarGraph_Draw( Value , 1 , 0 , 16 , 255 , Lines )
--
-- LCD_BarGraph_Draw( Value , 2 , 0 , 16 , 255 , Boxes )
--
-- LCD_BarGraph_Draw( Value , 3 , 0 , 16 , 255 , Blocks)
-- 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.
-- LCD Row to place the BARgraph (1 to 4)
-- can be either a constant or a variable.
-- LCD Column to place the BARgraph (0 to LCDsize - 1)
-- can be either a constant or a variable.
-- LCDsize is the number of Chars in 1 line of the LCD, for "4x16" it's 16
-- Width of the BARgraph in charaters. (1 to LCDsize)
-- can be either a constant or a variable.
-- Range is 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.

-- Define styles
Const byte Lines = 1
Const byte Boxes = 2
Const byte Blocks = 3
-- Define Bar numbers
-- Const byte Boarder = 3
-- Const byte OneBar = 2
-- Const byte TwoBars = 1
-- Const byte ThreeBars = 0
-- 4X20 LCD
-- Const Byte Row[5] = {0x80,0x80,0xC0,0x94,0xD4}
-- If 4X16 LCD is used, comment the above line
-- and uncomment the following line...
-- Const Byte Row[5] = {0x80,0x80,0xC0,0x90,0xD0}
-- Global Variables here
Var byte BAR_Style
Var word Remainder
Var sdword BAR_Temp = 0
-- Lines Style custom chars ----
Procedure CharSetLines is
_lcd_write_command(0x40) -- Go to CGRAM location 64
for 7 loop
lcd_write_char(0x15) -- Custom char 0 - 3 lines |||
end loop
_lcd_write_command(0x48) -- Go to CGRAM location 72
lcd_write_char(0x15)
for 5 loop
lcd_write_char(0x14) -- Custom char 1 - 2 lines ||:
end loop
lcd_write_char(0x15)

_lcd_write_command(0x50) -- Go to CGRAM location 80
lcd_write_char(0x15)
for 5 loop
lcd_write_char(0x10) -- Custom char 2 - 1 line |::
end loop
lcd_write_char(0x15)
End procedure
-- Boxes Style custom chars ----
Procedure CharSetBoxes is
_lcd_write_command(0x40) -- Go to CGRAM location 64
lcd_write_char(0x1F)
for 5 loop
lcd_write_char(0x15) -- Custom char 0 - 3 lines III
end loop
lcd_write_char(0x1F)
_lcd_write_command(0x48) -- Go to CGRAM location 72
lcd_write_char(0x1C) --(0x1D)
for 5 loop
lcd_write_char(0x14) -- Custom char 1 - 2 lines II:
end loop
lcd_write_char(0x1C) --(0x1D)
_lcd_write_command(0x50) -- Go to CGRAM location 80
lcd_write_char(0x15)
for 5 loop
lcd_write_char(0x10) -- Custom char 2 - 1 line |::
end loop
lcd_write_char(0x15)
End procedure
-- blocks Style custom chars ----
Procedure CharSetBlocks is
_lcd_write_command(0x40) -- Go to CGRAM location 64
for 7 loop
lcd_write_char(0x1F) -- Custom char 0 - 3 block |||
end loop
_lcd_write_command(0x48) -- Go to CGRAM location 72
lcd_write_char(0x1D)
for 5 loop
lcd_write_char(0x1C) -- Custom char 1 - 2 lblock ||:
end loop
lcd_write_char(0x1D)
_lcd_write_command(0x50) -- Go to CGRAM location 80
lcd_write_char(0x15)
for 5 loop
lcd_write_char(0x10) -- Custom char 2 - 1 line |::
end loop
lcd_write_char(0x15)
End procedure
-- Dots boarder custom chars ----
Procedure CharSetDots is
_lcd_write_command(0x58) -- Go to CGRAM location 88
lcd_write_char(0x15) -- Draw a three dots . . .
for 5 loop
lcd_write_char(0x00)
end loop
lcd_write_char(0x15) -- Draw a three dots . . .
End procedure
-- custom chars ----
Procedure Char_Set(byte in Style) is
BAR_Style = Style -- Remeber last used CharSet
if Style == 1 then -- Load new custom chars if style is changed
CharSetLines
elsif
Style == 2 then
CharSetBoxes
elsif
Style == 3 then
CharSetBlocks
Else
CharSetLines
End if
End procedure
-- custom chars are loaded from here at start up ----
Procedure LCD_BarGraph_Init is
-- Bar graph is initialized to lines at start up
BAR_Style = Lines -- 1 = Lines, 2 = Boxed, 3 = Blocks
Char_Set(BAR_Style) -- Load custom chars when PIC is 1st powered on
CharSetDots -- Load boarder dots
End procedure

-- Bar Graph is drawn here ----
Procedure LCD_BarGraph_Draw(Word in BAR_Value,
Byte in BAR_Row,
Byte in BAR_Col,
Byte in BAR_Width,
Word in BAR_Range,
Byte in Style) is

Var Word Limit
Var Byte BAR_Loop = 0
If (BAR_Width == 0) Then -- If BAR_Width = 0, do nothing
return
End If
If Style != BAR_Style Then -- If style changed, the load the
Char_Set(Style) -- new style to LCD CGRAM....
End If

lcd_cursor_position(BAR_Row, BAR_Col) -- Init cursor to bar graph start
BAR_Temp = BAR_Row -- Define at which row the bar is
-- lcd_cursor_position(BAR_Temp, (BAR_Col + BAR_Temp)) -- Move cursor to new position

-- Make complicated calculations
BAR_Temp = BAR_Value * BAR_Width
Remainder = BAR_Temp % BAR_Range
BAR_Temp = BAR_Temp / BAR_Range

While (BAR_Loop <1) | (Bar_Loop < (BAR_Width - 1)) loop
If BAR_Temp > BAR_Loop Then
lcd_write_char(0) -- Send 3 bars
End If
If BAR_Temp < BAR_Loop Then
lcd_write_char(3) -- Clear to end of bar width
End If
If BAR_Temp == BAR_Loop Then
Limit = BAR_Range * 6
Limit = Limit / 10
If Remainder >= Limit Then
lcd_write_char(1) -- Send 2 bars
Else
Limit = BAR_Range * 3
Limit = Limit / 10
If Remainder >= Limit Then
lcd_write_char(2) -- Send 1 bar
Else
lcd_write_char(3) -- No bars sent
End If
End If
End If
BAR_Loop = BAR_Loop + 1
end loop

End procedure
  Reply With Quote

Reply


Hide this!Advertise here!
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nixie bargraph as a audio VU-meter wim Tubes / Valves 11 27th March 2011 08:13 PM
Bargraph and clip LED's nigelwright7557 Solid State 0 24th November 2009 12:42 AM
FS: LCD Controllers - $90+shipping (use laptop LCD on your desktop) infrared Swap Meet 4 25th February 2003 08:07 PM


New To Site? Need Help?

All times are GMT. The time now is 03:12 PM.


vBulletin Optimisation provided by vB Optimise (Pro) - vBulletin Mods & Addons Copyright © 2014 DragonByte Technologies Ltd.
Copyright 1999-2014 diyAudio

Content Relevant URLs by vBSEO 3.3.2