volatile long sekunden; #define LF_FREQUENCY 32768UL #define SECONDS(x) ((uint32_t)((LF_FREQUENCY * x) + 0.5)) #ifdef __cplusplus extern "C" { #endif void settimer(){ NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos; NRF_CLOCK->TASKS_LFCLKSTART = 1; while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0); NRF_CLOCK->EVENTS_LFCLKSTARTED = 0; NRF_RTC0->PRESCALER = 0; NRF_RTC0->CC[0] = SECONDS(1); NRF_RTC0->EVTENSET = RTC_EVTENSET_COMPARE0_Enabled << RTC_EVTENSET_COMPARE0_Pos; NRF_RTC0->INTENSET = RTC_INTENSET_COMPARE0_Enabled << RTC_INTENSET_COMPARE0_Pos; NVIC_EnableIRQ(RTC0_IRQn); NRF_RTC0->TASKS_START = 1; } #ifdef __cplusplus } #endif #ifdef __cplusplus extern "C" { #endif void RTC0_IRQHandler(void) { volatile uint32_t dummy; if (NRF_RTC0->EVENTS_COMPARE[0] == 1) { NRF_RTC0->EVENTS_COMPARE[0] = 0; NRF_RTC0->CC[0] = NRF_RTC0->COUNTER + SECONDS(1); sekunden++; dummy = NRF_RTC0->EVENTS_COMPARE[0]; dummy; } } #ifdef __cplusplus } #endif