在线时间886 小时
UID3054195
ST金币0
蝴蝶豆61
注册时间2014-8-21
论坛元老
- 最后登录
- 2020-12-9
|
a0a.1 32b0c
自动返回你输入的字符
主函数如下:- #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]);
- }
-
- }
复制代码
|
|