How can you substitute a string on USART output?

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Francesco.C
Posts: 41
Joined: Thu Feb 26, 2009 6:54 pm
Location: UK

How can you substitute a string on USART output?

Post by Francesco.C » Wed Aug 24, 2011 10:29 pm

Hi guys,

I have a serial device connected to the PIC USART. This devive expects commands that are very short and have no real meaning.

For example; the command to litght-up a digit is 'bn0'.
This has no real meaning and i would like to substitute it with 'Digit0'.
So that when i send 'Digit0' over the USART it will transmit insted 'bn0'.

Is this possible?


I started to think something like;

#Define bn0 = Digit0

But when i do; USART.Write(Digit0), i encounter errors for obvious rasons.

Can you help please?

Regards

Francesco

Doj
Posts: 362
Joined: Wed Apr 11, 2007 10:18 pm
Location: East Sussex

Post by Doj » Wed Aug 24, 2011 11:25 pm

Hello Francesco,

I think the issue is that USART will be a STRING so the define may need to be:-

#define Digit0 = "bn0"

USART.Write(Digit0)

I have no hardware to test it but this seems the logical method to me.

Mark

User avatar
octal
Registered User
Registered User
Posts: 586
Joined: Thu Jan 11, 2007 12:49 pm
Location: Paris IDF
Contact:

Post by octal » Wed Aug 24, 2011 11:46 pm

what about simply using constant strings:

Code: Select all

const Digit0 ="bn0"

//... and in your code 

USART.Write(Digit0)  // will now send the string "bn0"


Francesco.C
Posts: 41
Joined: Thu Feb 26, 2009 6:54 pm
Location: UK

Post by Francesco.C » Thu Aug 25, 2011 5:59 pm

Thank you octal,
your code works fine.

I will read a little more about constants now.

Regards

Francesco

Post Reply