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

printf a floating #

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



Joined: 09 Sep 2003
Posts: 52

View user's profile Send private message MSN Messenger

printf a floating #
PostPosted: Thu Sep 02, 2004 2:56 pm     Reply with quote

I have the PIC Demo 2 Plus and I write the code to measure a ADC channel as voltage and display it on the LCD as floating. I only want to print 2 #s after the decimal point only. I know that in C, if you print 2 #s after the decimal point is to put a . between the % and f. But it does not work for CCS. Its there anything I missing?

Here is my code:

Code:

/////////////////////////////////////////////////////////////////////////
////                          EX_TC74.C                             ////
////                          I2C serial concept                     ////
////  This program uses the TC74 TO-220-5 to                     ////
////  read the temperature for the sensor.                          ////
////                                                                 ////
////               TC74 pin        Processor                          ////
////                  1            n/a   NC                           ////
////                  2            23   RC3      SDA                  ////
////                  3            n/a   gnd                          ////
////                  4            18   RC3       SCL                  ////
////                  5            n/a   VDD                           ////
////                                                                 ////
/////////////////////////////////////////////////////////////////////////


#include <18f458.h>
#device ADC=10
#fuses XT,NOWDT,NOPROTECT,NOLVP

#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) 
#use i2c(Master,fast,sda=PIN_C4, scl=PIN_C3, FORCE_HW)
#include <lcdd.c>


main()
{
byte value,temp;
int16 bat_value;
float batt;

lcd_init();

setup_adc_ports( RA0_ANALOG );
setup_adc( ADC_CLOCK_INTERNAL );
while(1)
   {
     set_adc_channel( 0 );
      delay_us(25);
      bat_value = read_adc();
     batt = bat_value * (float) 0.00488;
      printf(lcd_putc,"\nBattery: %.2f V",batt);
     delay_ms(100);
       
      i2c_Start();                                          // Set a START condition I2C Bus
      i2c_Write(0b10011010);                                // Address and Write Flag
      i2c_Write(0x00);                                      // Temperature Register
      i2c_Start();                                          // Set a START condition I2C Bus
      i2c_Write(0b10011011);                                // Address and Read Flag
      value = i2c_Read();                                   // Read Teperature
      i2c_stop();
     delay_ms(5);   
    
     temp = value * 9/5 + 32;
     printf("Temp: %d Degree\n\r",temp);
     printf(lcd_putc,"\fValue: %d Degree",temp);

    
    
     if(value < 21)
      {
         output_high(PIN_B0);
         output_low(PIN_B0);
      }
      else
      {
         output_high(PIN_B1);
         output_low(PIN_B0);
      }
   }


}






The error message ( printf format % is invalid).

Please help.
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

Like Prego, its in there...
PostPosted: Thu Sep 02, 2004 3:15 pm     Reply with quote

Doesn't ANYONE read the manual any more??

Taken from page 125 for Printf():

The format takes the generic form %wt where w is optional and may be 1-9 to specify how many characters are to be outputted, or 01-09 to indicate leading zeros or 1.1 to 9.9 for floating point. t is the type and may be one of the following:
C Character
S String or character
U Unsigned int

etc...
cxiong



Joined: 09 Sep 2003
Posts: 52

View user's profile Send private message MSN Messenger

PostPosted: Fri Sep 03, 2004 7:25 am     Reply with quote

I just download the manual from CCS. It does cover the topic I ask for.

Thanks.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Fri Sep 03, 2004 7:58 am     Reply with quote

The CCS manual is fairly small and if you are going to do any serious work it is worth reading cover to cover. You will discover lots of things you never thought to ask for!
_________________
The search for better is endless. Instead simply find very good and get the job done.
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