Maybe your going the wrong way. You could convert the a/d reading to a ASCII string and then compare with the user's string. One way would be to have 6 bytes to calculate the a/d value (work bytes). The high order work byte will contain the 100's digit from the a/d. Second byte 10's, third byte units. The forth byte tenth's, fifth hundredths and sixth byte thousand's. You will not compare the thousand's digit but it will keep from having too great of round off errors. Then test each bit in a/d reading. If bit set, add the 6 decimal values to the 6 work bytes. They will accumulate a value for each digit. This value will not overflow into higher order byte as you will be adding at most the value of 9 each time and you will be doing it at most 10 times. So maximum value is 90 or less. After checking each of the 10 or 8 bits of the a/d and adding the correct values to each byte of the work bytes, go through each testing for greater than 9. If it is, subtract 10 from it, increment the next higher byte and test the same byte again. When done all six bytes, just ignore the sixth or thousand's byte, it's served it's purpose and set a couple of bits to convert each byte to ASCII digit. Or convert the user ASCII character string to 5 decimal bytes for comparison. You will need to calculate the conversions for each a/d bit to use in the pic program, but a pc program or spread sheet could do this. If you wanted to get fancy, write a pc program to write that part of the code for you. Bill ----- Original Message ----- From: "Andrew Warren" To: "Microcontroller discussion list - Public." Sent: Wednesday, November 30, 2005 3:02 AM Subject: Re: [PIC] Convert ASCII string to variable for comparison > 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 -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist