int printf (
const char *fmtstr /* format string */
<[>, arguments ... <]>); /* additional arguments */
The printf function formats a series of strings and numeric values and builds a string to write to the output stream using the putchar function. The fmtstr argument is a format string that may be composed of characters, escape sequences, and format specifications.
在keil安装文件目录C51LIB中,找到PUTCHAR.C文件,将其包含进工程文件中,并修改。
/*
* putchar (full version): expands '
' into CR LF and handles
* XON/XOFF (Ctrl+S/Ctrl+Q) protocol
*/
char putchar (char c) {
if (c == '
') {
if (RI) {
if (SBUF == XOFF) {
do {
RI = 0;
while (!RI);
}
while (SBUF != XON);
RI = 0;
}
}
while (!TI);
TI = 0;
SBUF = 0x0d; /* output CR */
}
if (RI) {
if (SBUF == XOFF) {
do {
RI = 0;
while (!RI);
}
while (SBUF != XON);
RI = 0;
}
}
while (!TI);
TI = 0;
return (SBUF = c);
}
int printf (
const char *fmtstr /* format string */
<[>, arguments ... <]>); /* additional arguments */
The printf function formats a series of strings and numeric values and builds a string to write to the output stream using the putchar function. The fmtstr argument is a format string that may be composed of characters, escape sequences, and format specifications.
在keil安装文件目录C51LIB中,找到PUTCHAR.C文件,将其包含进工程文件中,并修改。
/*
* putchar (full version): expands ' ' into CR LF and handles
* XON/XOFF (Ctrl+S/Ctrl+Q) protocol
*/
char putchar (char c) {
if (c == ' ') {
if (RI) {
if (SBUF == XOFF) {
do {
RI = 0;
while (!RI);
}
while (SBUF != XON);
RI = 0;
}
}
while (!TI);
TI = 0;
SBUF = 0x0d; /* output CR */
}
if (RI) {
if (SBUF == XOFF) {
do {
RI = 0;
while (!RI);
}
while (SBUF != XON);
RI = 0;
}
}
while (!TI);
TI = 0;
return (SBUF = c);
}
上面的寄存器明显不是C8051串口的寄存器,需要修改。
还是有些不懂,再此请教一下:
首先我确定printf是通过操作SBUF来实现的,
keil中stdio.h中有函数extern int printf (const char *, ...);说明printf是外部的函数,怎么找到它的函数体,虽然它是通过putchar()实现的。
2-------putchar.c文件中有3个一样的函数体char putchar (char c) {},那printf是怎么区分调用这些函数的
还有一问题就是putchar.c中定义的
#define XON 0x11
#define XOFF 0x13
代表什么意思
以上的问题让我觉得关于标准C语言的用法,还是什么也不会。。。。
希望能指点一下!
一周热门 更多>