初级会员

- 积分
- 62
- 金钱
- 62
- 注册时间
- 2014-11-25
- 在线时间
- 0 小时
|
5金钱
#include "stm32f10x.h"
#include "stdio.h"
int SendChar (int ch);
int fputc(int ch, FILE *f);
int GetKey (void);
void USART1_Config(void);
void GPIO_Config(void);
/*----------------------------------------------------------------------------*/
int main(void)
{
SystemInit();
GPIO_Config();
USART1_Config();
printf(" --串口printf打印模板!--\r\n");
while(1)
{
printf(" --串口printf打印模板!--\r\n");
}
}
/* Implementation of putchar (also used by printf function to output data) */
int SendChar (int ch) { /* Write character to Serial Port */
USART_SendData(USART1, (unsigned char) ch);
while (!(USART1->SR & USART_FLAG_TXE));
return (ch);
}
int GetKey (void) { /* Read character from Serial Port */
while (!(USART1->SR & USART_FLAG_RXNE));
return (USART_ReceiveData(USART1));
}
/*******************************************************************************
* 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 */
USART_SendData(USART1, (u8) ch);
/* Loop until the end of transmission */
while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
{
}
return ch;
}
|
|