| 程序是这样的/* Includes ------------------------------------------------------------------*/ #include "stm32f10x.h"
 #include "platform_config.h"
 #include "stm32f10x_usart.h"
 #include "misc.h"
 //#include "stdarg.h"
 #include <stm32f10x_lib.h>
 
 
 
 /* Private function prototypes -----------------------------------------------*/
 void RCC_Configuration(void);
 void NVIC_Configuration(void);
 void USART_Config(void);
 void USART1_Puts(char * str);//输出字符串
 void USART1_Putc(char c);//输出一个字符
 unsigned char USART1_ReceiveChar(void);//接收一个字符
 
 char rbuff[100];
 
 
 /****************************************************************************
 * 名    称:int main(void)
 * 功    能:主函数
 * 入口参数:无
 * 出口参数:无
 * 说    明:
 * 调用方法:无
 ****************************************************************************/
 int main(void)
 {
 
 
 /* System Clocks Configuration */
 RCC_Configuration();                                                                                          //系统时钟设置
 
 /*嵌套向量中断控制器
 说明了USART1抢占优先级级别0(最多1位) ,和子优先级级别0(最多7位) */
 NVIC_Configuration();                                                                                          //中断源配置
 
 /*对控制LED指示灯的IO口进行了初始化,将端口配置为推挽上拉输出,口线速度为50Mhz。PA9,PA10端口复用为串口1的TX,RX。
 在配置某个口线时,首先应对它所在的端口的时钟进行使能。否则无法配置成功,由于用到了端口B, 因此要对这个端口的时钟
 进行使能,同时由于用到复用IO口功能用于配置串口。因此还要使能AFIO(复用功能IO)时钟。*/
 //GPIO_Configuration();                                                                                          //端口初始化
 USART_Config();
 while(1){}
 
 }
 
 /****************************************************************************
 * 名    称:void USART_Config(USART_TypeDef* USARTx)
 * 功    能:配置STM32 串口1
 * 入口参数:USARTx     串口名称(x=1,-5)*
 * 出口参数:无
 * 说    明:串口1工作模式配置
 * 调用方法:void USART_Config(USART1)          00000000000000000000
 ****************************************************************************/
 void USART_Config(void)
 {
 GPIO_InitTypeDef GPIO_InitStructure;
 USART_InitTypeDef USART_InitStructure;
 
 
 
 /* Configure USART1_Tx as alternate function push-pull */
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
 GPIO_Init(GPIOA, &GPIO_InitStructure);
 
 /* Configure USART1_Rx as input floating */
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
 GPIO_Init(GPIOA, &GPIO_InitStructure);
 //USART工作在异步模式下
 USART_InitStructure.USART_BaudRate = 9600;//波特率
 USART_InitStructure.USART_WordLength = USART_WordLength_8b;//数据位数
 USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
 USART_InitStructure.USART_Parity = USART_Parity_No ;//无奇偶校验位
 USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件控制流
 USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;//发送接收均使能
 /* Configure the USARTx */
 USART_Init(USART1, &USART_InitStructure);
 USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
 /* Enable the USARTx */
 USART_Cmd(USART1, ENABLE);
 
 }
 
 
 void USART1_Putc(char c)
 {
 USART_SendData(USART1, c);
 /* Loop until the end of transmission */
 while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
 }
 
 void USART1_Puts(char * str)
 {
 while(*str)
 {
 USART_SendData(USART1, *str++);
 /* Loop until the end of transmission */
 while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
 }
 
 }
 
 unsigned char USART1_ReceiveChar(void)
 {
 while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);
 return(USART_ReceiveData(USART1));
 }
 
 /****************************************************************************
 * 名    称:void RCC_Configuration(void)
 * 功    能:系统时钟配置为72MHZ, 外设时钟配置
 * 入口参数:无
 * 出口参数:无
 * 说    明:
 * 调用方法:无
 ****************************************************************************/
 void RCC_Configuration(void)
 {
 SystemInit();
 RCC_APB2PeriphClockCmd( RCC_APB2Periph_USART1 |RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |RCC_APB2Periph_AFIO  , ENABLE);
 }
 
 /****************************************************************************
 * 名    称:void GPIO_Configuration(void)
 * 功    能:通用IO口配置
 * 入口参数:无
 * 出口参数:无
 * 说    明:
 * 调用方法:
 ****************************************************************************/
 /*
 void GPIO_Configuration(void)
 {
 
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;                                     //LED1控制--PB5
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;                         //推挽输出
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_Init(GPIOB, &GPIO_InitStructure);
 
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;                                  //USART1 TX
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;                     //复用推挽输出
 GPIO_Init(GPIOA, &GPIO_InitStructure);                                     //A端口
 
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;                          //USART1 RX
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;            //复用开漏输入
 GPIO_Init(GPIOA, &GPIO_InitStructure);                                  //A端口
 }
 */
 /****************************************************************************
 * 名    称:void NVIC_Configuration(void)
 * 功    能:中断源配置
 * 入口参数:无
 * 出口参数:无
 * 说    明:
 * 调用方法:无
 ****************************************************************************/
 void NVIC_Configuration(void)
 {
 /*  结构声明*/
 NVIC_InitTypeDef NVIC_InitStructure;
 
 /* Configure the NVIC Preemption Priority Bits */
 /* Configure one bit for preemption priority */
 /* 优先级组 说明了抢占优先级所用的位数,和子优先级所用的位数   在这里是1, 7 */
 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
 
 
 NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;                                     //设置串口1中断
 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;                     //抢占优先级 0
 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;                                //子优先级为0
 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;                                        //使能
 NVIC_Init(&NVIC_InitStructure);
 }
 /******************* (C) COPYRIGHT 2011 奋斗STM32 *****END OF FILE****/
 |