Console classification
1. Menu-based console, select menu to execute command
2. Analytic console to execute commands by entering commands
printf (), scanf () function porting
1. function with variable parameter
2. Printing information to the serial port
3. The key is to convert the argument to a string, and the correlation function needs to be ported from the Linux kernel or the standard C library
Va_list args;
Va_start (args, FMT);
vsprintf (buf, FMT, args);
Va_end (args);
/********************************************************************* Name: puts* parameter: str output String * Return: I output character number * Function: output String * * /int puts (const char *str) {int i; The output character count for (i = 0; Str[i]! = ' \ "; i++) {//If the output character is a terminator, end the output string PUTC (Str[i]);} return i;} /********************************************************************* Name: gets* parameter: str input string * Return: I input character number * Function: input String * * /int gets (char *str) {//standard C returned as char * The input string pointer of type char ch; input character int i; Enter the number of characters ch = getc_echo (); for (i = 0; ch! = ' \ r '; i++) {///if the input character is carriage return, end the input string str[i] = Ch;ch = Getc_echo ();} str[i++] = ' \ r '; Add carriage return str[i++] = ' \ n '; Add newline str[i] = ' + '; Add terminator return i;} /********************************************************************* Name: printf* parameter: Format formatted string * Return: num OUTPUT characters * function : Formatted output string *********************************************************************/int printf (const char *format, ...) {ChaR Buffer[bufsize]; string caching va_list args; parameter list int num; The number of output characters//conversion parameters are string Va_start (args, format); Read parameter vsprintf (buffer, format, args); The conversion parameter is String va_end (args); End conversion//output string to Serial num = puts (buffer); return num;} /********************************************************************* Name: scanf* parameter: Format formatted input string * return: num input character number * Function: Format input string *********************************************************************/int scanf (const char *format, ... } {//Standard C Returns whether the success flag of type int is the int num; Enter the number of characters Char buffer[bufsize]; string caching va_list args; parameter list//input string to serial num = gets (buffer);//convert string to parameter Va_start (args, format); Read parameter vsscanf (buffer, format, args); The conversion string is the parameter va_end (args); End convert return num;}
[Country EMBED strategy] [057] [Serial console Setup]