Does anyone know how I can receive a float from a PC down to my PIC (16f876). Does anyone have the code to do this by any chance???
Cheers,
Dave.
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
Posted: Thu Feb 24, 2005 7:28 am
Well as far as the transmission a float on the pc is just a number encoded as a fixed number of bytes. If the bytes are transmitted one by one as they will be via RS232 the PIC will receive the bytes.
Now the fun begins
The number must be decoded to a valid float for the PIC. The PIC uses an
international standard....The CCS manual shows the sign mantissa exponent layout. a byte recieved can be big endian or little endian so you'll have to watch for it. Also watch out for the placement of the byte in the output stream ( is it part of the exponent or the mantissa) Next if the float is from some microsoft products it may have the first bit of the mantissa jazzed up. In floating point binary the first bit of the mantissa is always a one. Now the softees knowing this sometimes stuff the sign bit in there switching it to represent a neg or sometimes a pos ( when it comes to jazz there are no standards) so you need to look at the first bit of the mantissa to see if it is always one.
Also watch for the exponent offset.
Start by trying powers of two 2 4 8 16 in float and see how they are coded. they should all be sign bit,1,0...0 ( Ex 22 zeros for CCS float) for the mantissa with only the exponent varying.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum