引脚的使用是最普遍也是最简单的,无非是配置,写(置位、置零、翻转),读,引脚中断。
GPIO简介
- 51822有31个引脚(可惜我的电路板引出来的只有很少的几个),分别是P0.0-P0.30,可以通过管脚配置寄存器PIN_CNF[n] register (n=0..30),对每个管脚进行单独的配置。配置的参数包括:
- Direction 方向(输入、输出)
- Drive strength 驱动方式(开漏输出、推挽输出等)
- Enabling of pull-up and pull-down resistors 允许上/下拉电阻
- Pin sensing
- Input buffer disconnect
- Analog input (for selected pins) 模拟输入(只对特定的AD引脚)
GPIO操作
初始化
#include "nrf_gpio.h"
这个库文件已经封装的很好了,初始化很简单,设置输出或者输入,简单明了。
#define LED_0 8 // led1 引脚P0.8
#define LED_1 9 // led2 引脚P0.9
#define LED_2 10 // led3 引脚P0.10
#define key1 22 //key1 引脚P0.22