https://jingyan.baidu.com/article/86fae3466b65bc7c48121a3e.html
//自定義打印函數(shù)
void uart0_Printf( const char * format, ... )
{
?uint8_t k=0;
?char buf[128];
?char *pbuf=NULL;
?va_list args;
?pbuf =buf;
?va_start(args, format);
?vsprintf(buf,format, args);
?while(*(pbuf+k)!='\0')
?{
? M0P_UART0->SBUF =*(pbuf+k);//循環(huán)發(fā)送一個(gè)字節(jié)一個(gè)字節(jié)的發(fā)
? k++;
? delay1ms (2);
?}
?va_end (args);
}
https://jingyan.baidu.com/article/86fae3466b65bc7c48121a3e.html
想自己實(shí)現(xiàn)printf的不定參數(shù)就行格式化輸出,比如printf("%d",1)
想重載這個(gè)printf函數(shù)
//自定義打印函數(shù)
void uart0_Printf( const char * format, ... )
{
?uint8_t k=0;
?char buf[128];
?char *pbuf=NULL;
?va_list args;
?pbuf =buf;
?va_start(args, format);
?vsprintf(buf,format, args);
?while(*(pbuf+k)!='\0')
?{
? M0P_UART0->SBUF =*(pbuf+k);//循環(huán)發(fā)送一個(gè)字節(jié)一個(gè)字節(jié)的發(fā)
? k++;
? delay1ms (2);
?}
?va_end (args);
}
void WF_Printf(const char * str, ...)
{???? ?
??? // if((DataBase._Run_Mode_Enum!=Run_Mode_Enum_Factory)||(DataBase.cfg.Cfg_Page_5.value._IsPut_Log))//在剛啟動(dòng)和配置輸出log時(shí),開始輸出log
???? {
??????? char buffer[bufsize]={0};? // 待打印字符串緩存
??????? va_list args;
??????? va_start(args, str);?? ?
??????? vsnprintf(buffer,bufsize,str,args);?????? ?
??????? va_end(args);
? Uart_Send_Data_By_Len(M0P_UART0, (uint8_t*)buffer,strlen((char*)buffer));//打印函數(shù)?????? ?
??? }
}
void WF_Printf(const char * str, ...)
{???? ?
??? // if((DataBase._Run_Mode_Enum!=Run_Mode_Enum_Factory)||(DataBase.cfg.Cfg_Page_5.value._IsPut_Log))//在剛啟動(dòng)和配置輸出log時(shí),開始輸出log
???? {
??????? char buffer[bufsize]={0};? // 待打印字符串緩存
??????? va_list args;
??????? va_start(args, str);?? ?
??????? vsnprintf(buffer,bufsize,str,args);?????? ?
??????? va_end(args);
? Uart_Send_Data_By_Len(M0P_UART0, (uint8_t*)buffer,strlen((char*)buffer));//打印函數(shù)?????? ?
??? }
}