|
|
View previous topic :: View next topic |
Author |
Message |
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
Trivial string problem |
Posted: Wed Jun 04, 2008 9:24 am |
|
|
In years of working with PICs and CCS I have never had to use strings until now. This code is almost verbatim from my beginning C primer. It prints "Hello Small_Strings" and "This is a quoted string" but it prints nothing for globalstring.
What am I doing wrong? Is it some peculiarity of PICs or CCS? I suspect I am not declaring the string correctly.
I am using PCW 3.242 with a PIC18F2585.
Code: | char globalstring[] = "This is a global string.";
void main() {
output_high(PWR_485);
fprintf(Gliderbus,"Hello Small_Strings\n\r");
while(1){
delay_ms(100);
fprintf(Gliderbus,"This is a Quoted String\n\r");
fprintf(Gliderbus,"%s", globalstring);
}
}
|
Output: Code: | Hello Small_Strings
This is a Quoted String
This is a Quoted String
This is a Quoted String
This is a Quoted String
This is a Quoted S....... |
_________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jun 04, 2008 10:11 am |
|
|
I installed vs. 3.242 and ran the following program in MPLAB Simulator.
It works. It displays this in the Output window:
Quote: |
Hello Small_Strings
This is a Quoted String
This is a global string.
|
Code: |
#include <18F2585.h>
#fuses INTRC_IO, NOWDT, PUT, BROWNOUT, NOLVP, NOPBADEN
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS, stream=Gliderbus)
char globalstring[] = "This is a global string.";
//==========================
void main()
{
fprintf(Gliderbus,"Hello Small_Strings\n\r");
delay_ms(100);
fprintf(Gliderbus,"This is a Quoted String\n\r");
fprintf(Gliderbus,"%s", globalstring);
while(1);
} |
|
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
Stranger & stranger... |
Posted: Wed Jun 04, 2008 12:23 pm |
|
|
Thanks PCM, but here is my output and the exact code I am now running, mostly your code with minimum changes for my hardware:
Quote: | Hello Small_Strings
This is a Quoted String
This is a Quoted String
This is a Quoted String
This is a Quoted String
This is a Quoted String
Thi |
Code: | #include <18F2585.h>
#fuses HS, NOWDT, PUT, BROWNOUT, NOLVP, NOPBADEN
#use delay(clock=8000000)
#define PWR_485 PIN_C3
#use rs232(baud=1200, xmit=PIN_C6, rcv=PIN_C7, ERRORS, stream=Gliderbus, enable=PIN_B3)
char globalstring[] = "This is a global string.";
//==========================
void main()
{
output_high(PWR_485);
fprintf(Gliderbus,"Hello Small_Strings\n\r");
while(1){
fprintf(Gliderbus,"This is a Quoted String\n\r");
fprintf(Gliderbus,"%s", globalstring);
delay_ms(100);
}
} |
I even ran it real slow (600 baud) to see if the global string was being overwritten. How can "Quoted String" print, but "global string" not print? _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jun 04, 2008 12:57 pm |
|
|
There's a problem with using the Enable pin with printf or fprintf in your
version of the compiler. This problem is fixed in later versions.
This thread discusses some work-arounds:
http://www.ccsinfo.com/forum/viewtopic.php?t=28433 |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed Jun 04, 2008 1:19 pm |
|
|
Wow, thanks! It would have taken me forever to find that. The work around is simple, almost elegant.
It is so good to find it's not pilot error _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
|
|
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
|