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

How to Print binary as decimal fraction

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



Joined: 24 Sep 2009
Posts: 3
Location: Buffalo, NY

View user's profile Send private message

How to Print binary as decimal fraction
PostPosted: Thu Sep 24, 2009 6:49 pm     Reply with quote

Hi all,

I'm working on PIC18f2620 + CS5463 (power monitor). I saw some posts regarding CS5463 spi. In CS5463 registers, some values are 0<Vrms(for eg.)<1. These are 24 bit registers. I can read these values well and good into the processor. I'm using pic18f2620 with MPLAB IDE +CCS version 4.3.

Is there a way I can use some printf method to get the decimal fraction? or some usable format? Or should I do bit by bit 2^i thing?

To be more clear, lets say I read 0xC00000 from Vrms register. This is 0b110000000000000000000000. I need to convert it to 0.75.

Appreciate any help in advance.
Avarachan
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Sep 24, 2009 7:19 pm     Reply with quote

The simple way, conceptually, is just to do a division. The program
below has this output:
Quote:
0.75

Code:

#include <18F452.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//======================================
void main(void)
{
int32 value;
float result;

value = 0xC00000;

result =  (float)value / 0x1000000;

printf("%4.2f \r", result);


while(1);
}
 

I'm assuming that your value is an unsigned number.
avarachan



Joined: 24 Sep 2009
Posts: 3
Location: Buffalo, NY

View user's profile Send private message

thanks
PostPosted: Fri Sep 25, 2009 9:49 am     Reply with quote

Thank you. I think i will use simple division. I was at a loss as the various registers have different binary point locations. Thanks, PCMProgrammer!
dsabatino



Joined: 29 Jan 2010
Posts: 2

View user's profile Send private message

CS5463 SPI help
PostPosted: Tue Feb 02, 2010 1:24 am     Reply with quote

Hello avarachan,

I am attempting to communicate with the CS5463 but I am having some difficulties getting my microcontroller to interface over the SPI. Could you please post your code so that I may see your working example? I am using the Atmega32 but I'm sure I would be able to port the code as needed.

Thank you very much!
Edson



Joined: 10 Mar 2011
Posts: 1
Location: Portugal

View user's profile Send private message

Re: How to Print binary as decimal fraction
PostPosted: Fri Mar 11, 2011 3:18 pm     Reply with quote

avarachan wrote:
Hi all,

I'm working on PIC18f2620 + CS5463 (power monitor). I saw some posts regarding CS5463 spi. In CS5463 registers, some values are 0<Vrms(for eg.)<1. These are 24 bit registers. I can read these values well and good into the processor. I'm using pic18f2620 with MPLAB IDE +CCS version 4.3.

Is there a way I can use some printf method to get the decimal fraction? or some usable format? Or should I do bit by bit 2^i thing?

To be more clear, lets say I read 0xC00000 from Vrms register. This is 0b110000000000000000000000. I need to convert it to 0.75.

Appreciate any help in advance.
Avarachan

Hi Avarachant
I'm not reading anything at all on CS5463. Is there any way you can send me the routine that you're using to initialize the CS5463?
_________________
Edson Teixeira
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