Discuz! Board

标题: NRF51822 定时器中断 [打印本页]

作者: wolfdong7    时间: 2015-6-2 09:12
标题: NRF51822 定时器中断
教程的定时器中断,感觉像延时一样。

能不能像中断一样,设置初始值,计数到了,跳入IRQ里面处理。
作者: wolfdong7    时间: 2015-6-2 11:28
已解决!代码工程:http://pan.baidu.com/s/1pr9IQ

#include "nrf51.h"
#include "nrf_gpio.h"
#include "led.h"
#include "time.h"
#include <stdbool.h>
#include <stdint.h>

void time1_init(void)  //&para;¨&Ecirc;±&AElig;÷&sup3;&otilde;&Ecirc;&frac14;&raquo;&macr;,&para;¨&Ecirc;±1s
{

    NRF_TIMER2->MODE        = TIMER_MODE_MODE_Timer;
    NRF_TIMER2->PRESCALER   = 9;  //Ftimer  = 31250 Hz   =32us

    NRF_TIMER2->CC[2]       = (31250U);  //=32us*31250=1s
    NRF_TIMER2->INTENSET    = TIMER_INTENSET_COMPARE2_Enabled << TIMER_INTENSET_COMPARE2_Pos;


    NRF_TIMER2->SHORTS      = (TIMER_SHORTS_COMPARE1_CLEAR_Enabled << TIMER_SHORTS_COMPARE1_CLEAR_Pos);
               
                NVIC_ClearPendingIRQ(TIMER2_IRQn);
    NVIC_SetPriority(TIMER2_IRQn,3);
                NVIC_EnableIRQ(TIMER2_IRQn);  
          NRF_TIMER2->TASKS_START = 1; //&iquest;&ordf;&AElig;&ocirc;&para;¨&Ecirc;±&AElig;÷
}
void TIMER2_IRQHandler(void)  //&para;¨&Ecirc;±&AElig;÷&Ouml;&ETH;&para;&Iuml;&Auml;&pound;&Ecirc;&frac12;·&thorn;&Icirc;&ntilde;&ordm;&macr;&Ecirc;&yacute;
{

    if ((NRF_TIMER2->EVENTS_COMPARE[2] == 1) && (NRF_TIMER2->INTENSET & TIMER_INTENSET_COMPARE2_Msk))
    {
      NRF_TIMER2->EVENTS_COMPARE[2] = 0;
   
      LED2_UN;//&micro;&ccedil;&AElig;&frac12;·&shy;×&ordf;


                         NRF_TIMER2->TASKS_CLEAR = 1; //&Ccedil;&aring;&sup3;&thorn;&frac14;&AElig;&Euml;&atilde;
    }

}

int main(void)
{
  LED_Init();
        KEY_Init();
        EXIT_Init();
                time1_init(); //&sup3;&otilde;&Ecirc;&frac14;&raquo;&macr;time&pound;&raquo;
  LED1_ON;
        LED2_ON;       
        LED2_UN;
       
  // LED 0 and LED 1 blink alternately.
  while(1)
  {
           
                                               
   
    nrf_delay_ms(500);
   
   
   
    nrf_delay_ms(500);
  }
}

作者: admin    时间: 2015-6-5 11:33
wolfdong7 发表于 2015-6-2 11:28
已解决!代码工程:http://pan.baidu.com/s/1pr9IQ

#include "nrf51.h"

这个要支持
作者: wolfdong7    时间: 2015-6-6 14:30
admin 发表于 2015-6-5 11:33
这个要支持

谢谢!
期待版主为我们新手写出更多的好教程来。
作者: ldcung    时间: 2015-9-5 13:40
wolfdong7 发表于 2015-6-2 11:28
已解决!代码工程:http://pan.baidu.com/s/1pr9IQ

#include "nrf51.h"

赞一个,正需要它。

作者: vipfanghui    时间: 2015-11-17 14:40
wolfdong7 发表于 2015-6-2 11:28
已解决!代码工程:http://pan.baidu.com/s/1pr9IQ

#include "nrf51.h"

大赞,正需要这个。
作者: sinba    时间: 2015-11-26 11:31
那天也研究了好久没搞明白;谢谢楼主了





欢迎光临 Discuz! Board (http://www.qfv8.com/) Powered by Discuz! X3