NRF52840 learning journey (two) button 01CPU scan version

Time in 2021 Nian 1 Yue 25 Ri , winter vacation home, a good school to learn

 

Development Board : snow's 100 head piece NRF52840 EVAL KIT

Download tool: JINLK V11 (preferably JLINK V9 or higher, some people use JLINK OB, other downloaders STLINK, DAP are not recommended)

Version number: KEIL5 programming environment, CMSIS is 5.3.0, CMSIS of NRF52840 is 8.35.0

Reference material: NRF52840-Eval-Kit-Schematic.pdf (Schematic)

nRF5_SDK_17.0.2_d674dde (official routine)

nRF5_SDK_17.0.0_offline_doc (official document)

 

Realization function: button light

 

Button schematic

The IO ports are 11 and 18, of which 18 is the RESET button, I don't know if it can be used as a normal button, I will try

Configure IO as up input, then when the button is pressed, it is 0 level, when the button is not pressed or released, it is high level

Use nrf_gpio_cfg_input to configure as input mode

Code      

nrf_gpio_cfg_input(11,NRF_GPIO_PIN_PULLUP );

       nrf_gpio_cfg_input(18,NRF_GPIO_PIN_PULLUP );

 

Now the IO scan mode reads the button

code show as below      

while(1)
	{
		if(0 == nrf_gpio_pin_read(11))
		{
			nrf_delay_ms(10); //xiaodou
			if(0 == nrf_gpio_pin_read(11))
			{
				nrf_gpio_pin_toggle(LED0);
				
				while(0 == nrf_gpio_pin_read(11));
			}
		}
		
	}

 

Phenomenon: Press the button, the LED status is reversed

 

I tried 18 pins, and there is no way to control it. It should be the reset pin. You may need to cancel its reset function to use it as a normal IO port. I don't know it now, and I won't tell you if I learn

 

The overall code is as follows:

#include <stdbool.h>
#include <stdint.h>
#include "nrf_delay.h"
#include "nrf_delay.h"

/**
 * @brief Function for application main entry.
 */
int main(void)
{
	uint32_t LED0,LED1,LED2,LED3;
	uint32_t KEY0,KEY1;
	
	LED0 =  NRF_GPIO_PIN_MAP(0,13);
	LED1 =  NRF_GPIO_PIN_MAP(0,14);
	LED2 =  NRF_GPIO_PIN_MAP(1,9);
	LED3 =  NRF_GPIO_PIN_MAP(0,16);
	
	KEY0 =  NRF_GPIO_PIN_MAP(0,11);
	KEY1 =  NRF_GPIO_PIN_MAP(0,18);

	nrf_gpio_cfg_output(13);
	nrf_gpio_cfg_output(14);
	nrf_gpio_cfg_output(41);
	nrf_gpio_cfg_output(16);

	nrf_gpio_pin_set(13);
	nrf_gpio_pin_set(14);
	nrf_gpio_pin_set(41);
	nrf_gpio_pin_set(16);
	
	nrf_gpio_cfg_input(11,NRF_GPIO_PIN_PULLUP );
	nrf_gpio_cfg_input(18,NRF_GPIO_PIN_PULLUP );
	
	
	while(1)
	{
		if(0 == nrf_gpio_pin_read(KEY0))
		{
			nrf_delay_ms(10); //xiaodou
			if(0 == nrf_gpio_pin_read(KEY0))
			{
				nrf_gpio_pin_toggle(LED0);
				
				while(0 == nrf_gpio_pin_read(KEY0)); //songshou
			}
		}
				
	}
	
}

Continue to talk about the buttons in the next section, I haven't played yet

Guess you like

Origin blog.csdn.net/jwdeng1995/article/details/113105362