I am trying to write a very simple program to output a serial string including hex codes when I press a button. It works fine if the string does not include 0x00, but if it does this is treated as 'end of string' and does not output.
printf ("\x01\x02\x00\x03\x04")
SBUF =0x01 SBUF =0x02 SBUF =0x00 SBUF =0x03 SBUF =0x04
Getting back to Trevor's original question. I am trying to write a very simple program to output a serial string including hex codes when I press a button. Well, as has already been pointed out, the fundemental problem is that what you are trying to put out is not a string. Remember that string is just a convenient contraction of null terminated string and you will not fall into the same trap again. Since printf deals with null terminated strings, this is not the solution for you. A simple solution would be to write a loop something like this:
loop = length_of_string; p = address_of_string; do { putchar( *p++ ); }while( --loop != 0 )
while (loop--) { putchar(*p++); }
View all questions in Keil forum