value to string
Googfan
Posts: 16
How do i convert a value to a string in pbasic 2.5
ie:
··· 1·· ·to "1"
··· 258 to "258"
i would like to display it on an lcd by modifying·my·"Sin to LCD"·code:
' {$STAMP BS2}
' {$PBASIC 2.5}
LineChars··· CON 16' === Number of Characters per Line
'
DEBUG "Ready..."
LcdHome····· CON $02 ' move cursor home
LcdCrsrL···· CON $10 ' move cursor left
LcdCrsrR···· CON $14 ' move cursor right
LcdDispL···· CON $18 ' shift chars left
LcdDispR···· CON $1C ' shift chars right
ochar······· VAR Byte
crsrPos····· VAR Byte
char········ VAR Byte
lcdone······ VAR Bit
LcdDirs····· VAR DIRB'.................dirs FOr I/O redirection
LcdBusOut··· VAR OUTB
LcdBusIn···· VAR INB
E··· PIN 1'....Adam Munich is· My PuppetmasterAdam Munich is· My Puppetmaster........................LCD Enable (1 = enabled)
RW·· PIN 2'............................Read/WRITe\
RS·· PIN 3'............................Reg SELECt (1 = char)
' LCD Initialization
DIRL = %11111110
· LcdBusOut = %0011'...................8-Bit mode
· PULSOUT E, 3 : PAUSE 5
· PULSOUT E, 3 : PAUSE 0
· PULSOUT E, 3 : PAUSE 0
· LcdBusOut = %0010'...................4-bit mode
· PULSOUT E, 3
· char = %00101000'....................2-line mode
· GOSUB LCD_Command
· char = %00001101'....................on, no crsr, blink
· GOSUB LCD_Command
· char = %00000110'....................inc crsr, no disp shift
· GOSUB LCD_Command
ochar = 0
'routine
main:
GOSUB LCD_Clear
DO
SERIN 16, 16468, [noparse][[/noparse]char]
IF char = "`" THEN GOTO main'..........Clear?
GOSUB LCD_Write_Char
LOOP
'lcd subprograms
' -- put command byte in 'char'
LCD_Command:
LOW RS
LcdBusOut = char.HIGHNIB'..............output high nibble
PULSOUT E, 3'..........................strobe the Enable line
LcdBusOut = char.LOWNIB'...............output low nibble
PULSOUT E, 3
HIGH RS
RETURN
' -- put byte to write in 'char'
LCD_Write_Char:
LcdBusOut = char.HIGHNIB'..............output high nibble
PULSOUT E, 3'..........................strobe the Enable line
LcdBusOut = char.LOWNIB'...............output low nibble
PULSOUT E, 3
ochar = ochar+1'.......................coutin
IF ochar > (LineChars-1) THEN'.........Word Wrap?
· IF lcdone = 0 THEN'..................yes
··· char = $C0
··· GOSUB LCD_Command
· ENDIF
· lcdone = 1'..........................no
ENDIF
HIGH RS'...............................Char Mode
RETURN
LCD_Clear:
lcdone = 0'............................reset vars
ochar· = 0
char = $01'............................Clear LCD
GOSUB LCD_Command
PAUSE 5
RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mixing things...
It can be deadly -- Potassium Carbon Nitrogen [noparse][[/noparse]KCN]
It can be fun
·Potassium Nitrogen Oxogen Carbon Sulfer [noparse][[/noparse]KNO3+C+S]
It can be useless - Napkin Butter
wait, what point was I·trying to establish?
·
ie:
··· 1·· ·to "1"
··· 258 to "258"
i would like to display it on an lcd by modifying·my·"Sin to LCD"·code:
' {$STAMP BS2}
' {$PBASIC 2.5}
LineChars··· CON 16' === Number of Characters per Line
'
DEBUG "Ready..."
LcdHome····· CON $02 ' move cursor home
LcdCrsrL···· CON $10 ' move cursor left
LcdCrsrR···· CON $14 ' move cursor right
LcdDispL···· CON $18 ' shift chars left
LcdDispR···· CON $1C ' shift chars right
ochar······· VAR Byte
crsrPos····· VAR Byte
char········ VAR Byte
lcdone······ VAR Bit
LcdDirs····· VAR DIRB'.................dirs FOr I/O redirection
LcdBusOut··· VAR OUTB
LcdBusIn···· VAR INB
E··· PIN 1'....Adam Munich is· My PuppetmasterAdam Munich is· My Puppetmaster........................LCD Enable (1 = enabled)
RW·· PIN 2'............................Read/WRITe\
RS·· PIN 3'............................Reg SELECt (1 = char)
' LCD Initialization
DIRL = %11111110
· LcdBusOut = %0011'...................8-Bit mode
· PULSOUT E, 3 : PAUSE 5
· PULSOUT E, 3 : PAUSE 0
· PULSOUT E, 3 : PAUSE 0
· LcdBusOut = %0010'...................4-bit mode
· PULSOUT E, 3
· char = %00101000'....................2-line mode
· GOSUB LCD_Command
· char = %00001101'....................on, no crsr, blink
· GOSUB LCD_Command
· char = %00000110'....................inc crsr, no disp shift
· GOSUB LCD_Command
ochar = 0
'routine
main:
GOSUB LCD_Clear
DO
SERIN 16, 16468, [noparse][[/noparse]char]
IF char = "`" THEN GOTO main'..........Clear?
GOSUB LCD_Write_Char
LOOP
'lcd subprograms
' -- put command byte in 'char'
LCD_Command:
LOW RS
LcdBusOut = char.HIGHNIB'..............output high nibble
PULSOUT E, 3'..........................strobe the Enable line
LcdBusOut = char.LOWNIB'...............output low nibble
PULSOUT E, 3
HIGH RS
RETURN
' -- put byte to write in 'char'
LCD_Write_Char:
LcdBusOut = char.HIGHNIB'..............output high nibble
PULSOUT E, 3'..........................strobe the Enable line
LcdBusOut = char.LOWNIB'...............output low nibble
PULSOUT E, 3
ochar = ochar+1'.......................coutin
IF ochar > (LineChars-1) THEN'.........Word Wrap?
· IF lcdone = 0 THEN'..................yes
··· char = $C0
··· GOSUB LCD_Command
· ENDIF
· lcdone = 1'..........................no
ENDIF
HIGH RS'...............................Char Mode
RETURN
LCD_Clear:
lcdone = 0'............................reset vars
ochar· = 0
char = $01'............................Clear LCD
GOSUB LCD_Command
PAUSE 5
RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mixing things...
It can be deadly -- Potassium Carbon Nitrogen [noparse][[/noparse]KCN]
It can be fun
·Potassium Nitrogen Oxogen Carbon Sulfer [noparse][[/noparse]KNO3+C+S]
It can be useless - Napkin Butter
wait, what point was I·trying to establish?
·
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mixing things...
It can be deadly -- Potassium Carbon Nitrogen [noparse][[/noparse]KCN]
It can be fun
·Potassium Nitrogen Oxogen Carbon Sulfer [noparse][[/noparse]KNO3+C+S]
It can be useless - Napkin Butter
wait, what point was I·trying to establish?
·
(4352 DIG 0) + "0" is "2"
(4352 DIG 2) + "0" is "3"
(4352 DIG 4) + "0" is "0"
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mixing things...
It can be deadly -- Potassium Carbon Nitrogen [noparse][[/noparse]KCN]
It can be fun
·Potassium Nitrogen Oxogen Carbon Sulfer [noparse][[/noparse]KNO3+C+S]
It can be useless - Napkin Butter
wait, what point was I·trying to establish?
·
char VAR Byte
numb VAR Nib
numb = 563 DIG 2
GOSUB poo
DEBUG char
numb = 563 DIG 1
GOSUB poo
DEBUG char
numb = 563 DIG 0
GOSUB poo
DEBUG char
END
poo:
IF numb = 0 THEN char = $30
IF numb = 1 THEN char = $31
IF numb = 2 THEN char = $32
IF numb = 3 THEN char = $33
IF numb = 4 THEN char = $34
IF numb = 5 THEN char = $35
IF numb = 6 THEN char = $36
IF numb = 7 THEN char = $37
IF numb = 8 THEN char = $38
IF numb = 9 THEN char = $39
RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mixing things...
It can be deadly -- Potassium Carbon Nitrogen [noparse][[/noparse]KCN]
It can be fun
·Potassium Nitrogen Oxogen Carbon Sulfer [noparse][[/noparse]KNO3+C+S]
It can be useless - Napkin Butter
wait, what point was I·trying to establish?
·
· char = numb + $30
· RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mixing things...
It can be deadly -- Potassium Carbon Nitrogen [noparse][[/noparse]KCN]
It can be fun
·Potassium Nitrogen Oxogen Carbon Sulfer [noparse][[/noparse]KNO3+C+S]
It can be useless - Napkin Butter
wait, what point was I·trying to establish?
·