Dear all,
i have some problem regarding the conversion of a variable to string.
I have the following code.
Code:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' VAR for IR to LCD '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
IRCS var byte ' this is the checksum for the IR required in external display command
TEMP var word ' this is the word variable for TEMP
temperature var word ' for result and output to lcd
TEMPIR var word ' set a variable tempir
Remainder var word ' Get the remainder = tempir//50
'------------------------------------------------------------------------------*
' Measure IR object temp sent to uLCD *
'------------------------------------------------------------------------------*
object:
reg = $07 ' based on the datasheet $07 is the object's temp
addr = %10110100 ' $B4 binary value: %10110100
i2cwrite SDA, scl, addr ' send write command, shift the address B4, 8 bits where LSB is W = 0
i2cwrite sda, scl, reg ' register is $07
addr = %10110101 ' $B5 Binary value: %10110101
i2cwrite sda, scl, addr ' sends read command, shift the address B5, 8 bits where LSB is R = 1, clock idles low
i2cread SDA, SCL,addr,reg,[temp.lowbyte,temp.highbyte] ' reg = $07
tempir = (temp.highbyte << 8) + temp.lowbyte
temperature = tempir/50 ' based on the manual we need to divide by 50 or 0.02
temperature = temperature - 273 ' subtract 273 for Degree in C,actually is 273,15
remainder = (tempir*2)//100 ' multiply x 2 and get the remainder //100
pause 100
gosub display
return
'------------------------------------------------------------------------------*
' IR Display 1 the parameters *
'------------------------------------------------------------------------------*
display: ' IR TEMP
hserout2 [$73,$00,$02,$12,$00,$ff,"IR TEMP:",00]
Hserin2 timeout,error,[wait(6)]
hserout2 [$73,$08,$02,$12,$F8,$00,dec2 temperature,".",dec2 remainder,"*C",00] 'this one works on display 1 which doesnt require CS
Hserin2 timeout,error,[wait(6)]
gosub checksum2
hserout [$01,$0F,$00,temperature,remainder,IRCS] ' this one doent work, i get random numbers on the display.
Hserin timeout,error,[wait(6)]
return
'------------------------------------------------------------------------------|
' CHECKSUM IR |
'------------------------------------------------------------------------------|
checksum2:
IRCS = 0
IRCS = $01 ^ $0F ^ $00 ^ temperature
IRCS = IRCS ^ remainder
return
One i do the CS calculation, and returning from checksum2 the following is not working as expectred.
Code:
hserout [$01,$0F,$00,temperature,remainder,IRCS] ' this one doent work, i get random numbers on the display.
Hserin timeout,error,[wait(6)]
return
even if i try the following.
Code:
hserout [$01,$0F,$00,dec2 temperature,dec remainder,IRCS] ' this one doent work, i get random numbers on the display.
Hserin timeout,error,[wait(6)]
return
Is there a way to convert the variable to string ourside from a preset command like the HSEROUT?
for example is there a way to make something like this in PBP?
temperature = #temperature.
Bookmarks