We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi, This is my program. int a = 0x0A; printf("%c",a); Why is it that the output from the serial port is 0x0D and 0x0A instead of just 0x0A itself? Thanks..
The printf function calls putchar to output characters. The putchar function, by default, converts a /n into a /r/n. Take a look at the PUTCHAR.C file in the \KEIL\C51\LIB\ directory. Jon
So, how do i overcome this problem.. Thanks..
Well, there are several ways to overcome this problem... 1. Go to a Keil training class. There, they teach how to do stuff like that plus a whole lot more. 2. Hire a consultant. There are many good to great consultants on this forum who would be more than happy to consult for you. 3. Take a look in the manuals to find out how to configure printf for your needs. Then, look at the putchar.c file in the lib directory. Jon
Hi, Anyone will like to help me with this problem. I don't understand the putchar.c file. Thanks..
Using serial port,what about writing yourself function uchar putchar(uchar ch) { while (!TI) ; TI = 0; SBUF = ch; }
%c means to print characters. 0x0A is not a character. It is a code. The range of "printable characters" is something like 61 to 7F for lower case a-z and some other for upper case A-Z, plus the !.;; and other types. Do a web search for ASCII table. if you want to print hex values, rather than the character values, do a printf("%04X", SomeInt); HTH,
"0x0A is not a character. It is a code." That's extremely misleading. 0x0A is the numeric represention (ASCII code) for the ASCII character 'newline' or 'linefeed'. %c is a perfectly good way of outputting a linefeed with printf(). The concept of "printable characters" has nothing to do with printf(). Stefan
>>"0x0A is not a character. It is a code." >That's extremely misleading. >0x0A is the numeric represention (ASCII >code) You just stated that it is a code. ASCII code. I don't think it is "extremely misleading". Sure, an ASCII terminal represents the 0x0A as a Line feed or Carriage return. (Can't remember), but I don't think the user is that deep into the theory and is probably using it as an ascii character by the message. Regards,
"You just stated that it is a code. ASCII code." Yes, but so is 0x41. And that's an 'A'. It doesn't mean it isn't a character. "I don't think it is "extremely misleading"." Ok, totally wrong then. Every value in the range 0 to 127 is an ASCII character. "Sure, an ASCII terminal represents the 0x0A as a Line feed or Carriage return" Like I said, it's a linefeed. "but I don't think the user is that deep into the theory and is probably using it as an ascii character by the message" Yes, he is using it as an ASCII character. That's because it IS an ASCII character. But you've gone and told him it isn't. To be honest, I don't think that understanding what an ASCII character is is exactly being "deep into the theory". It's pretty fundamental stuff. Stefan