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);
}
}