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

Passing a string to a subroutine and parsing it....

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



Joined: 24 Apr 2014
Posts: 138

View user's profile Send private message

Passing a string to a subroutine and parsing it....
PostPosted: Fri May 01, 2015 1:09 pm     Reply with quote

Hi All,

I want to send a string to a subroutine like this:

Code:

Display_4D_Text("Hello World");


and then parse it character by character to send the data to a serially connected LCD module. So far, I have got it working.....

Code:

void Display_4D_Text(Char InString)
{
   int8 iIndex = 0;

// Here we send the character string command....
   fputc(0x00,LCD_Display);
   fputc(0x06,LCD_Display);

   for ( iIndex=0 ; iIndex<strlen(InString) ; iIndex++ )
   {
      fputc(InString[iIndex],LCD_Display);   
   }

//Here we tell the display 'that's it...'
   fputc(0x00,LCD_Display);   
}

Thanks,

Jack
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri May 01, 2015 1:55 pm     Reply with quote

Quote:
So far, I have got it working.....

I didn't see that it was working. Your code required a couple changes
to make it work, as shown in bold below.
Quote:

#include <18F4520.h>
#device PASS_STRINGS=IN_RAM
#fuses INTRC_IO, BROWNOUT, PUT, NOWDT
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS, stream=LCD_Display)

#include <string.h>

void Display_4D_Text(Char *InString)
{
int8 i;

for(i=0; i < strlen(InString); i++)
{
fputc(InString[i], LCD_Display);
}

}

//=================================
void main()
{
Display_4D_Text("Hello World");

while(TRUE);
}

I cut out that parts of your code that I didn't need for the test program,
and I simplified your index variable name.
JAM2014



Joined: 24 Apr 2014
Posts: 138

View user's profile Send private message

PostPosted: Fri May 01, 2015 2:19 pm     Reply with quote

Hi,

Sorry, that should have read:

Quote:

So far, I haven't got it working.....


I had tried adding the '*' previously, and figured it should have worked fine like that. What I missed was this:

Code:

#device PASS_STRINGS=IN_RAM


It's now working like a champ!

Thanks!!

Jack
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