📄 main.c
字号:
/**
******************************************************************************
* @file UART1_Printf\main.c
* @brief This file contains the main function for: retarget the C library printf function to the UART1 example.
* @author STMicroelectronics - MCD Application Team
* @version V1.0.1
* @date 09/22/2008
******************************************************************************
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>© COPYRIGHT 2008 STMicroelectronics</center></h2>
* @image html logo.bmp
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm8s_lib.h"
#include "stdio.h"
/**
* @addtogroup UART1_Printf
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
char putchar (char c);
/* Private functions ---------------------------------------------------------*/
/**
* @brief Example firmware main entry point.
* @par Parameters:
* None
* @retval void None
* @par Required preconditions:
* None
* @par Library functions called:
* - UART1_DeInit()
* - UART1_Init()
* - UART1_Cmd()
* - CLK_HSIPrescalerConfig()
*/
void main(void)
{
/*High speed internal clock prescaler: 1*/
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
UART1_DeInit();
/* UART1 configuration ------------------------------------------------------*/
/* UART1 configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Receive and transmit enabled
- UART1 Clock disabled
*/
/* Configure UART1 */
UART1_Init((u32)115200, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO, UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE);
/* Output a message on Hyperterminal using printf function */
printf("\n\rUART1 Example :retarget the C library printf function to the UART1\n\r");
while (1);
}
/**
* @brief Retargets the C library printf function to the UART1.
* @param[in] c Character to send
* @retval char Character sent
* @par Required preconditions:
* - None
* @par Library functions called:
* - UART1_GetFlagStatus()
* - UART1_SendData8()
*/
char putchar (char c)
{
if (c == '\n')
{
/* put '\r' to hardware here */
/* Wait transmission is completed : otherwise the first data is not sent */
while (!UART1_GetFlagStatus(UART1_FLAG_TC));
UART1_SendData8('\r');
/* Wait transmission is completed */
while (!UART1_GetFlagStatus(UART1_FLAG_TC));
}
/* put c to hardware here */
/* Wait transmission is completed : otherwise the first data is not sent */
while (!UART1_GetFlagStatus(UART1_FLAG_TC));
UART1_SendData8(c);
/* Wait transmission is completed */
while (!UART1_GetFlagStatus(UART1_FLAG_TC));
return (c);
}
/**
* @brief Reports the name of the source file and the source line number where
* the assert error has occurred.
* User can add his own implementation to report the file name and line number.
* ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line)
* @retval void None
* @par Required preconditions:
* None
* @par Called functions:
* None
*/
#ifdef FULL_ASSERT
void assert_failed(u8 *file, u16 line)
#else
void assert_failed(void)
#endif
{
/* Add your own code to manage an assert error */
/* Infinite loop */
while (1)
{
}
}
/**
* @}
*/
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -