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

printf format

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



Joined: 06 May 2008
Posts: 14

View user's profile Send private message

printf format
PostPosted: Wed Feb 08, 2017 12:10 am     Reply with quote

Hi;

I am getting CC72AA33C3B1 kind of data on serial port from an embedded system.

Now i want to send similar type of command to that embedded system using my pic microcontroller hardware.

I tried many printf commands with different format but did not get above mention data format.

Regards
Ash
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Wed Feb 08, 2017 3:56 am     Reply with quote

This is just ASCII hex.

Six bytes.

So:
Code:

   int8 data_array[6] = {0xCC,0x72,0xAA,0x33,0xC3,177};
   //Now obviously you put whatever numbers you actually want to
   //send into the array.
   int8 ictr;
   for (ictr=0;ictr<6;ictr++)
      printf("%02X", data_array[ctr]);



Now things to note:

1) %02. This ensures each byte always uses 2 characters. Otherwise you will get a problem if you have a byte less than 15.
2) 'X'. Note the capital. This makes it format as (for example), 'AA', rather than 'aa'.
3) Note I deliberately put the last byte in decimal (177), to show I'm not cheating and 'pre-formatting' the data.
ashrafkhatri



Joined: 06 May 2008
Posts: 14

View user's profile Send private message

PostPosted: Wed Feb 08, 2017 6:30 am     Reply with quote

Thanks
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