View previous topic :: View next topic |
Author |
Message |
ashrafkhatri
Joined: 06 May 2008 Posts: 14
|
printf format |
Posted: Wed Feb 08, 2017 12:10 am |
|
|
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: 19549
|
|
Posted: Wed Feb 08, 2017 3:56 am |
|
|
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
|
|
Posted: Wed Feb 08, 2017 6:30 am |
|
|
Thanks |
|
|
|