>2. MCHIP has some good divide/multiply routines in the app notes. Check >AN544. > >A GOTCHA: You may find that 8 bit unsigned integers leave a lot to be >desired when doing this calculation. I use the formula > >C = (f-32)*9/5 > >If you divide first, then multiply you'll truncate your result, giving an >error. But if you multiply first then divide, you'll exceed the >capabilities of 8 bit math. I always use 16 bit numbers when doing >temperature, and may need to use 16 bit signed integers when doing >temperatures. Math routines for signed 16 bit multiplication in Assembler >are out there, but they are hairy. This quickly leads one to the conclusion >that C is more appropriate than Assembler for doing any kind of math. I try to avoid signed arithmetics as much as possible - I offset all variables so that the most negative value corresponds to zero and then grows up. It is also advantageous for comparison to various limits and so. I remove the offset just before the numbers are displayed, transmitted or output other way. Say you need -40F..+100F, e.g. -40C..+38C. The offset variables Foff and Coff will stay in range 0..140 and 0..78 respectively. Now the formulas are: Foff = (Coff * 9) / 5 Coff = (Foff * 5) / 9 Of course the result in parenthesis is 16 bits, you need 8x8 unsigned multiply and 16/7 (or 16/8) unsigned divide routines. Just after all the arithmetics, subtract 40 from the result, if negative display minus sign and make the value positive. Josef -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]: PIC only [EE]: engineering [OT]: off topic [AD]: advertisements