EFM32片内外设--LETimer Free Mode

/***************************************************
LETimer应用示例1: LETimer Free Mode
硬件环境: TG840 STK
                      LED灯 - PD7
                      LETimer0, Clock source: LFRCO
软件环境: IAR 6.30
效果:          LED灯1秒闪烁一次
***************************************************/

#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, 32765/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        = letimerRepeatFree,      /*Free mode*/
    };
   
    /* Initialize LETIMER */
    LETIMER_Init(LETIMER0, &letimerInit);
   
    LETIMER0->IEN = LETIMER_IEN_COMP0;
   
    NVIC_EnableIRQ(LETIMER0_IRQn);
}

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

void main(void)
{
    /* Align different chip revisions */
    CHIP_Init();
   
    CMU_ClockEnable(cmuClock_GPIO, true);
   
    GPIO_PinModeSet(gpioPortD, 7, gpioModePushPull,0);
   
    LETimer0_Initial();
   
    while(1)
    {
        EMU_EnterEM2(false);
    }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值