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

Maximum length of a string

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



Joined: 09 Sep 2003
Posts: 183
Location: Somewhere under water in the Great Lakes

View user's profile Send private message

Maximum length of a string
PostPosted: Fri May 13, 2005 4:42 pm     Reply with quote

PCWH version 3.212, PIC18F452

I am trying to create a fairly long string, then send it via RS 232 with a polled transmit routine. It appears that the output string from the sprintf() function is limited to 50 characters, even though my ram array for the string is much larger. I keep receiving a "String too long" error. Is this truly a limit of the compiler? I have looked around the CCS site and in the manual, but I can't find any specs on this type of limit. Anybody know where this info can be found?

Thanks in advance.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri May 13, 2005 5:00 pm     Reply with quote

With PCM vs. 3.224, I can use a string of up to 73 characters without
getting a "string too long" error. The following program compiled and
ran OK.

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

char array[90];

void main()
{

sprintf(array, "abcdefghijklmnopqrstuvwxzyABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789HelloWorld!");

printf("%s", array);

while(1);
}
Charlie U



Joined: 09 Sep 2003
Posts: 183
Location: Somewhere under water in the Great Lakes

View user's profile Send private message

PostPosted: Fri May 13, 2005 7:59 pm     Reply with quote

Ok, let's try again. Sorry for the edits, but I had an intermediate compile the worked when I thought that it hadn't, so I deleted the previous version of this post.

This does not work:

Code:
#include <18F452.h>
#use delay(clock=10000000)
#fuses NOWDT,WDT128,HS, NOPROTECT, NOOSCSEN, NOBROWNOUT, BORV20, NOPUT, \
   NOSTVREN, NODEBUG, NOLVP, NOWRT, NOWRTD, NOWRTB, NOWRTC, NOCPD, NOCPB, \
   NOEBTR, NOEBTRB
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors)

char string_buffer[100];

long int data[16];

void main()
{

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   
   sprintf(string_buffer, "%3lu,%3lu,%3lu,%3lu,%3lu,%3lu,%3lu,%3lu,\
         %3lu,%3lu,%3lu,%3lu,%3lu,%3lu,%3lu,%3lu",\
         data[0], data[1], data[2], data[3], data[4],data[5], data[6], \
         data[7], data[8], data[9], data[10], data[11], data[12], \
         data[13], data[14], data[15]);
   while (1)
   {
      ;
   }

}


It should only be 64 bytes long shouldn't it?

If I delete some of the data to reduce the string to less than 50 bytes, then it works:

Code:

#include <18F452.h>
#use delay(clock=10000000)
#fuses NOWDT,WDT128,HS, NOPROTECT, NOOSCSEN, NOBROWNOUT, BORV20, NOPUT, \
   NOSTVREN, NODEBUG, NOLVP, NOWRT, NOWRTD, NOWRTB, NOWRTC, NOCPD, NOCPB, \
   NOEBTR, NOEBTRB
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors)

char string_buffer[100];

long int data[16];

void main()
{

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   
   sprintf(string_buffer, "%3lu,%3lu,%3lu,%3lu,%3lu,%3lu,%3lu,%3lu,\
         %3lu,%3lu,%3lu,%3lu",\
         data[0], data[1], data[2], data[3], data[4],data[5], data[6], \
         data[7], data[8], data[9], data[10], data[11]);
   while (1)
   {
      ;
   }

}


But this version does work:

Code:

#include <18F452.h>
#use delay(clock=10000000)
#fuses NOWDT,WDT128,HS, NOPROTECT, NOOSCSEN, NOBROWNOUT, BORV20, NOPUT, \
   NOSTVREN, NODEBUG, NOLVP, NOWRT, NOWRTD, NOWRTB, NOWRTC, NOCPD, NOCPB, \
   NOEBTR, NOEBTRB
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors)

char string_buffer[100];

long int data[16];

void main()
{

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   
   sprintf(string_buffer, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,\
         %lu,%lu,%lu,%lu",\
         data[0], data[1], data[2], data[3], data[4],data[5], data[6], \
         data[7], data[8], data[9], data[10], data[11]);
   while (1)
   {
      ;
   }

}



But this one doesn't:
Code:

#include <18F452.h>
#use delay(clock=10000000)
#fuses NOWDT,WDT128,HS, NOPROTECT, NOOSCSEN, NOBROWNOUT, BORV20, NOPUT, \
   NOSTVREN, NODEBUG, NOLVP, NOWRT, NOWRTD, NOWRTB, NOWRTC, NOCPD, NOCPB, \
   NOEBTR, NOEBTRB
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors)

char string_buffer[100];

long int data[16];

void main()
{

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   
   sprintf(string_buffer, "%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,\
         %lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu",\
         data[0], data[1], data[2], data[3], data[4],data[5], data[6], \
         data[7], data[8], data[9], data[10], data[11], data[12], data[13], \
         data[14], data[15]);
   while (1)
   {
      ;
   }

}


AaaaaaaaaaaahhhhhhhhhHH?!?!?!?!?!?!?!?!?!?
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