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

How to display IEEE 754 in RS232

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



Joined: 03 Oct 2012
Posts: 242
Location: chennai

View user's profile Send private message

How to display IEEE 754 in RS232
PostPosted: Thu Aug 06, 2020 6:03 am     Reply with quote

How to display the IEEE in RS232

Code:
#include "18F2520.h"
#fuses HS
#use delay(clock=12000000)

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#include "ieeefloat.c"

float f;
int32 PCval;
int8 *p;

void main()
{
   while(1)
   {
      f = 0.0123;
      PCval=f_PICtoIEEE(f);
      printf("IEEE %Ld",PCval);

      printf("\n\r");
      delay_ms(1000);
   }
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Thu Aug 06, 2020 8:46 am     Reply with quote

Display how?.

If you want to print the fp value, then don't. Just print your variable 'f'.
If you want the hex values that the IEEE representation has, then just
print with &08x:

printf("IEEE %08x",PCval);

This then gives the hex digits corresponding to the IEEE value.
hemnath



Joined: 03 Oct 2012
Posts: 242
Location: chennai

View user's profile Send private message

PostPosted: Thu Aug 06, 2020 11:10 pm     Reply with quote

I get this result, IEEE 000000f0

I guess, for float 0.0123, IEEE hex is 0x3c4985f0
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 06, 2020 11:18 pm     Reply with quote

It has to be "lx", not "x". Then it will work.
hemnath



Joined: 03 Oct 2012
Posts: 242
Location: chennai

View user's profile Send private message

PostPosted: Thu Aug 06, 2020 11:56 pm     Reply with quote

perfect. Thanks!

Is it possible to display the value in binary format?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 07, 2020 1:13 am     Reply with quote

Here is a routine to display a byte in binary format:
http://www.ccsinfo.com/forum/viewtopic.php?t=1523&start=1
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Fri Aug 07, 2020 1:28 am     Reply with quote

Binary!...

You do realise you'll have 32bits for each number. Not exactly convenient to
do anything with....
You'd have to generate your own binary output routine. Not exactly hard:
Code:

void binary(unsigned int32 value)
{
    unsigned int32 mask=0x80000000;
    do {
        if (mask & value)
            putc('1');
        else
            putc('0');
        mask/=2;
    } while (mask!=0);
}
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