stm32 库函数(按键控制led灯闪烁)最简单易懂的使用方法

STM32 使用库函数(按键控制led不同的闪烁效果)

下面是main.c

1#include "stm32f10x.h" 2#include "led.h"` 3#include "key.h" 4int main(void) 5 6{ 7 8 9while(1) 10 { 11 12 13 if(!GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_3)) 14 { 15 16 17 GPIO_WriteBit(GPIOE,GPIO_Pin_5,(BitAction)(1)); 18 } 19 else 20 { 21 22 23 GPIO_WriteBit(GPIOE,GPIO_Pin_5,(BitAction)(0)); 24 } 25 } 26 27}

led.c

1#include "led.h" 2 3 4void LED_Init(void) 5{ 6 7 8GPIO_InitTypeDef GPIO_InitStructure;//构造结构体 9RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); 10RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);//使能其所在时钟 11GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;//定义IO端口 12GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//定义IO端口输出模式 13GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//定义IO端口输出速度 14GPIO_Init(GPIOE, &GPIO_InitStructure);//写入其中 15}

led.h

1#ifndef _led_H 2 3#include "stm32f10x.h" 4#include "stm32f10x_gpio.h" 5 6 7 8 9 10 11void LED_Init(void); 12 13#endif

key.c

1#include "key.h" 2 3void KEY_Init(void) 4 5{ 6 7 8 GPIO_InitTypeDef GPIO_InitStructure; //构造结构体 9 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);//使能其所在时钟 10 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;//定义IO端口 11 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//上拉输入 12 13 GPIO_Init(GPIOE,&GPIO_InitStructure); 14 15}

key.h

1#ifndef _led_H 2#define _led_H 3 4#include "stm32f10x.h" 5#include "stm32f10x_gpio.h" 6void KEY_Init(void); 7#define KEYPORT GPIOE 8#define KEY1 GPIO_Pin_3 9 10 11 12#endif
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

STM32使用HAL库实现按键的单击、双击、长按

STM32使用HAL库实现按键的单击、双击、长按目录STM32使用HAL库实现按键的单击、双击、长按前言具体思路工程配置代码实现实验效果前言编程开发环境:STM32

java将前端的json数组字符串转换为列表

记录下在前端通过ajax提交了一个json数组的字符串,在后端如何转换为列表。前端数据转化与请求varcontracts{id:'1',name:'yanggb合同1'},{id:'2',name:'yanggb合同2'},{id:'3',name:'yang