|
|
View previous topic :: View next topic |
Author |
Message |
gazalou Guest
|
Having troubles with printf |
Posted: Thu Nov 03, 2005 4:56 pm |
|
|
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
|
|
Posted: Thu Nov 03, 2005 8:39 pm |
|
|
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 |
Posted: Fri Nov 04, 2005 1:37 am |
|
|
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
|
Re: having trouble with printf |
Posted: Fri Nov 04, 2005 2:11 am |
|
|
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 |
Posted: Mon Nov 07, 2005 10:03 am |
|
|
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
|
|
Posted: Mon Nov 07, 2005 2:48 pm |
|
|
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 |
Posted: Mon Nov 07, 2005 3:24 pm |
|
|
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
|
|
|
|
|
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
|