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 CCS Technical Support

floatin to byte using union

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



Joined: 02 Oct 2004
Posts: 1
Location: pune

View user's profile Send private message Send e-mail

floatin to byte using union
PostPosted: Sat Oct 02, 2004 6:32 am     Reply with quote

Hi,

I am doing serial communication between VC++ code and CCS code
using USART.

for float to byte conversion have used union.

union
{
unsigned char tmp_char[4];
float tmp_float;
} un_tmp_float;


VC++ code send value 12.5000 as 0,0,72,65

but for same value ccs code requires 0,0,72,130

where could be proble, and how to overcom?

thnaks,
sachin
Ttelmah
Guest







Re: floatin to byte using union
PostPosted: Sat Oct 02, 2004 8:18 am     Reply with quote

sachin wrote:
Hi,

I am doing serial communication between VC++ code and CCS code
using USART.

for float to byte conversion have used union.

union
{
unsigned char tmp_char[4];
float tmp_float;
} un_tmp_float;


VC++ code send value 12.5000 as 0,0,72,65

but for same value ccs code requires 0,0,72,130

where could be proble, and how to overcom?

thnaks,
sachin

The problem is that the float format is not the same in VC, as in CCS. Unfortunately, the sign bit is stored in a different location on the two formats, which then displaces the exponent. There have been routines posted here in the past, to move the required bits around. It is not hard to do in C, with a mask, and a shift. On the CCS format, the sign bit sits as the top bit of the third byte (in the order you show them), while in VC, the sign sits as the top bit of the last byte. On CCS, the 8bit exponent sits entirely in the last byte, while in VC, the top seven bits of this sit in the last byte, and then the bottom bit occupies the tp bit of the third byte. The VC format, is the IEEE tandard layout, but the CCS format, would be slightly quicker to code for, removing the need to extract the exponent from two bytes. I'd suspect this is why CCS went this way...

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Oct 02, 2004 11:25 am     Reply with quote

Quote:
I am doing serial communication between VC++ code and CCS code
using USART. For float to byte conversion have used union.

http://www.ccsinfo.com/forum/viewtopic.php?t=18460&highlight=floating+conversion
http://www.ccsinfo.com/forum/viewtopic.php?t=11691&highlight=floating+conversion
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