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

Help with printf & PCH

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



Joined: 09 Jun 2004
Posts: 52

View user's profile Send private message

Help with printf & PCH
PostPosted: Tue Sep 20, 2005 7:15 pm     Reply with quote

I just migrated from a PIC 16F877A to a 18F4680, and programs didn't work, in the protions that wrote to a VFD display. I chassed it down to a problem when doing a printf with a float, where it clears my screen, or puts numbers in the wrong place.

If I take out the decimal point formatting of the "2.2%f", it does NOT clear the display & shows up in the correct position, and is (somewhat) acceptable.

Advice on how to achieve same results as with previous versions of CCS compilers will be appreciated.

CCS PCH C Compiler, Version 3.234
Code:


//   Fuel_x_1.c


#include <18f4680.H>
//#FUSES HS,NOPROTECT,NOWDT,NOBROWNOUT,NOLVP,NOCPD,NOWRT,DEBUG
#FUSES HS,NOPROTECT,NOWDT,NOBROWNOUT,NOLVP,NOCPD,NOWRT
#use delay(clock=10000000)
#use i2c(master,sda=PIN_C4,scl=PIN_C3,slow,force_hw)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) 

//#define   ICD2

#ifdef   ICD2
   #reserve 0x70,0xF0,0x170
   #reserve 0x1E5:0x1F0
#endif

////////////////////////////////////////////////////////////////////////////



#include "noritake_fms_3x.h"

float float_1;

//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
   
void main()
   {
   delay_ms(100);
   vfd_init();
   vfd_putc("\fFuel Management System");
   vfd_gotoxy(1,2);
   vfd_putc("Fuel_X_1.c");
   delay_ms(5000);
   vfd_putc("\fPrintf function");
   vfd_gotoxy(1,2);
   vfd_putc("line 2  ");
   delay_ms(3000);
   float_1 = 32.1234;
   printf(vfd_putc,"%2.2f",float_1);  <== CLEARS DISPLAY & WRONG POSITION
   
   }

//   Fuel_x_1.c


#include <18f4680.H>
//#FUSES HS,NOPROTECT,NOWDT,NOBROWNOUT,NOLVP,NOCPD,NOWRT,DEBUG
#FUSES HS,NOPROTECT,NOWDT,NOBROWNOUT,NOLVP,NOCPD,NOWRT
#use delay(clock=10000000)
#use i2c(master,sda=PIN_C4,scl=PIN_C3,slow,force_hw)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) 

//#define   ICD2

#ifdef   ICD2
   #reserve 0x70,0xF0,0x170
   #reserve 0x1E5:0x1F0
#endif

////////////////////////////////////////////////////////////////////////////



#include "noritake_fms_3x.h"

float float_1;

//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
   
void main()
   {
   delay_ms(100);
   vfd_init();
   vfd_putc("\fFuel Management System");
   vfd_gotoxy(1,2);
   vfd_putc("Fuel_X_1.c");
   delay_ms(5000);
   vfd_putc("\fPrintf function");
   vfd_gotoxy(1,2);
   vfd_putc("line 2  ");
   delay_ms(3000);
   float_1 = 32.1234;
   printf(vfd_putc,"%f",float_1); <<== OK display
   
   }




Thanks,
Steve
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 20, 2005 8:38 pm     Reply with quote

First thing, put a while(1); statement at the end of your program.
CCS puts a hidden sleep statement at the end of main(), and it's
better that you end your program in a way that you define, rather
than letting CCS do it.

2nd, your problem is caused by a bug in the CCS printf routine
for floating points. A few revisions ago, they tried to fix the
round-off bug. But they introduced new bugs, such as the one
you're seeing. The printf in your code is putting out a huge number
of space characters (0x20) before it prints the floating point value.

I think you should report this bug to CCS. I sent them several emails,
as each revision still had bugs in the printf floating point code.
Then they posted on their revisions page a revision that "will make
everybody happy". But even that one still has bugs. They didn't fix it.
So I just gave up. Maybe, if you send them an email with sample code,
and a full explanation, maybe they'll fix it ?

Here is demo program that shows a work-around for your problem.
Create a small routine that will filter out the leading spaces. Then feed
the output of your main printf statement to the filtered output routine.
Let the filter routine send chars to vfd_putc().
Code:

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

my_putc(char c)
{
if(c != 0x20)
   printf(vfd_putc, "%c", c);
   
}   

float float_1;

//=======================
void main()
{
float_1 = 32.1234;
printf(my_putc, "%2.2f",float_1);

while(1);
}
eyewonder300



Joined: 09 Jun 2004
Posts: 52

View user's profile Send private message

PostPosted: Tue Sep 20, 2005 9:00 pm     Reply with quote

Thanks, PCM. Your work-around seems to be working. I will send in a bug-report to CCS & maybe they can correct this.

Steve
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