当前位置:网站首页>NB-IOT智能云家具项目系列实站
NB-IOT智能云家具项目系列实站
2022-08-05 05:24:00 【毕竟是shy哥】
NB-IOT智能云家具项目-DAY4
5.1 查看按键的实物图、原理图
KEY1— PA0不按,管脚 低电平,按下 管脚 高电平
KEY2—PA2不按,管脚 高电平,按下 管脚 低电平
KEY3—PA12不按,管脚 高电平,按下 管脚 低电平
if(按下按键)// 判断KEY2----PD2 是否是 低电平
做什么操作
5.2 查看按键对应的CPU数据手册
存在四种输出模式:
输入浮空:如果硬件上外界上/下拉电阻,软件上配置成浮空
输入上拉: 如果硬件上没外接上/下拉电阻,软件上配置
输入下拉: 如果硬件上没外接上/下拉电阻,软件上配置
模拟功能: 只用在ADC DAC
if(( GPIOC->IDR & (1<<12)) 0)// 判断KEY3----PC12 是否是 低电平—>转换成判断 GPIOC_IDR 的第12位是否0
做什么操作
(GPIOC->IDR&(1<<12))==0
结论:项目板上按键—输入浮空
步骤1:管脚要存在一个高低电平
步骤2:把管脚配置成一种输入模式–输入浮空
// KEY3----- PC12 不按,管脚 高电平 ,按下 管脚 低电平
GPIOC->MODER &=~(1<<24);
GPIOC->MODER &=~(1<<25);// 模式寄存器—输入模式
GPIOC->PUPDR &=~(1<<24);
GPIOC->PUPDR &=~(1<<25);// 浮空
步骤3:这时管脚的高低电平就会存放到 输入数据寄存器中,用户读该寄存器,得到高低电平
if(( GPIOC->IDR & (1<<12)) 0)// 判断KEY3----PC12 是否是 低电平—>转换成判断 GPIOC_IDR 的第12位是否0
做什么操作
打开 PA PC PD 的外设时钟
步骤1:在LED的工程模板上,创建、保存、添加key.c key.h
步骤2:编写文件
key.c文件
//包含自身头文件
#include"key.h"
//包含系统头文件
#include"stm32f4xx.h"
//key初始化 --关键 输入浮空配置
void key_init(void)
{
// 打开 PA PC PD 外设时钟
// PA0 PC12 PD2 配置输入浮空
}
Key.h ---- 函数的声明
步骤3:主函数调用
main.c文件
//包含按键头文件
#include"key.h"
int main()
{
led_init();
key_init();
/*先把LED全部关掉*/
//不断查询按键状态
while(1
{
if(key1_press)//key1按下
led1_on;
else if()//key2按下
led2_on;
else if()//key3按下
led3_on;
else
{
//所有灯灭掉
}
}
5.3 采用编写软件模块化编写代码
5.4 实现效果:按键控制LED的操作
实验代码:link提取码8888
边栏推荐
- Does flink cdc currently support Gauss database sources?
- Vim tutorial: vimtutor
- D39_Vector
- VRRP概述及实验
- What's the point of monitoring the involution of the system?
- Introduction to Network Layer Protocols
- Insight into the general trend of the Internet, after reading this article, you will have a thorough understanding of Chinese domain names
- Media query, rem mobile terminal adaptation
- 逻辑卷创建
- 请问下通过flink sql读取hologres 的两张表的 binlog,然后如何进行join?
猜你喜欢
Vim tutorial: vimtutor
The problem come from line screening process
从“双卡双待“到”双通“,vivo率先推动DSDA架构落地
BIO,NIO,AIO实践学习笔记(便于理解理论)
LeetCode练习及自己理解记录(1)
人人AI(吴恩达系列)
King power volume LinkSLA, realize operations engineer is happy fishing
Wireshark packet capture and common filtering methods
vim教程:vimtutor
input detailed file upload
随机推荐
[问题已处理]-虚拟机报错contains a file system with errors check forced
What's the point of monitoring the involution of the system?
Four ways to obtain Class objects through reflection
Logical volume creation
Tencent Internal Technology: Evolution of Server Architecture of "The Legend of Xuanyuan"
D39_Vector
config.js related configuration summary
input detailed file upload
产品学习资料
One-arm routing experiment and three-layer switch experiment
RAID disk array
磁盘管理与文件系统
Advantages of overseas servers
el-progress implements different colors of the progress bar
The size of the screen adaptation
sql server duplicate values are counted after
What?CDN cache acceleration only works for accelerating static content?
LeetCode中常用语言的一些基本方法记录
wc, grep, tar, vi/vim
sql server 重复值在后面计数