void Uart_Printf(char *fmt, ...)
{
va_list ap;
char string[256];
va_start(ap, fmt);
vsprintf(string, fmt, ap);
Uart_SendString(string);
va_end(ap);
}
//只考虑一个字符串。
简化版
void Uart0_Printf(char *fmt)
{
char string[256];
Uart0_SendString(string);
}
void Uart0_SendString(char *pt)
{
while (*pt)
Uart0_SendByte(*pt++);
}
void Uart0_SendByte(int data)
{
if (data == '\n')
{
while (!(rUTRSTAT0 & 0x2));
Delay(10); //because the slow response of hyper_terminal
WrUTXH0('\r');
}
while (!(rUTRSTAT0 & 0x2)); //Wait until THR is empty.
Delay(10);
WrUTXH0(data);
}
//缺点只有串口1;
//寻找delay的替代,先不要管。粘贴入代码的时候删去