看了一个例程,可以实现了
#define DEBUG_PRINT(fmt,...) snprintf(UART_DEBUG_BUFFER, UART_DEBUG_BUFFER_LINE_SIZE, fmt, __VA_ARGS__); \
UART_DEBUG_PRINT();
#ifdef __DEBUG_UART__
/*******************************************************************
* Function: UART_DEBUG_PRINT
* Description: Prints debug info over the UART using a predefined
* buffer.
*******************************************************************/
int UART_DEBUG_PRINT(void)
{
unsigned int i = 0; /* index */
char temp; /* temp char */
/* loop through the debug buffer until the end, a NULL, or an error */
for ( i = 0; i < UART_DEBUG_BUFFER_LINE_SIZE; i++)
{
temp = UART_DEBUG_BUFFER[i];
/* if not NULL then print it */
if (temp)
{
if( 0 == PutChar(temp) )
{
/* if error was detected then quit */
return 0;
}
/* if it was a newline we need to add a carriage return */
if ( 0x0a == temp )
{
if( 0 == PutChar(0x0d) )
{
/* if error was detected then quit */
return 0;
}
}
}
else
{
/* else NULL was found */
return 1;
}
}
return 1;
}
#endif