admin管理员组

文章数量:1558883

01、上节回顾

STM32 | USART实战案例

本节案例

1、通过电脑串口助手字符串,控制开发板LED灯

HCL11:      亮灯  HCL10:    灭灯

思路

a.使用数组存放传递过来的数据,并判断每一个字符是否为':', 如果为':'一帧数据接收完毕,反之继续接收数据

b.使用函数strcmp判断数据是否相等


02、LED配置

#ifndef __LED_H#define __LED_H#include "stm32f4xx.h"#define LED0_ON    GPIO_ResetBits(GPIOF, GPIO_Pin_9)#define LED0_OFF  GPIO_SetBits(GPIOF, GPIO_Pin_9)void Led_Init(void);#endif
#include "led.h"/*********************************引脚说明:LED0 -- PF9LED1 -- PF10LED2 -- PE13LED3 -- PE14**********************************/void Led_Init(void){
    GPIO_InitTypeDef  GPIO_InitStruct;    //使能GPIOE组时钟  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);      //使能GPIOF组时钟  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);      GPIO_InitStruct.GPIO_Pin  = GPIO_Pin_9|GPIO_Pin_10;    //引脚9 10  GPIO_InitStruct.GPIO_Mode  = GPIO_Mode_OUT;  //输出模式  GPIO_InitStruct.GPIO_OType  = GPIO_OType_PP;  //推挽输出  GPIO_InitStruct.GPIO_PuPd  = GPIO_PuPd_UP;    //上拉  GPIO_InitStruct.GPIO_Speed  = GPIO_Speed_50MHz; //速度   GPIO_Init(GPIOF, &GPIO_InitStruct);    GPIO_InitStruct.GPIO_Pin  = GPIO_Pin_13|GPIO_Pin_14;    //引脚13 14  GPIO_InitStruct.GPIO_Mode  = GPIO_Mode_OUT;  //输出模式  GPIO_InitStruct.GPIO_OType  = GPIO_OType_PP;  //推挽输出  GPIO_InitStruct.GPIO_PuPd  = GPIO_PuPd_UP;    //上拉  GPIO_InitStruct.GPIO_Speed  = GPIO_Speed_50MHz; //速度   GPIO_Init(GPIOE, &GPIO_InitStruct);      GPIO_SetBits(GPIOF, GPIO_Pin_9);  GPIO_SetBits(GPIOF, GPIO_Pin_10);  GPIO_SetBits(GPIOE, GPIO_Pin_13);  GPIO_SetBits(GPIOE, GPIO_Pin_14);}

03、SysTick配置

#ifndef __DELAY_H#define __DELAY_H#include "stm32f4xx.h"void Delay_Init(void);

本文标签: 串口字符串助手案例开发板