Integer to ascii?
Handtool
Posts: 17
Howdy,
I have a variable "temp" that stores an integer that's updated frequently.· I'd like to·display it·on a·LCD terminal Appmod.··I have·been modifying the·example code for the LCD appmod :
DO
GOSUB ADC_Data
temp = (TempSpan/255 * adcBits/10 + Offset)/10
GOSUB Display
addr = Msg3 ' display "Temp ="
GOSUB LCD_Put_String
char = LcdLine2 + 3············ ' move cursor to 2nd line
GOSUB LCD_Command
addr = temp
GOSUB LCD_Put_String········ ' display temp
IF temp >· 65· THEN
HIGH SSR
ELSEIF temp <· 66· THEN
LOW SSR
ENDIF
LOOP
Everything works but the "addr·= temp" part.· Do I need to do integer to ascii conversion?· Whats the efficient way to do this?· Thanks
·
I have a variable "temp" that stores an integer that's updated frequently.· I'd like to·display it·on a·LCD terminal Appmod.··I have·been modifying the·example code for the LCD appmod :
DO
GOSUB ADC_Data
temp = (TempSpan/255 * adcBits/10 + Offset)/10
GOSUB Display
addr = Msg3 ' display "Temp ="
GOSUB LCD_Put_String
char = LcdLine2 + 3············ ' move cursor to 2nd line
GOSUB LCD_Command
addr = temp
GOSUB LCD_Put_String········ ' display temp
IF temp >· 65· THEN
HIGH SSR
ELSEIF temp <· 66· THEN
LOW SSR
ENDIF
LOOP
Everything works but the "addr·= temp" part.· Do I need to do integer to ascii conversion?· Whats the efficient way to do this?· Thanks
·
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
E PIN 1 ' LCD Enable (1 = enabled)
RW PIN 2 ' Read/Write\
RS PIN 3 ' Reg Select (1 = char)
LcdDirs VAR DIRB ' dirs for I/O redirection
LcdBusOut VAR OUTB
LcdBusIn VAR INB
CS PIN 8 'ADC Control pin
CLK PIN 9 'ADC Clock pin
DataOutput PIN 10 'ADC Output pin
SSR PIN 15 'SSR pin
'
[noparse][[/noparse] Constants ]
LcdCls CON $01 ' clear the LCD
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
LcdDDRam CON $80 ' Display Data RAM control
LcdLine1 CON $80 ' DDRAM address of line 1
LcdLine2 CON $C0 ' DDRAM address of line 2
LcdScrollTm CON 250 ' LCD scroll timing (ms)
'
[noparse][[/noparse] Variables ]
addr VAR Word ' address pointer
crsrPos VAR Byte ' cursor position
char VAR Byte ' character sent to LCD
idx VAR Byte ' loop counter
scan VAR Byte ' loop counter
temp VAR Word
adcBits VAR Byte
TempSpan VAR Word ' Full Scale input span in tenths of degrees.
TempSpan = 20000 ' Declare span. Set Vref to 1V and
' 0 to 255 res. will be spread over 100
' (hundredths).
Offset VAR Word ' Minimum temp. @Offset, ADC = 0
Offset = 0
'
[noparse][[/noparse] EEPROM Data ]
CC0 DATA $0E, $1F, $1C, $18, $1C, $1F, $0E, $00 ' char 0
CC1 DATA $0E, $1F, $1F, $18, $1F, $1F, $0E, $00 ' char 1
CC2 DATA $0E, $1F, $1F, $1F, $1F, $1F, $0E, $00 ' char 2
Msg1 DATA "WELCOME", 0
Msg2 DATA " BREWMASTER ", 0
Msg3 DATA "TEMP = ", 0
'
[noparse][[/noparse] Initialization ]
Initialize:
NAP 5 ' let LCD self-initialize
DIRL = %11111110 ' setup pins for LCD
LCD_Init:
#IF _LcdReady #THEN
LCDCMD E, %00110000 : PAUSE 5 ' 8-bit mode
LCDCMD E, %00110000 : PAUSE 0
LCDCMD E, %00110000 : PAUSE 0
LCDCMD E, %00100000 : PAUSE 0 ' 4-bit mode
LCDCMD E, %00101000 : PAUSE 0 ' 2-line mode
LCDCMD E, %00001100 : PAUSE 0 ' no crsr, no blink
LCDCMD E, %00000110 ' inc crsr, no disp shift
#ELSE
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 = %00001100 ' on, no crsr, no blink
GOSUB LCD_Command
char = %00000110 ' inc crsr, no disp shift
GOSUB LCD_Command
#ENDIF
'
[noparse][[/noparse] Program Code ]
Main:
char = LcdCls ' clear the LCD
GOSUB LCD_Command
PAUSE 500
Write_Greeting:
addr = Msg1 ' point to message
GOSUB LCD_Put_String ' write it
Scroll_Message:
crsrPos = LcdLine2 ' scroll on line 2
addr = Msg2 ' point to msg
GOSUB LCD_Scroll_String ' scroll it
PAUSE 2500
char = LcdCls ' clear the LCD
GOSUB LCD_Command
PAUSE 500
DO
GOSUB ADC_Data
temp = (TempSpan/255 * adcBits/10 + Offset)/10
GOSUB Display
addr = Msg3 ' display "Temp ="
GOSUB LCD_Put_String
char = LcdLine2 + 3 ' move cursor to 2nd line
GOSUB LCD_Command
addr = temp
GOSUB LCD_Put_String ' display temp
IF temp > 65 THEN
HIGH SSR
ELSEIF temp < 66 THEN
LOW SSR
ENDIF
LOOP
'
[noparse][[/noparse] Subroutines ]
ADC_Data:
HIGH CS
LOW CS
LOW CLK
PULSOUT CLK, 210
SHIFTIN DataOutput,CLK,MSBPOST,[noparse][[/noparse]adcBits\8]
RETURN
Display:
DEBUG HOME
DEBUG "8-bit binary value: ", BIN8 adcBits
DEBUG CR, CR, "Decimal value: ", DEC3 adcBits
DEBUG CR, CR, "Temp: ", DEC temp
RETURN
' Writes stored (in DATA statement) zero-terminated string to LCD
' -- position LCD cursor
' -- point to 0-terminated string (first location in 'addr')
LCD_Put_String:
DO
READ addr, char
IF (char = 0) THEN EXIT
GOSUB LCD_Write_Char
addr = addr + 1
LOOP
RETURN
' Scroll a message across LCD line
' -- set starting position in 'crsrPos'
' -- point to 0-terminated string (first location in 'addr')
' -- strings should be padded with eight spaces on each end
LCD_Scroll_String:
DO
char = crsrPos ' move to start of window
GOSUB LCD_Command
FOR idx = 0 TO 7 ' write chars in window
READ (addr + idx), char
IF (char = 0) THEN EXIT ' stop if end of string
GOSUB LCD_Write_Char
NEXT
IF (char = 0) THEN EXIT
addr = addr + 1 ' scroll
PAUSE LcdScrollTm
LOOP
RETURN
' Send command to LCD
' -- put command byte in 'char'
LCD_Command: ' write command to LCD
#IF _LcdReady #THEN
LCDCMD E, char
RETURN
#ELSE
LOW RS
GOTO LCD_Write_Char
#ENDIF
' Write character to current cursor position
' -- but byte to write in 'char'
LCD_Write_Char: ' write character to LCD
#IF _LcdReady #THEN
LCDOUT E, 0, [noparse][[/noparse]char]
#ELSE
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 to character mode
#ENDIF
RETURN
' Reads byte from LCD
' -- put byte address in 'addr'
' -- returns byte read in 'char'
LCD_Read_Char: ' read character from LCD
#IF _LcdReady #THEN
LCDIN E, addr, [noparse][[/noparse]char]
#ELSE
char = addr ' move cursor
GOSUB LCD_Command
HIGH RS ' data command
HIGH RW ' read
LcdDirs = %0000 ' make LCD bus inputs
HIGH E
char.HIGHNIB = LcdBusIn ' get high nibble
LOW E
HIGH E
char.LOWNIB = LcdBusIn ' get low nibble
LOW E
LcdDirs = %1111 ' return data lines to outputs
LOW RW
#ENDIF
RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
This would probly work
SELECT temp
CASE 32
char = "32"
CASE 33
char = "33"...
GOSUB LCD_Write_Char
The drawback is that I would have over 100 cases. Is there a better way?