- /**
- ******************************************************************************
- * [url=home.php?mod=space&uid=288409]@file[/url] UART1_Printf\main.c
- * [url=home.php?mod=space&uid=247401]@brief[/url] This file contains the main function for: retarget the C library printf
- * /scanf functions to the UART1 example.
- * [url=home.php?mod=space&uid=187600]@author[/url] MCD Application Team
- * [url=home.php?mod=space&uid=895143]@version[/url] V2.0.4
- * [url=home.php?mod=space&uid=212281]@date[/url] 26-April-2018
- ******************************************************************************
- * @attention
- *
- * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
- *
- * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
- * You may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.st.com/software_license_agreement_liberty_v2
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************
- */
- /* Includes ------------------------------------------------------------------*/
- #include "stm8s.h"
- #include "stdio.h"
- /**
- * @addtogroup UART1_Printf
- * @{
- */
- /* Private typedef -----------------------------------------------------------*/
- /* Private define ------------------------------------------------------------*/
- #ifdef _RAISONANCE_
- #define PUTCHAR_PROTOTYPE int putchar (char c)
- #define GETCHAR_PROTOTYPE int getchar (void)
- #elif defined (_COSMIC_)
- #define PUTCHAR_PROTOTYPE char putchar (char c)
- #define GETCHAR_PROTOTYPE char getchar (void)
- #else /* _IAR_ */
- #define PUTCHAR_PROTOTYPE int putchar (int c)
- #define GETCHAR_PROTOTYPE int getchar (void)
- #endif /* _RAISONANCE_ */
- /* Private macro -------------------------------------------------------------*/
- /* Private variables ---------------------------------------------------------*/
- /* Private function prototypes -----------------------------------------------*/
- /* Private functions ---------------------------------------------------------*/
- /**
- * @brief Main program.
- * @param None
- * @retval None
- */
- void main(void)
- {
- char ans;
- /*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
- */
- UART1_Init((uint32_t)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()/getchar() functions to the UART\n\r");
- printf("\n\rEnter Text\n\r");
- while (1)
- {
- ans = getchar();
- printf("%c", ans);
- }
- }
- /**
- * @brief Retargets the C library printf function to the UART.
- * @param c Character to send
- * @retval char Character sent
- */
- PUTCHAR_PROTOTYPE
- {
- /* Write a character to the UART1 */
- UART1_SendData8(c);
- /* Loop until the end of transmission */
- while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET);
- return (c);
- }
- /**
- * @brief Retargets the C library scanf function to the USART.
- * @param None
- * @retval char Character to Read
- */
- GETCHAR_PROTOTYPE
- {
- #ifdef _COSMIC_
- char c = 0;
- #else
- int c = 0;
- #endif
- /* Loop until the Read data register flag is SET */
- while (UART1_GetFlagStatus(UART1_FLAG_RXNE) == RESET);
- c = UART1_ReceiveData8();
- return (c);
- }
- #ifdef USE_FULL_ASSERT
- /**
- * @brief Reports the name of the source file and the source line number
- * where the assert_param error has occurred.
- * @param file: pointer to the source file name
- * @param line: assert_param error line source number
- * @retval None
- */
- void assert_failed(uint8_t* file, uint32_t line)
- {
- /* 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) */
- /* Infinite loop */
- while (1)
- {
- }
- }
- #endif
- /**
- * @}
- */
- /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|