Jinx wrote: > A temperature sensor has a 0-12V o/p, spanning the range 0C to 40C. > The user sends the PIC "G20.58", meaning "alert me when the > temperature goes over 20.58 degrees" > > Now there are two things to consider. First is the 5:12 scaling > of the input, second is converting the "20.58" to a variable that can > be compared to the A2D > > I've tried a few things long-hand and wonder if there's a generic way > of doing it Ok... If you just wanted to convert from ASCII to decimal (and if you didn't have to check the string for conformance to your syntax), you would: 1. Point at the rightmost character. 2. MULTIPLIER = 1. TOTAL = 0. 3. Grab the character at which we're pointing. If it's a "G" (or "E" or "L" or whatever), exit. 4. Otherwise, if it's a decimal point, divide TOTAL by MULTIPLIER, set MULTIPLIER = 1, and go to step 7. 5. Otherwise, convert the character from ASCII to a decimal number, multiply it by MULTIPLIER, and add it to TOTAL. 6. MULTIPLIER = MULTIPLIER * 10. 7. Move your pointer one character leftward, then go to step 3. That process would convert your "G20.58" to the number 20.58 (in whatever format you've chosen to represent non-integers)... But YOU want to convert it to a number that takes into account the ADC scaling, so for your particular case (temperature sensor reads 0-40C and max ADC value is 255), you'd change step 5 to read: 5. Otherwise, convert the character from ASCII to a decimal number, multiply it by MULTIPLIER * 255/40, and add it to TOTAL. With that change, you'd get: CHARACTER MULTIPLIER TOTAL 1 0 8 1 8 * 1 * 255/40 = 51 5 10 51 + 8 * 10 * 255/40 = 369.75 . 100 369.75/100 = 3.6975 0 1 3.6975 + 0 * 1 * 255/40 = 3.6975 2 10 3.6975 + 2 * 10 * 255/40 = 131.1975 G 100 131.1975 So your ADC threshold is 131 or so. Is that what you wanted? -Andrew === Andrew Warren - fastfwd@ix.netcom.com -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist