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

printf float doesn't work

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



Joined: 19 Jan 2010
Posts: 4

View user's profile Send private message

printf float doesn't work
PostPosted: Mon Mar 08, 2010 9:13 pm     Reply with quote

Good day, I have got this printf problem when I try simulating with Proteus.
Using pcwhd 4.084
Code:

#include <16f877a.H>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#define INTS_PER_SECOND 60     

long count;     

#int_rtcc                         
void clock_isr() {               
      ++count;
}

void main() {

   long start,diff;
   float dt;

   set_timer0(0);
   setup_counters( RTCC_INTERNAL, RTCC_DIV_256 | RTCC_8_BIT);
   enable_interrupts(INT_RTCC);
   enable_interrupts(GLOBAL);

   do {

      start=count;
      getc();
      diff=count-start;
      dt=(diff)/60;
      printf("%Ld %Ld %6.4f seconds.\n\r",count,start,dt);

   } while (TRUE);

}

For example, start=0, count=133;
the value dt should be 2.2166, but it only shows 2.
Did I miss something there?
Jerson



Joined: 31 Jul 2009
Posts: 122
Location: Bombay, India

View user's profile Send private message Visit poster's website

PostPosted: Tue Mar 09, 2010 7:23 am     Reply with quote

change this
Code:
      dt=(diff)/60;

to this
Code:

      dt=(float)diff/60;

and you'll get the result you want
kalman



Joined: 19 Jan 2010
Posts: 4

View user's profile Send private message

PostPosted: Tue Mar 09, 2010 8:25 am     Reply with quote

wow, thanks
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