NRF51822之app_button使用
我们现在开始使用app_button,为什么要使用这个来替代直接使用GPIOTE呢?
因为我们在手册中可以看到如果一直开启GPIOTE in模式的需要需要很大电流。所以我们需要使用RTC来“周期”的查询。
/** @file * @brief Example app_button project. * */ #include <stdbool.h> #include <string.h> #include "app_button.h" #include "boards.h" #include "app_gpiote.h" #include "app_timer.h" #define APP_TIMER_PRESCALER 0 /**< Value of the RTC1 PRESCALER register. */ #define APP_TIMER_OP_QUEUE_SIZE 4 /**< Size of timer operation queues. */ #define BUTTON_DEBOUNCE_DELAY 50 // Delay from a GPIOTE event until a button is reported as pushed. #define APP_GPIOTE_MAX_USERS 1 // Maximum number of users of the GPIOTE handler. /* * Handler to be called when button is pushed. * param[in] pin_no The pin number where the event is genereated * param[in] button_action Is the button pushed or released */ static void button_handler(uint8_t pin_no, uint8_t button_action) { if(button_action == APP_BUTTON_PUSH) { switch(pin_no) { case BUTTON_1: nrf_gpio_pin_toggle(LED_1); break; case BUTTON_2: nrf_gpio_pin_toggle(LED_2); break; case BUTTON_3: nrf_gpio_pin_toggle(LED_3); break; case BUTTON_4: nrf_gpio_pin_toggle(LED_4); break; default: break; } } //if(button_action == APP_BUTTON_RELEASE)//键释 } /** * Initialize the clock. */ void init_clock() { NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos); NRF_CLOCK->EVENTS_LFCLKSTARTED = ; NRF_CLOCK->TASKS_LFCLKSTART = ; ); // Wait for clock to start } /** * Initialize all four LEDs on the nRF51 DK. */ void init_leds() { nrf_gpio_cfg_output(LED_1); nrf_gpio_cfg_output(LED_2); nrf_gpio_cfg_output(LED_3); nrf_gpio_cfg_output(LED_4); nrf_gpio_pin_set(LED_1); nrf_gpio_pin_set(LED_2); nrf_gpio_pin_set(LED_3); nrf_gpio_pin_set(LED_4); } /**@brief Function for the Power Management. */ static void power_manage(void) { // Use directly __WFE and __SEV macros since the SoftDevice is not available. // Wait for event. __WFE(); // Clear Event Register. __SEV(); __WFE(); } /** * Function for application main entry. */ int main(void) { init_leds(); init_clock(); uint32_t err_code; // Button configuration structure. static app_button_cfg_t p_button[] = { {BUTTON_1, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_PULLUP, button_handler}, {BUTTON_2, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_PULLUP, button_handler}, {BUTTON_3, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_PULLUP, button_handler}, {BUTTON_4, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_PULLUP, button_handler}}; // Macro for initializing the application timer module. // It will handle dimensioning and allocation of the memory buffer required by the timer, making sure that the buffer is correctly aligned. It will also connect the timer module to the scheduler (if specified). APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, NULL); // Macro for initializing the GPIOTE module. // It will handle dimensioning and allocation of the memory buffer required by the module, making sure that the buffer is correctly aligned. APP_GPIOTE_INIT(APP_GPIOTE_MAX_USERS); // Initializing the buttons. err_code = app_button_init(p_button, ]), BUTTON_DEBOUNCE_DELAY); APP_ERROR_CHECK(err_code); // Enabling the buttons. err_code = app_button_enable(); APP_ERROR_CHECK(err_code); while(true) { power_manage(); } }
需要注意的是app_button底层调用app_time和app_gpiote。而在裸机下需要我们配置好32khz时钟,即在代码中init_clock。
NRF51822之app_button使用的更多相关文章
- nRF51822之app_button控制uart的开启和关闭
为什么要使用app_button来控制uart的开启和关闭 还是先上datesheet中uart开启的时候需要HFCLK,需要消耗大量大电流.所以在我们需要的时候需要通过io来通知nrf51822开启 ...
- nrf51822中app_button 的应用
Button Handler(按键处理程序) 按键处理程序是使用GPIOTE(GPIO Task and Event)的处理机制实现的,为了防止按键的抖动.在GPIOTE event(事件)处理程序中 ...
- NRF51822之GPIOTE使用
---恢复内容开始--- 在上篇介绍nrf51822的GPIOTE http://www.cnblogs.com/libra13179/p/5336580.html 我们现在开始下水游泳. /** @ ...
- [nRF51822] 14、浅谈蓝牙低功耗(BLE)的几种常见的应用场景及架构(科普类干货)
蓝牙在短距离无线通信领域占据举足轻重的地位—— 从手机.平板.PC到车载设备, 到耳机.游戏手柄.音响.电视, 再到手环.电子秤.智能医疗器械(血糖仪.数字血压计.血气计.数字脉搏/心率监视器.数字体 ...
- [nRF51822] 13、浅谈nRF51822和NRF24LE1/NRF24LU1/NRF24L01经典2.4G模块无线通信配置与流程
前言: nRF51可以支持基于2.4G的互相通信.与NRF24LE1的通信.与NRF24LU1的通信.与NRF24L01的通信. 一.nRF51822基于2.4G和nRF51822通信 其中nRF5 ...
- [nRF51822] 12、基础实验代码解析大全 · 实验19 - PWM
一.PWM概述: PWM(Pulse Width Modulation):脉冲宽度调制技术,通过对一系列脉冲的宽度进行调制,来等效地获得所需要波形. PWM 的几个基本概念: 1) 占空比:占空比是指 ...
- [nRF51822] 11、基础实验代码解析大全 · 实验16 - 内部FLASH读写
一.实验内容: 通过串口发送单个字符到NRF51822,NRF51822 接收到字符后将其写入到FLASH 的最后一页,之后将其读出并通过串口打印出数据. 二.nRF51822芯片内部flash知识 ...
- [nRF51822] 10、基础实验代码解析大全 · 实验15 - RTC
一.实验内容: 配置NRF51822 的RTC0 的TICK 频率为8Hz,COMPARE0 匹配事件触发周期为3 秒,并使能了TICK 和COMPARE0 中断. TICK 中断中驱动指示灯D1 翻 ...
- [nRF51822] 9、基础实验代码解析大全 · 实验12 - ADC
一.本实验ADC 配置 分辨率:10 位. 输入通道:5,即使用输入通道AIN5 检测电位器的电压. ADC 基准电压:1.2V. 二.NRF51822 ADC 管脚分布 NRF51822 的ADC ...
随机推荐
- 参加 TiD 2015 是怎样一番体验?
人生有很多第一次,(专程打飞的去帝都)参加软件大会,我也是第一次. TiD 说到软件大会,QCon.PyCon 什么的早已如雷贯耳,没吃过猪肉还没见过猪跑?但对于 TiD,确实还是头一次听说. ...
- HDU4057 Rescue the Rabbit(AC自动机+状压DP)
题目大概是给几个DNA片段以及它们各自的权值,如果一个DNA包含某个片段那么它的价值就加上这个片段的权值,同时包含多个相同DNA片段也只加一次,问长度l的DNA可能的最大价值. 与HDU2825大同小 ...
- bzoj1032 [JSOI2007]祖码Zuma
1032: [JSOI2007]祖码Zuma Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 672 Solved: 335[Submit][Stat ...
- 洛谷 P1010 幂次方 Label:模拟
题目描述 任何一个正整数都可以用2的幂次方表示.例如 137=2^7+2^3+2^0 同时约定方次用括号来表示,即a^b 可表示为a(b). 由此可知,137可表示为: 2(7)+2(3)+2(0) ...
- 【BZOJ】1180: [CROATIAN2009]OTOCI & 2843: 极地旅行社(lct)
http://www.lydsy.com/JudgeOnline/problem.php?id=1180 今天状态怎么这么不好..................................... ...
- 原创Java版的Shell
如果你接触过windows操作系统,你应该对windows中的cmd有一定的了解. 如果你接触过Linux操作系统,你应该对Linux的shell有一定的了解. 本文说的正是linux中的shell. ...
- JAVA发送邮件工具类
import java.util.Date;import java.util.Properties; import javax.mail.BodyPart;import javax.mail.Mess ...
- python中迭代器和生成器
l=[1,2,3,4] for n in l: print n 在看上面这段代码的时候,我们没有显式的控制列表的偏移量,就可以自动的遍历了整个列表对象.那么for 语句是怎么来遍历列表l的呢?要回答这 ...
- Intent学习笔记
Intent首先字面意思大概是意图.负责activity之间或者,activity与service等(我只知道这么点)之间信息的传递.就跟快递员起的作用差不多(我这这么理解),由一下六部分组成: Co ...
- php5全版本绕过open_basedir读文件脚本
这是前段时间写的代码了(http://www.weibo.com/1074745063/ByAPqj7s0),最近一直忙着和几个同学一起做非安全类的创业项目.所以也没拿到JAE.SAE测试一下. 不说 ...