⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uart_printf.c

📁 s3c2440的LCD控制器驱动程序 ps 无操作系统的情况
💻 C
字号:
/*
******************************************************************************************************************
*                                            xxx project ---- xxx module
*
*                        Copyright(C), 2006-2007, Allwinner Microelectronic Co., Ltd.
*											All Rights Reserved
*
*File Name : UART_printf.c
*
*Author : Wang Yugang
*
*Version : 1.0
*
*Date : 2007.7.27    17:50
*
*Description : test void UART_printf( const char * str, ...)
*
*Others : None at present.
*
*
* History :
*
* <Author>          <time>      <version>     <desricption>
*
* Wangyugang      2007.7.27        1.0         build the file
*  
*******************************************************************************************************************
*/


#include <stdarg.h>
#include "format_transformed.h"
#include "serial.h"





void UART_printf( const char * str, ...);




/*
******************************************************************************************************************
*
*Function Name : test_UART_printf
*
*Description : This function is just a temp function, to test function UART_printf().
*                In release version, this function should be deleted.
*
*Input : void.
*
*Output : void.
*
*call for : void UART_printf( const char * str, ...), defined in current file.
*
*Others : None at present.
*
*******************************************************************************************************************
*/
void test_UART_printf( void )
{
	int i = 0xffff0000 ;
	char ch = 'A';
	char *s = "hello.";
	UART_printf("Sucessful!  i= %d = %u = %x = %X, s = %s, ch = %c, addr of s = %p.\n", i, i, i,i, s, ch, s );
}








/*
******************************************************************************************************************
*
*Function Name : UART_printf
*
*Description : This function is to formatedly output through UART, similar to ANSI C function printf().
*                This function can support and only support the following Conversion Specifiers:
*              %d		Signed decimal integer.
*              %u		Unsigned decimal integer.
*              %x		Unsigned hexadecimal integer, using hex digits 0f.
*              %X		Unsigned hexadecimal integer, using hex digits 0F.
*              %c		Single character.
*              %s		Character string.
*              %p		A pointer.
*
*Input : refer to ANSI C function printf().
*
*Output : void, different form ANSI C function printf().
*
*call for : void int_to_string_dec( int input, char * str ), defined in format_transformed.c.
*           void int_to_string_hex( int input, char * str );  defined in format_transformed.c.
*           void Uint_to_string_dec( unsigned int input, char * str );  defined in format_transformed.c.
*           void UART_putchar( int ch); defined in boot loader.
*           void UART_puts( const char * string ); defined in boot loader.
*
*Others : None at present.
*
*******************************************************************************************************************
*/
void UART_printf( const char * str, ...)
{	
	char string[13];
	char *p;
	int hex_flag ;
	va_list argp;
	
	va_start( argp, str );
	
	while( *str )
	{
		if( *str == '%' )
		{	
			++str;
			p = string;
			hex_flag = HEX_X;
			switch( *str )
			{
				case 'd': int_to_string_dec( va_arg( argp,  int ), string );
                          while( *p )
                          	UART_putchar( *p++ );
						  ++str;
						  break; 
				case 'x': hex_flag = HEX_x;	         // jump to " case 'X' "
				case 'p':                                     
				case 'X': int_to_string_hex( va_arg( argp,  int ), string, hex_flag );
						  while( *p )
                          	UART_putchar( *p++ );
                          ++str;
						  break;
				case 'u': Uint_to_string_dec( va_arg( argp,  int ), string );
						  while( *p )
                          	UART_putchar( *p++ );
						  ++str;
						  break;
				case 'c': UART_putchar( va_arg( argp,  int ) );
						  ++str;
						  break;
				case 's': UART_puts( va_arg( argp, char * ) );
						  ++str;
						  break;
				default : UART_putchar( '%' );       // if current character is not Conversion Specifiers 'dxpXucs', 
						  UART_putchar( *str );         // output directly '%' and current character, and then
						  ++str;                        // let 'str' point to next character.
			}
		}
				
		else
		{                                        
			if( *str == '\n' )                      // if current character is '\n', insert and output '\r'
				UART_putchar( '\r' );               
				
			UART_putchar( *str++ ); 
		}                  
	}	
	                                    
	va_end( argp );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -