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

The same old float printf problem
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hadeelqasaimeh



Joined: 05 Jan 2006
Posts: 105

View user's profile Send private message

PostPosted: Tue Mar 27, 2007 5:59 pm     Reply with quote

thank you
i will try now
hadeelqasaimeh



Joined: 05 Jan 2006
Posts: 105

View user's profile Send private message

PostPosted: Wed Mar 28, 2007 4:33 am     Reply with quote

oh my god ,,each time i find new proplem
first of all here is a test code:


Code:
#include <16f877a.h>
#include <string.h>
#fuses xt,NOWDT,NOLVP
#use delay(clock=4000000)
#include <stdlib.h>
#include <ftoa_ts.c>
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

static char RX[15] ,MX[10],S1[20],S2[20], buffer[20];
float value;
char prec, format;
int8 i,j;

void main() {

      prec=0;
      format='f';
      strcpy(RX,"1111");
      strcpy(MX,"2222");
      strcpy(S1,"*");
      strcpy(S2,"#");


      value=22;

while (1)
{/      putc('A');
      delay_ms(1000);

      ftoa(value, buffer, prec, format);
      putc('B');
      delay_ms(1000);

      strcat(S1,RX);
      putc('C');
      delay_ms(1000);

      strcat(S1,MX);
      putc('D');
     delay_ms(1000);

      strcat(S1,S2);
      putc('E');
      delay_ms(1000);


      strcat(S1,buffer);
      putc('F');
     delay_ms(1000);




}}


i see the output on hyperterminal as the following:

Quote:
ABCDEFABCDEFABCD
then lock up

also i try the following:
Code:
#include <16f877a.h>
#fuses XT, NOWDT, PUT, BROWNOUT, NOLVP
#use delay(clock=4000000)
//#include "lcd_kbd1.c"
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#include <stdlib.h>
#include <ftoa_ts.c>

//============================
void main()
{
float f;
char buffer[30];
char prec;
char format;

float f1 = 1;

     [color=red] prec = 1;[/color]
      format = 'f';

    while (TRUE)
{
      ftoa(f1, buffer, prec, format);

   printf("%s",buffer);
   delay_ms(1000);
      f1=f1 + 2;


}
}


output:
Quote:


1.0
3.0
5.0
7.0
9.00
11.0
13.000.0
13.0
15.013.0
15.013.0
14.9
17.0
19.0
21.0
23.0
25.0


as u see there is error

i need to get large numbers
so i change the following

Code:
float f1 = 11111;

      prec = 0;

and
Code:
      f1=f1 + 11111;

output was
Quote:
11111
22221
33267
]‹++0
55405
64666
77777
88888
99999
111110


other sample
Quote:
288886
299997
311107
322219
333330
344441
003
ھ
366663
377774
388885
399996
411107

other sample:
Quote:
955546
966657
977768
988879
999990
1011101
1022212
1033323
1044433
1055545


after all this i try other way
Code:
#include <16f877a.h>
#include <string.h>
#fuses xt,NOWDT,NOLVP
#use delay(clock=4000000)
#include <stdlib.h>
#include <ftoa_ts.c>
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

static char RX[15] ,MX[10],S1[20],S2[20], buffer[20];
int16 value;
//char prec, format;
int8 i,j;

void main() {
   value= 1;
   strcpy(S1,"#\r\n");
while(1) {
    delay_ms(100);
    //printf("*1$&","%04.3w",value,"#\r\n");
         printf("%6.3f *1$&",value,"%s ",S1);

  // printf("%04.3f",value*1.2207E-3);
   value= value+3;
   delay_ms(1000);
}}



i want to get value and send:
Quote:


*1$&value#


and then recieve it on other pic and get it a gain

sorry Embarassed
hadeelqasaimeh



Joined: 05 Jan 2006
Posts: 105

View user's profile Send private message

PostPosted: Wed Mar 28, 2007 4:35 am     Reply with quote

http://www.ccsinfo.com/forum/viewtopic.php?p=78127&sid=26670b91d4d566859412fb1f7a93a5e4

i use this link
PCM programmer



Joined: 06 Sep 2003
Posts: 21414

View user's profile Send private message

PostPosted: Wed Mar 28, 2007 11:44 am     Reply with quote

What's your compiler version ? I copied and pasted your test program
into MPLAB and compiled it first with vs. 3.249 and then with vs. 4.030.
I ran it in the MPLAB simulator, and used 'UART1' to display the results
in the Output Window. I added a '\r' to your printf statement, to get
each number displayed on a new line. It worked absolutely perfectly.
Quote:

1.0
3.0
5.0
7.0
9.0
11.0
13.0
15.0
17.0
19.0
21.0
23.0
25.0
27.0
29.0
31.0
33.0
etc.

Post your compiler version.
hadeelqasaimeh



Joined: 05 Jan 2006
Posts: 105

View user's profile Send private message

PostPosted: Wed Mar 28, 2007 3:42 pm     Reply with quote

version 3.249
PCM programmer



Joined: 06 Sep 2003
Posts: 21414

View user's profile Send private message

PostPosted: Wed Mar 28, 2007 3:56 pm     Reply with quote

I installed PCM vs. 3.249. I copied and pasted your program into an
MPLAB project. I added one line, to do a carriage-return/linefeed after
displaying the string. I compiled and programmed it into a 16F877A
on my PicDem2-Plus board. It works. I let it run for a few minutes
while I was typing this in, and it never fails. It always works.

I suggest that you re-install your compiler. I can't really help any more.

Here is the output, displayed in a terminal window on my PC:
Quote:

1.0
3.0
5.0
7.0
9.0
11.0
13.0
15.0
17.0
19.0
21.0
23.0
25.0
27.0
29.0
31.0

Here is the test program:
Code:

#include <16f877a.h>
#fuses XT, NOWDT, PUT, BROWNOUT, NOLVP
#use delay(clock=4000000)
//#include "lcd_kbd1.c"
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#include <stdlib.h>
#include <ftoa_ts.c>

//============================
void main()
{
float f;
char buffer[30];
char prec;
char format;

float f1 = 1;

prec = 1;
format = 'f';

while (TRUE)
  {
   ftoa(f1, buffer, prec, format);

   printf("%s",buffer);
   printf("\n\r");   // Added this line.

   delay_ms(1000);
   f1=f1 + 2;
  }
}
hadeelqasaimeh



Joined: 05 Jan 2006
Posts: 105

View user's profile Send private message

PostPosted: Wed Mar 28, 2007 4:19 pm     Reply with quote

i will try
thank you
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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