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 -- PF9
LED1 -- PF10
LED2 -- PE13
LED3 -- 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);
版权声明:本文标题:STM32 | USART1电脑串口助手发送字符串,控制开发板LED灯案例 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1727404784a1113249.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论