当前位置:网站首页>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
边栏推荐
- Tencent Internal Technology: Evolution of Server Architecture of "The Legend of Xuanyuan"
- Successful indie developers deal with failure & imposters
- Native JS takes you to understand the implementation and use of array methods
- 教您简单几步实现工业树莓派正确安装RS232转USB驱动
- Insight into the general trend of the Internet, after reading this article, you will have a thorough understanding of Chinese domain names
- The future of cloud gaming
- LeetCode中常用语言的一些基本方法记录
- 产品学习资料
- 5分钟完成mysql离线安装
- 错误记录集锦(遇到则记下)
猜你喜欢

Complete mysql offline installation in 5 minutes

路由器和静态路由的配置

人人AI(吴恩达系列)

NAT experiment
time complexity and space complexity

Chengyun Technology was invited to attend the 2022 Alibaba Cloud Partner Conference and won the "Gathering Strength and Going Far" Award

The hook of the operation of the selenium module

System basics - study notes (some command records)
![[问题已处理]-jenkins流水线checkout超时](/img/3d/c14276d2b5ce18fc3d1288abb059c0.png)
[问题已处理]-jenkins流水线checkout超时

Dry!Teach you to use industrial raspberries pie combining CODESYS configuration EtherCAT master station
随机推荐
LeetCode刷题记录(2)
In-depth Zabbix user guide - from the green boy
DisabledDate date picker datePicker
七种让盒子水平垂直居中的方法
What are some things that you only know when you do operation and maintenance?
Vim tutorial: vimtutor
The use of three parameters of ref, out, and Params in Unity3D
BIO,NIO,AIO实践学习笔记(便于理解理论)
Browser Storage for H5
单臂路由实验和三层交换机实验
Chengyun Technology was invited to attend the 2022 Alibaba Cloud Partner Conference and won the "Gathering Strength and Going Far" Award
What's the point of monitoring the involution of the system?
错误类型:反射。ReflectionException:无法设置属性“xxx”的“类”xxx”与价值“xxx”
H5开发调试-Fiddler手机抓包
The method of using ROS1 bag under ROS2
记录vue-页面缓存问题
Successful indie developers deal with failure & imposters
VLAN介绍与实验
CIPU, what impact does it have on the cloud computing industry?
User and user group management, file permission management