View previous topic :: View next topic |
Author |
Message |
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
How to display IEEE 754 in RS232 |
Posted: Thu Aug 06, 2020 6:03 am |
|
|
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
|
|
Posted: Thu Aug 06, 2020 8:46 am |
|
|
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
|
|
Posted: Thu Aug 06, 2020 11:10 pm |
|
|
I get this result, IEEE 000000f0
I guess, for float 0.0123, IEEE hex is 0x3c4985f0 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 06, 2020 11:18 pm |
|
|
It has to be "lx", not "x". Then it will work. |
|
|
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
|
Posted: Thu Aug 06, 2020 11:56 pm |
|
|
perfect. Thanks!
Is it possible to display the value in binary format? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Fri Aug 07, 2020 1:28 am |
|
|
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);
}
|
|
|
|
|