天天看點

STM32 printf 輸出到usart1

MDK4.7環境

#include "stm32f10x.h"

//在STM32中使用printf輸出到USART1,在配置好USART1後,再點“Project->Optins For Target'xxxfile'->Target”中

//勾選 Use Micro LIB 這樣以後就可以使用printf函數了

#include <stdio.h>    //一定要包含這個庫檔案

int fputc(int ch, FILE *f)   //提示出錯可以不管

{  

    //等待發送完畢

    while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET );

   //ch送給USART1

    USART_SendData(USART1, ch ); 

    //傳回ch

    return(ch);    

}

//過程結束.

int main(void)

{

//前提是一定要先定義好USART1

printf("ABCDEFGH");

}

繼續閱讀