> -----Original Message----- > From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behalf > Of alan smith > Sent: 13 May 2010 13:39 > To: Microcontroller discussion list - Public. > Subject: [PIC] converting C to F > > Processor is a 18F23K20 > > I've never had the requirement to do much math with a PIC, other than > simple divide by 2 or 4 (shifts), add and subtract > > So looking for a little help in implementing this > > temp_F = (temp_C * 9 / 5) + 32; > > The temp_C * 9 can be done with the MULLW instruction. Just not to sure > about the divide by 5 part? What range of input values do you need to cover? By adding an offset you can use a close approximation for your fractional calculation and spread the error out. e.g. temp_F = ( ( (temp_C * 205) + 112 ) >> 8 ) + 32 + temp_C This gives results accurate to within +-0.4 Fahrenheit over the range -50 to +200 degrees Celsius Mike ======================================================================= This e-mail is intended for the person it is addressed to only. The information contained in it may be confidential and/or protected by law. If you are not the intended recipient of this message, you must not make any use of this information, or copy or show it to any person. Please contact us immediately to tell us that you have received this e-mail, and return the original to us. Any use, forwarding, printing or copying of this message is strictly prohibited. No part of this message can be considered a request for goods or services. ======================================================================= -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist