CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

RS232 with float

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








RS232 with float
PostPosted: Tue Jul 05, 2005 12:45 am     Reply with quote

I want to send the floating point variable with help of pic to PC or PC to PIC. First of all we think that to pc to pic.

getch(); function takes char. otherwise pc send 4 byte data for 1 float variable. how can re -organize the this 4 bytes data taken by getch to obtain the correct FLOAT variable(that is sended by PC)
PICoHolic



Joined: 04 Jan 2005
Posts: 224

View user's profile Send private message

PostPosted: Tue Jul 05, 2005 2:24 am     Reply with quote

CCS uses the same format Microchip uses in the 14000 calibration constants. PCW users have a utility PCONVERT that will provide easy conversion to/from decimal, hex and float in a small window in Windows. See EX_FLOAT.C for a good example of using floats or float types variables.

A float is a 4-byte number:
- byte 1 is the exponent
- MSB of byte 2 is the sign bit
- the remainig 23 bits are the Mantisa

So, you can get those 4 bytes and decode them.

Good Luck. Very Happy
Ttelmah
Guest







PostPosted: Tue Jul 05, 2005 3:57 am     Reply with quote

Fortunately, it is all done for you.
The PIC format, and the single precision IEEE format, have all the parts the same size, but just re-ordered slightly in the four bytes. In the 'Drivers' directory, there is a little file called 'ieeefloat.c', which can be included in any PIC program, and contains definitions for two functions 'f_PICtoIEEE', and 'f_IEEEtoPIC', which reorganise the contents of a four byte float, between the two systems.
Declare a union, containing four bytes, a float, and an int 32. for serial input, read the four bytes into the four element byte array in this, then 'hand' the int32 to 'f_IEEEtoPIC, and it'll return a PIC float to work with. Going the other way, hand a PIC float to f_PICtoIEEE, and it'll return an INT32 that you can put into the same union, then you jus output the four bytes to the PC.
If your compiler is very old, you may not have this file, but almost identical code has been posted in the past (I have posted one version), which should be available in the archives.

Best Wishes
sraiderk



Joined: 09 Feb 2005
Posts: 48

View user's profile Send private message

PostPosted: Wed Jul 06, 2005 7:33 am     Reply with quote

Thank you Smile
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group