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

rs232 problem

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



Joined: 11 Nov 2016
Posts: 8

View user's profile Send private message Send e-mail

rs232 problem
PostPosted: Mon Aug 21, 2017 12:16 am     Reply with quote

We want to send data using rs232.

However receive device want to use following protocol:

ex ) we want to send '123'
send data (*HEX) : 31 32 33
** Each hex data must have space bar.

but printf () function in PCW,
actual send data (*HEX) : 313233

So receive device can't read anything.

How can i make space bar in our every sending data ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19553

View user's profile Send private message

PostPosted: Mon Aug 21, 2017 1:28 am     Reply with quote

Do it digit by digit.

You don't show us how the data is stored at the PIC end?.
However:
Code:

   int8 to_send=123;
   int8 ctr;
   char buffer[4];
   
   sprintf(buffer,"%03d", to_send);
   //buffer now has '123'
   for (ctr=0;ctr<3;ctr++)
   {
       printf("%02X ",buffer[ctr]);
   }
//will print "31 32 33 "

This takes the source integer, turns it into ASCII, 3 digits long, then outputs these three digits in hex, each with a trailing space.
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