Shop OBEX P1 Docs P2 Docs Learn Events
Converting a digital temperature reading to ASCII values — Parallax Forums

Converting a digital temperature reading to ASCII values

corbydivercorbydiver Posts: 2
edited 2006-02-25 19:11 in BASIC Stamp
I am using a DS1822 digital thermometer with a BS2p Stamp. I am reading in the temperature using the code in the OWIN_OWOUT.bsp file (in the Reference Manual) as the basis for my code. I can read the temperature into a Word variable with one Byte that carries the magnitude of the temperature and the other Byte carries the sign of the value. The temperature can be displayed on the screen using the DEBUG command with the SDEC formatter. For my application, this temperature reading is part of an ASCII string that is output on a pin and saved (also as a string of ASCII bytes) to EEPROM for later retrieval. I can't figure out how to use the WRITE command (which does not allow formatters such as SDEC) to make an appropriate conversion. One byte can be converted into a "+" or a "-" from the 0 or 1 byte, respectively. The problem is with the other byte. Use 23 degrees as an example. One byte reads 0 (for positive) and the other reads 23. I need to convert the one byte containing a 23 to two bytes - one containing a 50 (ASCII "2") and the next a 51 (ASCII "3"). How do I do this? Am I approaching this the wrong way? I don't really care what method is used, I just need to be able to store the temperature value that is read in from the DS1822 as ASCII characters.

Comments

Sign In or Register to comment.