当前位置:网站首页>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
边栏推荐
- What's the point of monitoring the involution of the system?
- link 和@improt的区别
- 监控系统的内卷,有什么讲究?
- Network Troubleshooting Basics - Study Notes
- 媒体查询、rem移动端适配
- sql server 重复值在后面计数
- What is Alibaba Cloud Express Beauty Station?
- wc, grep, tar, vi/vim
- Transformer interprets and predicts instance records in detail
- Does flink cdc currently support Gauss database sources?
猜你喜欢

input详解之文件上传

监控系统的内卷,有什么讲究?

Q 2020, the latest senior interview Laya soul, do you know?

Problems encountered in installing Yolo3 target detection module in Autoware

In-depth Zabbix user guide - from the green boy

Mina断线重连

LinkSLA insists that users come first and creates a sustainable operation and maintenance service plan

带你深入了解Cookie

错误类型:反射。ReflectionException:无法设置属性“xxx”的“类”xxx”与价值“xxx”

Alibaba Cloud Video on Demand
随机推荐
The hook of the operation of the selenium module
The highlight moment of operation and maintenance starts with intelligence
Cloud Computing Basics - Study Notes
Network wiring and digital-to-system conversion
多线程之传递参数
Tencent greetings function SCF - entry instructions
[ingress]-ingress exposes services using tcp port
H5 的浏览器存储
Browser Storage for H5
618,你也许可以清醒亿点点
LeetCode中常用语言的一些基本方法记录
The method of using ROS1 bag under ROS2
Q 2020, the latest senior interview Laya soul, do you know?
Tencent Cloud Message Queue CMQ
浏览器兼容汇总
产品学习资料
RAID disk array
Autoware--Beike Tianhui rfans lidar uses the camera & lidar joint calibration file to verify the fusion effect of point cloud images
Xiaodu Xiaodu is here!
link 和@improt的区别