nRF51822看门狗实战运用

#include 
#include 
#include "nrf.h"
#include "nrf_delay.h"
#include "nrf_gpio.h"

#define LED0  (18)
#define LED1  (19)
#define RELOAD_COUNT (32768*5 - 1)    // 5 seconds

void wdt_init(void)
{
    NRF_WDT->TASKS_START = 0;
    NRF_WDT->CRV = RELOAD_COUNT;//5s
    NRF_WDT->CONFIG =
    WDT_CONFIG_HALT_Pause << WDT_CONFIG_HALT_Pos |//pause wdt when halt
    WDT_CONFIG_SLEEP_Pause << WDT_CONFIG_SLEEP_Pos;//pause wdt when sleep
    NRF_WDT->RREN = WDT_RREN_RR0_Enabled << WDT_RREN_RR0_Pos;//en RR[0]
}

void wdt_start(void)
{
    NRF_WDT->TASKS_START = 1;
}

void wdt_feed(void)
{
    NRF_WDT->RR[0] = WDT_RR_RR_Reload;
}

int main(void)
{
	nrf_gpio_cfg_output(LED0);
	nrf_gpio_pin_clear(LED0);

	nrf_gpio_cfg_output(LED1);
	nrf_gpio_pin_clear(LED1);
	
	unsigned int i = 10;	
	while(i--)
	{
		nrf_delay_ms(100);
		nrf_gpio_pin_toggle(LED1);//detect reset
	}
	nrf_gpio_pin_clear(LED1);
	
	wdt_init();
	wdt_start();
	while(1)
	{
		wdt_feed();
		nrf_delay_ms(1000);
		nrf_gpio_pin_toggle(LED0);
	}
}

 

你可能感兴趣的:(嵌入式)