这是例子啊
examples/USART/USART_HyperTerminal_Interrupt/main.c Go to the documentation of this file. 00001 /** 00002 ****************************************************************************** 00003 * @file USART_HyperTerminal_Interruptmain.c 00004 * @brief This file contains the main function for usart using interrupts in communication example. 00005 * @author STMicroelectronics - APG Application Team 00006 * @version V1.0.1 00007 * @date 09/22/2008 00008 ****************************************************************************** 00009 * 00010 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 00011 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 00012 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 00013 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 00014 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 00015 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 00016 * 00017 * <h2><center>© COPYRIGHT 2008 STMicroelectronics</center></h2> 00018 * @image html logo.bmp 00019 ****************************************************************************** 00020 */ 00021 00022 /* Includes ------------------------------------------------------------------*/ 00023 #include "stm8a_lib.h" 00024 00025 /** 00026 * @addtogroup USART_HyperTerminal_Interrupt 00027 * @{ 00028 */ 00029 /* Private typedef -----------------------------------------------------------*/ 00030 /* Private define ------------------------------------------------------------*/ 00031 /* Private macro -------------------------------------------------------------*/ 00032 /* Private variables ---------------------------------------------------------*/ 00033 /* Private variables ---------------------------------------------------------*/ 00034 /* Private function prototypes -----------------------------------------------*/ 00035 /* Private functions ---------------------------------------------------------*/ 00036 /** 00037 * @brief Validation firmware main entry point. 00038 * @par Parameters: 00039 * None 00040 * @retval void None 00041 * @par Required preconditions: 00042 * None 00043 * @par Library functions called: 00044 * - USART_DeInit() 00045 * - USART_Init() 00046 * - USART_Cmd() 00047 * - USART_ITConfig() 00048 * - CLK_HSIPrescalerConfig() 00049 */ 00050 void main(void) 00051 { 00052 /* Enable general interrupts */ 00053 enableInterrupts(); 00054 00055 /*High speed internal clock prescaler: 1*/ 00056 CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); 00057 00058 USART_DeInit(); 00059 /* USART configuration ------------------------------------------------------*/ 00060 /* USART configured as follow: 00061 - BaudRate = 9600 baud 00062 - Word Length = 8 Bits 00063 - One Stop Bit 00064 - Odd parity 00065 - Receive and transmit enabled 00066 - USART Clock disabled 00067 */ 00068 /* Configure the USART */ 00069 USART_Init((u32)9600, USART_WORDLENGTH_8D, USART_STOPBITS_1, USART_PARITY_ODD, USART_SYNCMODE_CLOCK_DISABLE, USART_MODE_TXRX_ENABLE); 00070 00071 /* Enable the USART Transmit interrupt: this interrupt is generated when the 00072 USART transmit data register is empty */ 00073 USART_ITConfig(USART_IT_TXE, ENABLE); 00074 /* Enable the USART Receive interrupt: this interrupt is generated when the 00075 USART receive data register is not empty */ 00076 USART_ITConfig(USART_IT_RXNE_OR, ENABLE); 00077 00078 while (1); 00079 } 00080 00081 /** 00082 * @brief Reports the name of the source file and the source line number where 00083 * the assert error has occurred. 00084 * User can add his own implementation to report the file name and line number. 00085 * ex: printf("Wrong parameters value: file %s on line %d
", file, line) 00086 * @retval void None 00087 * @par Required preconditions: 00088 * None 00089 * @par Called functions: 00090 * None 00091 */ 00092 #ifdef FULL_ASSERT 00093 void assert_failed(u8 *file, u16 line) 00094 #else 00095 void assert_failed(void) 00096 #endif 00097 { 00098 /* Add your own code to manage an assert error */ 00099 /* Infinite loop */ 00100 while (1) 00101 { 00102 } 00103 } 00104 00105 /** 00106 * @} 00107 */ 00108 00109 /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/