Keil™, An ARM® Company

Cx51 User's Guide

Technical Support

On-Line Manuals

Cx51 User's Guide

Cx51 Introduction Compiling Programs Language Extensions Preprocessor Advanced Programming 8051 Derivatives Error Messages Library Reference Library Files Source Code Standard Types jmp_buf size_t va_list wchar_t Macros CBYTE CWORD DBYTE DWORD FARRAY FCARRAY FCVAR FVAR PBYTE PWORD XBYTE XWORD Routines By Category Buffer Manipulation Routines Character Routines Data Conversion Routines Intrinsic Routines Math Routines Memory Allocation Routines Stream I/O Routines String Routines Variable Length Argument Routines Miscellaneous Routines Include Files SFR Definitions 80c517.h absacc.h assert.h ctype.h float.h intrins.h limits.h math.h rtx51tny.h setjmp.h stdarg.h stddef.h stdio.h stdlib.h string.h Reference _chkfloat_ _crol_ _cror_ _getkey _irol_ _iror_ _lrol_ _lror_ _nop_ _pop_ _push_ _testbit_ _tolower _toupper abs acos acos517 asin asin517 assert atan atan2 atan517 atof atof517 atoi atol cabs calloc ceil cos cos517 cosh exp exp517 fabs floor fmod free getchar gets init_mempool isalnum isalpha iscntrl isdigit isgraph islower isprint ispunct isspace isupper isxdigit labs log log10 log10517 log517 longjmp malloc memccpy memchr memcmp memcpy memmove memset modf offsetof pow printf printf517 putchar puts rand realloc scanf scanf517 setjmp sin sin517 sinh sprintf sprintf517 sqrt sqrt517 srand sscanf sscanf517 strcat strchr strcmp strcpy strcspn strlen strncat strncmp strncpy strpbrk strpos strrchr strrpbrk strrpos strspn strstr strtod strtod517 strtok strtol strtoul switchbank tan tan517 tanh toascii toint tolower toupper ungetchar va_arg va_end va_start vprintf vsprintf Appendix

Stream I/O Routines

RoutineAttributesDescription
getcharreentrantReads and echoes a character using the _getkey and putchar routines.
_getkey Reads a character using the 8051 serial interface.
gets Reads and echoes a character string using the getchar routine.
printf Writes formatted data using the putchar routine.
printf517 Writes formatted data using the putchar routine.
putchar Writes a character using the 8051 serial interface.
putsreentrantWrites a character string and newline ('\n') character using the putchar routine.
scanf Reads formatted data using the getchar routine.
scanf517 Reads formatted data using the getchar routine.
sprintf Writes formatted data to a string.
sprintf517 Writes formatted data to a string.
sscanf Reads formatted data from a string.
sscanf517 Reads formatted data from a string.
ungetchar Places a character back into the getchar input buffer.
vprintf Writes formatted data using the putchar function.
vsprintf Writes formatted data to a string.

The stream I/O routines are implemented as functions and are prototyped in the stdio.h include file.

The stream input and output routines allow you to read and write data to and from a user-defined I/O interface. Characters are read using the _getkey routine and are written using the putchar routine. The default _getkey and putchar functions in the C51 library read and write characters using the 8051 serial interface.

The source code for _getkey and putchar is available in the \KEIL\C51\LIB folder. You may modify these files and substitute them for the default library routines. The stream functions then perform input and output using your modified _getkey and putchar routines.

To use the existing _getkey and putchar routines, you must first initialize the 8051 serial port. If the serial port is not properly initialized, the default stream functions do not function. Initializing the serial port requires manipulating several special function registers (SFRs) of the 8051.

Related Knowledgebase Articles