EFM32片内外设--LETimer One-short Mode

 /***************************************************
LETimer应用示例1: LETimer One-shot Mode
解释:     The timer runs as long as REP0 != 0.
                 REP0 is decremented at each timer underflow.
注意:      LETimer 运行完毕之后,自动停止。
硬件环境: TG STK
           LED灯 - PD7
           LETimer0, Clock source: LFRCO
           按PB0,重新触发一次LETimer
软件环境: IAR 6.30
           在中断中触发了REP0和下溢出中断
效果:  LED灯闪烁3次。闪烁完3次之后,自动停止。可按PB0触发,重新闪烁三次
***************************************************/

#include "efm32.h"
#include "efm32_cmu.h"
#include "efm32_emu.h"
#include "efm32_letimer.h"
#include "efm32_gpio.h"
#include "efm32_rtc.h"
#include "efm32_chip.h"

void LETimer0_Initial(void)
{
    CMU_ClockSelectSet(cmuClock_LFA,cmuSelect_LFRCO);
    CMU_ClockEnable(cmuClock_CORELE, true);
    CMU_ClockEnable(cmuClock_LFA,true);
    CMU_ClockEnable(cmuClock_LETIMER0, true);

    /* Set initial compare values for COMP0 */
    LETIMER_CompareSet(LETIMER0, 0, 32768/2);
   
    /* Set configurations for LETIMER 0 */
    const LETIMER_Init_TypeDef letimerInit =
    {
        .enable         = true,                  /* Don't start counting when init completed - only with RTC compare match */
        .debugRun       = false,                  /* Counter shall not keep running during debug halt. */
        .rtcComp0Enable = false,                   /* Start counting on RTC COMP0 match. */
        .rtcComp1Enable = false,                  /* Don't start counting on RTC COMP1 match. */
        .comp0Top       = true,                   /* Load COMP0 register into CNT when counter underflows. COMP is used as TOP */
        .bufTop         = false,                  /* Don't load COMP1 into COMP0 when REP0 reaches 0. */
        .out0Pol        = 0,                      /* Idle value for output 0. */
        .out1Pol        = 0,                      /* Idle value for output 1. */
        .ufoa0          = letimerUFOANone,        /* Pulse output on output 0 */
        .ufoa1          = letimerUFOANone,        /* No output on output 1*/
        .repMode        = letimerRepeatOneshot,   /* Count while REP != 0 */
    };
   
    /* Initialize LETIMER */
    LETIMER_Init(LETIMER0, &letimerInit);
   
    LETIMER0->REP0 =0x05;
   
    LETIMER0->IEN = LETIMER_IEN_REP0 | LETIMER_IEN_COMP0;
   
    NVIC_EnableIRQ(LETIMER0_IRQn);
}

/**************************************************************************//**
 * @brief  Main function
 * Main is called from __iar_program_start, see assembly startup file
 *****************************************************************************/
int main(void)

    /* Align different chip revisions */
    CHIP_Init();

    //Config the PD7 as the LED
    CMU_ClockEnable(cmuClock_GPIO, true);
    GPIO_PinModeSet(gpioPortD, 7, gpioModePushPull,0);
   
    /* Configure PD8 and PB11 as input */
    GPIO_PinModeSet(gpioPortD, 8, gpioModeInput, 0);
    /* Set falling edge interrupt for both ports */
    GPIO_IntConfig(gpioPortD, 8, false, true, true);
 
    /* Enable interrupt in core for even and odd gpio interrupts */
    NVIC_ClearPendingIRQ(GPIO_EVEN_IRQn);
    NVIC_EnableIRQ(GPIO_EVEN_IRQn);
   
    LETimer0_Initial();
   
    while(1)
    {
        EMU_EnterEM2(false);
    }
}

void LETIMER0_IRQHandler(void)
{    
    GPIO_PinOutToggle(gpioPortD, 7);
    LETIMER0->IFC = LETIMER_IFC_REP0 | LETIMER_IFC_COMP0;
}

/**************************************************************************//**
 * @brief GPIO Interrupt handler (PD8)
 *****************************************************************************/
void GPIO_EVEN_IRQHandler(void)
{
    LETIMER0->REP0 =0x05;
    LETIMER_Enable(LETIMER0,true);
   
    /* Acknowledge interrupt */
    GPIO_IntClear(1 << 8);
}

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值