nRF51 Example 4 - Key and Interrupt

Source work

A key and an Interrupt

My assignment:

And other 3 keys and Interrupts

Please click “more” on the right!

Part of my source files

exit.c

1
void EXIT_KEY_Init(void)
{

	nrf_gpio_cfg_input(KEY_1,GPIO_PIN_CNF_PULL_Pullup);
	nrf_gpio_cfg_input(KEY_2,GPIO_PIN_CNF_PULL_Pullup);
	nrf_gpio_cfg_input(KEY_3,GPIO_PIN_CNF_PULL_Pullup);
	nrf_gpio_cfg_input(KEY_4,GPIO_PIN_CNF_PULL_Pullup);


	NVIC_EnableIRQ(GPIOTE_IRQn);

	NRF_GPIOTE->CONFIG[0] =  (GPIOTE_CONFIG_POLARITY_HiToLo << GPIOTE_CONFIG_POLARITY_Pos)
	                        | (30 << GPIOTE_CONFIG_PSEL_Pos)
	                        | (GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos);
	NRF_GPIOTE->INTENSET  = GPIOTE_INTENSET_IN0_Set << GPIOTE_INTENSET_IN0_Pos;


	NRF_GPIOTE->CONFIG[1] = (GPIOTE_CONFIG_POLARITY_HiToLo << GPIOTE_CONFIG_POLARITY_Pos)
	                        |(21 << GPIOTE_CONFIG_PSEL_Pos)
	                        |(GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos);
	NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_IN1_Set << GPIOTE_INTENSET_IN1_Pos;


	NRF_GPIOTE->CONFIG[2] = (GPIOTE_CONFIG_POLARITY_HiToLo << GPIOTE_CONFIG_POLARITY_Pos)
	                        |(22 << GPIOTE_CONFIG_PSEL_Pos)
	                        |(GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos);
	NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_IN2_Set << GPIOTE_INTENSET_IN2_Pos;


	NRF_GPIOTE->CONFIG[3] = (GPIOTE_CONFIG_POLARITY_HiToLo << GPIOTE_CONFIG_POLARITY_Pos)
	                        |(23 << GPIOTE_CONFIG_PSEL_Pos)
	                        |(GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos);
	NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_IN3_Set << GPIOTE_INTENSET_IN3_Pos;

}


void GPIOTE_IRQHandler(void)
{

	if ((NRF_GPIOTE->EVENTS_IN[0] == 1) &&
	    (NRF_GPIOTE->INTENSET & GPIOTE_INTENSET_IN0_Msk))
	{
		NRF_GPIOTE->EVENTS_IN[0] = 0;
		LED_Toggle(LED_0);
	}

	if ((NRF_GPIOTE->EVENTS_IN[1] == 1)&&
	    (NRF_GPIOTE->INTENSET & GPIOTE_INTENSET_IN1_Msk))
			{
		NRF_GPIOTE->EVENTS_IN[1] = 0;
		LED_Toggle(LED_1);
	}

	if ((NRF_GPIOTE->EVENTS_IN[2] == 1)&&
	    (NRF_GPIOTE->INTENSET & GPIOTE_INTENSET_IN2_Msk))
			{
		NRF_GPIOTE->EVENTS_IN[2] = 0;
		LED_Toggle(LED_2);
	}

	if ((NRF_GPIOTE->EVENTS_IN[3] == 1)&&
	    (NRF_GPIOTE->INTENSET & GPIOTE_INTENSET_IN3_Msk))
			{
		NRF_GPIOTE->EVENTS_IN[3] = 0;
		LED_Toggle(LED_3);
	}
}

Download my files


This work is licensed under a Creative Commons Attribution 4.0 International License.

文章目录
  1. 1. Source work
  2. 2. My assignment:
  3. 3. Part of my source files
    1. 3.1. exit.c
,