LCD tachometer help
tgraz34
Posts: 16
Im currently using this code to display RPM and a bargraph on a LCD screen.
The problem is that i have 4 zeros infront of RPM and i dont want them to be there.
I know that its because of the DEC4 command in the subroutine Def_Horiz_Bar_Char:.
Does anyone know of a way to get around this problem.
The problem is that i have 4 zeros infront of RPM and i dont want them to be there.
I know that its because of the DEC4 command in the subroutine Def_Horiz_Bar_Char:.
Does anyone know of a way to get around this problem.
' -----[noparse][[/noparse] Title ]-------------------------------------------------------------- ' Smart Sensors and Applications - HorizBarGraph.bs2 ' Display values entered into the Debug Terminal's Receive windowpane ' as horizontal bar graph data in the LCD. ' {$STAMP BS2} ' {$PBASIC 2.5} ' -----[noparse][[/noparse] I/O Pins ]----------------------------------------------------------- LcdPin PIN 15 SpeedIn PIN 0 ' -----[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 ' -----[noparse][[/noparse] Variables ]---------------------------------------------------------- rpm VAR Word pulses VAR Word percent VAR Byte 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 ' -----[noparse][[/noparse] Initialization ]----------------------------------------------------- PAUSE 100 ' Debounce power supply SEROUT LcdPin, T9600, [noparse][[/noparse]LcdOn, LcdCls] ' Initialize LCD SEROUT LcdPin, T9600, [noparse][[/noparse]137, "RPM" ] PAUSE 5 ' 5 ms delay for clearing display custChar = 3 ' Select Custom Character 3 dotLine = %11111 ' Black all pixels in each line GOSUB Def_Horiz_Bar_Char ' Character define subroutine line = Line1 DO GOSUB Acquire_RPM value = (RPM / 35) GOSUB Bar_Graph: LOOP ' Acquire_RPM Acquire_RPM: COUNT SpeedIn, Capture, Pulses rpm = (pulses * 12) RETURN ' Bar_Graph Bar_Graph: ' Fill from left with black bars value = value MAX 100 charCnt = value / 5 ' Number of black bars custChar = 3 ' Choose black custom character IF charCnt > 0 THEN ' If black bars to print then FOR cursor = 0 TO charCnt - 1 ' Print charCnt - 1 black bars GOSUB Disp_Cust_Char ' Print the black bar NEXT ENDIF ' Display Custom Character 2 with a certain number of black columns. cursor = charCnt ' Place cursor custChar = value // 5 ' How many 5ths of a bar? ' Choose bit pattern for custom character definition LOOKUP custChar, [noparse][[/noparse]%00000, %10000, %11000, %11100, %11110], dotLine custChar = 2 ' Set custom character to 2 GOSUB Def_Horiz_Bar_Char ' Define the custom character GOSUB Disp_Cust_Char ' Display the custom character ' Print over everything to the right with spaces. IF (charCnt + 1) < 15 THEN ' Partial char left of char 15? FOR cursor = (charCnt + 1) TO 15 ' Fill to right with " " SEROUT LcdPin, T9600, [noparse][[/noparse]line + cursor, " "] NEXT ELSEIF value = 80 THEN ' Special case: value = 80 SEROUT LcdPin, T9600, [noparse][[/noparse]line + cursor, 3] ELSEIF charCnt = 14 THEN ' Special case: 75 <= value <= 80 SEROUT LcdPin, T9600, [noparse][[/noparse]line + 15, " "] ENDIF RETURN ' Def_Horiz_Bar_Char Def_Horiz_Bar_Char: SEROUT LcdPin, T9600, ' Define custom character [noparse][[/noparse]Define + custChar] FOR index = 0 TO 7 ' 7 bytes, define 7 dotted lines SEROUT LcdPin, T9600, [noparse][[/noparse]dotLine] ' Send it to the LCD NEXT SEROUT LcdPin, T9600, [noparse][[/noparse]133, DEC4 rpm] RETURN ' Disp_Cust_Char Disp_Cust_Char: SEROUT LcdPin, T9600, ' Print custom character [noparse][[/noparse]line + cursor, custChar] RETURN
Comments
But maybe before this...
SEROUT·LcdPin,·T9600,·[noparse][[/noparse]133,·DEC4·rpm]
Maybe something like...
SEROUT·LcdPin,·T9600,·[noparse][[/noparse]133,·"··· "]
And instead of the above...
SEROUT·LcdPin,·T9600,·[noparse][[/noparse]133,·DEC·rpm]
If that does not work, might want to say which specific LCD you have and give a link to the instruction manual.
Or to explain this, here is a count down example which leaves the 1 there...
(Should count down from 12 to 7)
12
11
10
19
18
17
And a correction for that...
(Send spaces and it gets rid of the 1)
"· "
12
"· "
11
"· "
10
"· "
·9
"· "
·8
"· "
·7
So we have this and I was wondering what the 133 was for...
SEROUT·LcdPin,·T9600,·[noparse][[/noparse]133,·"··· "]
Looking in the directions for the LCD, it means...
133· Move cursor to line 0, position 5
So that gives us more options! Because there are more of these commands in the instruction manual...
128 Move cursor to line 0, position 0
129 Move cursor to line 0, position 1
130 Move cursor to line 0, position 2
131 Move cursor to line 0, position 3
132 Move cursor to line 0, position 4
133 Move cursor to line 0, position 5
134 Move cursor to line 0, position 6
135 Move cursor to line 0, position 7
136 Move cursor to line 0, position 8
137 Move cursor to line 0, position 9
So you could do this...
SEROUT LcdPin, T9600, [noparse][[/noparse]128, " "]
SEROUT LcdPin, T9600, [noparse][[/noparse]129, " "]
SEROUT LcdPin, T9600, [noparse][[/noparse]130, " "]
SEROUT LcdPin, T9600, [noparse][[/noparse]131, " "]
SEROUT LcdPin, T9600, [noparse][[/noparse]132, " "]
SEROUT LcdPin, T9600, [noparse][[/noparse]133, " "]
SEROUT LcdPin, T9600, [noparse][[/noparse]134, " "]
SEROUT LcdPin, T9600, [noparse][[/noparse]135, " "]
Or...
SEROUT LcdPin, T9600, [noparse][[/noparse]131, "··· "]
Depends on where position 0 is!
Experiment and see what happens...
FYI - Here are the LCD instructions. Note on page 11 it shows various characters. And one of the characters listed is blank! (Nothing). You could send that character to overwrite a zero...
http://www.parallax.com/Portals/0/Downloads/docs/prod/audiovis/SerialLCD-v2.0.pdf
Post Edited (bill190) : 3/1/2010 3:42:39 PM GMT