自动返回你输入的字符 (, 下载次数: 0) 上传 点击文件名下载附件 主函数如下:#include "stm32f0xx.h" #include "Usart1.h" unsigned char Uart_buf[2]={0x00,0x00}; //缓冲接收缓冲器 void led_gpio_config() { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHBPeriphClockCmd ( RCC_AHBPeriph_GPIOA, ENABLE); //总线使能 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //Pin 5 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT ; //输出模式 GPIO_InitStructure.GPIO_OType =GPIO_OType_PP ; //推挽输出 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ; //配置为上拉 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; //50MHz GPIO_Init(GPIOA, &GPIO_InitStructure); } int main(void) { led_gpio_config(); //IO口初始化 GPIO_SetBits(GPIOA,GPIO_Pin_5); USART_Config(); printf("STM32-NUCLEO-072RB开发板初始化成功!\r\n"); printf(""hello world"!\r\n"); printf("\r\n 你输入的字符是:\r\n"); while (1) { Uart_buf[0]=Uart_RChar(); if(Uart_buf[0]!=NULL) printf("你输入的字符是:%x\r\n",Uart_buf[0]); } }复制代码