HEX byte to ASCII output...
Hello,
I am using the Dallas 18S20 to measure temperature. My code is working and I can display the decimal temp on the LCD screen.
My problem is:
The 18S20 provides the temp in HEX (example. $31), I convert that to decimal 49. I then divide 49 by 2 and obtain the temprature of 29degs C.
I need to transmit the "2" and "9" in ASCII. How do I strip the "2" and "9" from the decimal byte 29 in (INTTEMP.LOWBYTE / 2)....? :confused:
INTERNALTEMP:
OWOut DQI,1,[$CC,$44] 'REQUEST FOR INT TEMP AD CONVERSION
PAUSE 750 'WAIT FOR CONVERSION TO COMPLETE
OWOut DQI,1,[$CC,$BE] 'REQUEST XMIT OF TEMP DATA
OWIn DQI,0,[INTTEMP.LOWBYTE,INTTEMP.HIGHBYTE] 'REC TEMP DATA
Lcdout $fe, 1, DEC INTTEMP.HIGHBYTE, " ", DEC (INTTEMP.LOWBYTE / 2)
GOTO INTERNALTEMP
end
Thanks,
John
Re: HEX byte to ASCII output...
Probably a better way...
To strip out place values
code snip from project with four digits.
Code:
C_THOS = TempC / 1000
C_HUNS = (TempC - C_THOS * 1000) /100
C_TENS = (TempC-((C_THOS * 1000) + (C_HUNS * 100)))/10
C_ONES = TempC - ((C_THOS * 1000) + (C_HUNS * 100)+ C_TENS * 10)
Then convert to..
Again, snipped from a project using an array.
Code:
FAT_src[40] = $30+C_THOS
FAT_src[41] = $30+C_HUNS
FAT_src[42] = $30+C_TENS
FAT_src[43] = $30+C_ONES
Does that help?
Re: HEX byte to ASCII output...
Quote:
Originally Posted by
mackrackit
Does that help?
Yes it does...thank you!
John
Re: HEX byte to ASCII output...
Works great now!
Code:
INTERNALTEMP:
OWOut DQI,1,[$CC,$44] 'REQUEST FOR INT TEMP AD CONVERSION
PAUSE 750 'WAIT FOR CONVERSION TO COMPLETE
OWOut DQI,1,[$CC,$BE] 'REQUEST XMIT OF TEMP DATA
OWIn DQI,0,[INTTEMP.LOWBYTE,INTTEMP.HIGHBYTE] 'REC TEMP DATA
IF INTTEMP.HIGHBYTE = $00 THEN INTTEMPSIGN = 43 'CHECK HIGHBYTE SET SIGN +
IF INTTEMP.HIGHBYTE = $FF THEN INTTEMPSIGN = 45 'CHECK HIGHBYTE SET SIGN -
IF INTTEMP.HIGHBYTE = $FF THEN INTTEMP.LOWBYTE = ($FF - INTTEMP.LOWBYTE) 'INVERT LOWBYTE FOR NEG
INTTEMP.LOWBYTE = INTTEMP.LOWBYTE / 2 'DIV BY 2 FOR DEGREES C
INTC_TENS = INTTEMP.LOWBYTE / 10 'CALC TENS DIGIT
INTC_ONES = INTTEMP.LOWBYTE - (INTC_TENS * 10) 'CALC ONES DIGIT
INTTX(1) = $30 + INTC_TENS 'CONVERT TO ASCII
INTTX(2) = $30 + INTC_ONES 'CONVERT TO ASCII
GOTO INTERNALTEMP
end
Re: HEX byte to ASCII output...
John,
The sensor has .5 degree resolution. You can store INTTEMP.LOWBYTE into a NEW VAR of length WORD then multiply the new variable by 5. In your example 49 X 5 is 245. HEX "31" actually represents +24.5 degrees C. Use "DIG" to isolate the digits of the NEW VAR WORD. WORD size is suitable because the maximum of INTTEMP.LOWBYTE is HEX "AA", 170 X 5 = 850 which represent +85.0 degrees C.
- Martin
Re: HEX byte to ASCII output...
Hi Martin,
Thanks for the DIG tip. That eliminates all that math.
Yes, I know I can get the .5 resolution, but I don't need it for this simple project. But, that doesn't mean I won't incorporate it in my code sometime in the future.
Thank again....
John