EFM32例程——LETIMER

硬件:EFM32GG230512
工具:keil5

LETIMER实验
LETIMER测试,输出PWM波

初始化

/*********************************************Copyright (c)***********************************************
** File name:             	adc.c
** Created by:				Gui              
** Version:               	V1.0.0
** Descriptions:         	LETIMER测试,输出PWM波
*********************************************************************************************************/
#include "letimer.h"

void letimer_init(void){

	CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFRCO); 
	CMU_ClockEnable(cmuClock_CORELE, true);
	CMU_ClockEnable(cmuClock_LETIMER0, true);  
//	CMU_ClockEnable(cmuClock_GPIO, true);
                         
    const LETIMER_Init_TypeDef tLetimerInit = 
    {
        .enable         = true,                                         /* 初始化完成后使能             */
        .debugRun       = true,                                         /* 调试期间不运行               */
        .rtcComp0Enable = false,                                        /* 禁能RTC匹配0触发启动         */
        .rtcComp1Enable = false,                                        /* 禁能RTC匹配1触发启动         */
        .comp0Top       = true,                                         /* COMP0作为计数器顶端值        */
        .bufTop         = false,                                        /* 禁能COMP1作为COMP0缓冲       */
        .out0Pol        = 0,                                            /* OUT0空闲输出低电平           */
        .out1Pol        = 0,                                            /* OUT1空闲输出低电平           */
        .ufoa0          = letimerUFOAPulse,                             /* OUT0输出脉冲                 */
        .ufoa1          = letimerUFOANone,                              /* OUT1无输出                   */
        .repMode        = letimerRepeatFree                             /* 自由模式                     */
    };
    LETIMER_Init(LETIMER0, &tLetimerInit);
	
	//COMP0决定输出脉冲频率,在本例程中配置脉冲输出频率为 32000/(COMP0+1)
    LETIMER_CompareSet(LETIMER0, 0, 499);//32000/(499+1)=64
  
    LETIMER_RepeatSet(LETIMER0, 0, 1);
    
	//使能LETIMER0的输出0,并使用LOC1映射
    LETIMER0->ROUTE = LETIMER_ROUTE_OUT0PEN | LETIMER_ROUTE_LOCATION_LOC1;
    
    GPIO_PinModeSet(gpioPortB, 11, gpioModePushPull, 1);                 /* 作LETIMER输出     */
}


main

/*********************************************Copyright (c)***********************************************
** File name:             	  	main.c
** Created by:					Gui              
** Version:               		V1.0.0        
** Descriptions:            	LETIMER测试,输出PWM波
*********************************************************************************************************/
#include "system.h"
#include "em_device.h"
#include "em_chip.h"
#include "em_cmu.h"
#include "em_int.h"
#include "delay.h"
#include "letimer.h"
#include "bsp_led.h"

uint32_t g_chip_tick = 0;

int main(){
	
	CMU_ClockEnable(cmuClock_HFPER, true); //前置芯片设置
	CMU_ClockEnable(cmuClock_GPIO, true);
	if(SysTick_Config(SystemCoreClockGet()/1000))while(1);//1ms的systick中断
	led_init();//PD4 PD5
	letimer_init();//PB11
	
	while(1){
		EMU_EnterEM2(false);
	}
}


你可能感兴趣的:(EFM32)