函数如下:
/*******************************************************************************
* Function Name : fputc
* Description : Retargets the C library printf function to the USART.
* Input : None
* Output : None
* Return : None
***************************************************************************** **/
int fputc(int ch, FILE *f)
{
// Place your implementation of fputc here
//e.g. write a character to the USART
USART1->DR.W = ((u16)ch & (u16)0x01FF);
///Loop until the end of transmission
while(USART1->SR.B.TC==0);
return ch;
}
// Write to USART BRR
USART1->BRR.W = (u16)tmpreg;
//end-------------------------------------------
USART1->CR1.B.UE =1 ; //USART1模块使能
printf("\r\n Usart1 OK! \r\n");
}
/*******************************************************************************
* Function Name : fputc
* Description : Retargets the C library printf function to the USART.
* Input : None
* Output : None
* Return : None
***************************************************************************** **/
int fputc(int ch, FILE *f)
{
// Place your implementation of fputc here
//e.g. write a character to the USART
USART1->DR.W = ((u16)ch & (u16)0x01FF);
///Loop until the end of transmission
while(USART1->SR.B.TC==0); //等待发送完成