概述
/***************************************************
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);
}
最后
以上就是舒服八宝粥为你收集整理的EFM32片内外设--LETimer One-short Mode的全部内容,希望文章能够帮你解决EFM32片内外设--LETimer One-short Mode所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复