LCD Bargraph help
This code dispays RPM and a percentage of how fast your going with a bar graph. How can i make this code so that the bar graph displays on a 4 x 20 LCD screen instead of a 2 X 16. So the bar graph doesn't stop at the 16th position and keeps going till the 20th.
' {$STAMP BS2}
' {$PBASIC 2.5}
' -----[noparse][[/noparse] I/O Pins ]-----------------------------------------------------------
LcdPin PIN 15
SpeedIn PIN 3
' -----[noparse][[/noparse] Constants ]----------------------------------------------------------
T9600 CON 84 ' True, 8-bits, no parity, 9600
Capture CON 5000
LcdCls CON 12 ' Form feed -> clear screen
LcdCr CON 13 ' Carriage return
LcdOff CON 21 ' Turns display off
LcdOn CON 22 ' Turns display on
Line0 CON 128 ' Line 0, character 0
Line1 CON 148 ' Line 1, character 0
Define CON 248 ' Address defines cust char 0
LcdBLon CON $11 ' Backlight On
' -----[noparse][[/noparse] Variables ]----------------------------------------------------------
rpm VAR Word
pulses VAR Word
custChar VAR Nib ' Custom charcter selector
index VAR Nib ' Eeprom index variable
dotLine VAR Byte ' 5-pixel dotted line
cursor VAR Nib ' Cursor placement
value VAR Byte ' Value to be graphed.
charCnt VAR Byte ' Character counting variable
line VAR Byte ' Line0 or Line1
percent VAR Byte
highVal VAR Word
' -----[noparse][[/noparse] Initialization ]-----------------------------------------------------
PAUSE 100
SEROUT LcdPin, T9600, [noparse][[/noparse]LcdOn, LcdCls, LcdBLon]
PAUSE 5
custChar = 3
dotLine = %11111
GOSUB Def_Horiz_Bar_Char
line = Line1
pulses = 0
highVal = 3500
DO
GOSUB Acquire_RPM
value = rpm / 44
GOSUB Bar_Graph:
LOOP
Acquire_RPM:
COUNT SpeedIn, Capture, Pulses
rpm = (pulses * 12)
percent = (rpm / (highVal / 100))
RETURN
Bar_Graph:
value = value MAX 80
charCnt = value / 5
custChar = 3
IF charCnt > 0 THEN
FOR cursor = 0 TO charCnt - 1
GOSUB Disp_Cust_Char
NEXT
ENDIF
cursor = charCnt
custChar = value // 5
LOOKUP custChar,
[noparse][[/noparse]%00000, %10000, %11000, %11100, %11110],
dotLine
custChar = 2
GOSUB Def_Horiz_Bar_Char
GOSUB Disp_Cust_Char
IF (charCnt + 1) < 15 THEN
FOR cursor = (charCnt + 1) TO 15
SEROUT LcdPin, T9600,
[noparse][[/noparse]line + cursor, " "]
NEXT
ELSEIF value = 80 THEN
SEROUT LcdPin, T9600,
[noparse][[/noparse]line + cursor, 3]
ELSEIF charCnt = 14 THEN
SEROUT LcdPin, T9600, [noparse][[/noparse]line + 15, " "]
ENDIF
RETURN
Def_Horiz_Bar_Char:
SEROUT LcdPin, T9600,
[noparse][[/noparse]Define + custChar]
FOR index = 0 TO 7
SEROUT LcdPin, T9600, [noparse][[/noparse]dotLine]
NEXT
SEROUT LcdPin, T9600, [noparse][[/noparse]134, DEC rpm, " RPM "]
SEROUT LcdPin, T9600, [noparse][[/noparse]164, DEC percent, "% "]
RETURN
Disp_Cust_Char:
SEROUT LcdPin, T9600,
[noparse][[/noparse]line + cursor, custChar]
RETURN

Comments
·??
Also there will be changes in the program segment that begins with
IF (charCnt + 1) < 15 THEN
where numbers 15, 80 and 14 should probably(?!) be 19, 100 and 18, respectively.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com