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

Having troubles with printf

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







Having troubles with printf
PostPosted: Thu Nov 03, 2005 4:56 pm     Reply with quote

Hello,
I have problem with printf. Can someone help me ?

here is the code :

const char hello_world[] = {"hello world"};
char ramstr[30];

printf ("hello world"); // that works

strcpy(ramstr,hello_world);
printf(ramstr); // that doesn't work
printf("%s",ramstr); // that doesn't work

memcpy(ramstr,hello_world,12);
printf(ramstr); // that doesn't work
printf("%s",ramstr); // that doesn't work

Thank you.
Marc.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 03, 2005 8:39 pm     Reply with quote

There are no pointers to constant strings in CCS.

The code below will work.
Code:

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

char ramstr[30];

//============================
void main()
{
strcpy(ramstr, "Hello World");

printf("%s", ramstr);

while(1);
}
gazalou
Guest







having trouble with printf
PostPosted: Fri Nov 04, 2005 1:37 am     Reply with quote

thank you "PCM PROGRAMER"

but still doesn't work.

here is another working example :

i=1;
printf("hello world %d time",i);

I'm using PCH on a 18f8720 may i have trouble with string.h ?
Foppie



Joined: 16 Sep 2005
Posts: 138
Location: The Netherlands

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

Re: having trouble with printf
PostPosted: Fri Nov 04, 2005 2:11 am     Reply with quote

gazalou wrote:
I'm using PCH on a 18f8720 may I have trouble with string.h ?

As far as I know, you don't need string.h for the code PCM prgogrammer gave you. He would have put it in his examplecode.

Instead of the const, can't you use a define?
Code:
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#define hello_world "Hello World!"

char ramstr[30];

//============================
void main()
{
printf ("hello world");

strcpy(ramstr,hello_world);
printf(ramstr);
printf("%s",ramstr);

memcpy(ramstr,hello_world,12);
printf(ramstr);
printf("%s",ramstr);

while(1);

}
Gazalou
Guest







Problem with printf
PostPosted: Mon Nov 07, 2005 10:03 am     Reply with quote

Hello,

Still digging with my problem of printf.

When I use rs232 WITHOUT using enable pin

printf ("hello world");
strcpy(ramstr,"hello world");
printf("%s",ramstr);

I get Two corrects "hello world".


When I use rs232 WITH using enable pin=G0 on 18f8720

printf ("hello world");
strcpy(ramstr,"hello world");
printf("%s",ramstr);

I get only one "hello world" ( the first one ), and the final "d" of the second.

What I mean is that printf always sends the correct data ( checked on a oscilloscope) And the enable pin is correctly managed only with "immediate" strings ( Also checked on oscilloscope ).

I use serial #2 of the 18f8720 (rxd=pin_G2, txd=Pin_G1, enable=Pin_G0). other pins of port G aren't used.

Can someone help me ?
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Mon Nov 07, 2005 2:48 pm     Reply with quote

Enable doesn´t have any conexion with the problem you mention, unless you are using RS485.

#use RS232 Option ENABLE means that the selected pin (PIN_G0) goes High during transmision only.
It is used to handle the Tx_Enable in RS485 transceivers.


Humberto
Gazalou
Guest







Problem with printf
PostPosted: Mon Nov 07, 2005 3:24 pm     Reply with quote

Thanks Humberto,

But I'm using Rs485 !

What I wanted to say is that all the printf's go out from the tx pin but in some cases the enable pin seems not to work.

If I do printf(hello world") I can see the enable pin "enabling the rs-485 transceiver" for each character.

If I do printf("%s",memorystring) the enable pin won't work for all character.

regards
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 07, 2005 3:40 pm     Reply with quote

Quote:
in some cases the enable pin seems not to work.

This thread has a work-around:
http://www.ccsinfo.com/forum/viewtopic.php?t=4843
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