|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
RS232 with float |
Posted: Tue Jul 05, 2005 12:45 am |
|
|
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
|
|
Posted: Tue Jul 05, 2005 2:24 am |
|
|
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. |
|
|
Ttelmah Guest
|
|
Posted: Tue Jul 05, 2005 3:57 am |
|
|
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
|
|
Posted: Wed Jul 06, 2005 7:33 am |
|
|
Thank you |
|
|
|
|
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
|