This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

printf() problem

Hello,

I'm using Keil to write data over the serial port.

ubyte b=0x0A;
printf("%c",b);


with this code I reveive two bytes: “0x0D” and “0x0A” in PC instead of “0x0A”. This happens only with “0x0A”. What's wrong with it?

Thanks
Senmeis

  • You made an assumption that the output stream would be binary. When in text mode, you get the two-character newline sequence used by Windows/MS-DOS.

    Was it the PC who sent the data, or was it the PC who receievd. Normal PC programs will convert newline into two characters if the stream isn't set as binary. Most probably, Keil has similar support on their side.

  • PC is the receiver. Do you mean the problem is the Microcontroller or the PC? Are there any ways still to use printf()? Anyway it is a standard function in keil.

    Thanks
    Senmeis

  • As far as I remember, the default implementation of putchar() in C166 expands '\n' into '\r\n'. Besides, the implementation is blocking. You should implement your own putchar(). You can take the default implementation and remove the '\n' expansion. If you need interrupt-driven serial I/O, have a look at the traffic example program.