当前位置:网站首页>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
边栏推荐
- 程序员应该这样理解I/O
- ES2020新特性
- link 和@improt的区别
- Cloud computing - osi seven layers and TCP\IP protocol
- H5开发调试-Fiddler手机抓包
- 摆脱极域软件的限制
- 单臂路由实验和三层交换机实验
- Autoware--Beike Tianhui rfans lidar uses the camera & lidar joint calibration file to verify the fusion effect of point cloud images
- The highlight moment of operation and maintenance starts with intelligence
- LeetCode刷题记录(2)
猜你喜欢

VLAN介绍与实验

Mina disconnects and reconnects

From "dual card dual standby" to "dual communication", vivo took the lead in promoting the implementation of the DSDA architecture

Tencent Internal Technology: Evolution of Server Architecture of "The Legend of Xuanyuan"

NAT实验

What are some things that you only know when you do operation and maintenance?

VRRP overview and experiment

Wireshark packet capture and common filtering methods

Transformer interprets and predicts instance records in detail

多线程之传递参数
随机推荐
DisabledDate date picker datePicker
Wechat applet page jump to pass parameters
D39_ coordinate transformation
Passing parameters in multiple threads
System basics - study notes (some command records)
Xiaodu Xiaodu is here!
LinkSLA insists that users come first and creates a sustainable operation and maintenance service plan
LeetCode中常用语言的一些基本方法记录
网络排错基础-学习笔记
Cloud computing - osi seven layers and TCP\IP protocol
初识网页与浏览器
What is Alibaba Cloud Express Beauty Station?
Four ways to obtain Class objects through reflection
The problem come from line screening process
请问下通过flink sql读取hologres 的两张表的 binlog,然后如何进行join?
network issue?Service packet loss?This is enough
Q 2020, the latest senior interview Laya soul, do you know?
滚动条问题,未解决
From "dual card dual standby" to "dual communication", vivo took the lead in promoting the implementation of the DSDA architecture
time complexity and space complexity