EFM32例程——CMU

硬件:EFM32GG230512
工具:keil5

CMU实验
CMU测试,输出时钟

初始化

/*********************************************Copyright (c)***********************************************
** File name:             	cmu.c
** Created by:				Gui              
** Version:               	V1.0.0
** Descriptions:           
*********************************************************************************************************/
#include "cmu.h"

void cmu_init(void){
	 CMU_ClockEnable(cmuClock_GPIO, true);                   
    /*
     *  将相应的GPIO口设置成输出,PA1输出低频,PA2输出高频
     */
    GPIO_PinModeSet(gpioPortA, 1, gpioModePushPull, 1);
    GPIO_PinModeSet(gpioPortA, 2, gpioModePushPull, 1);

    CMU_HFRCOBandSet(cmuHFRCOBand_1MHz);                                /* HFRCO设置为1MHz*/
    CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFRCO);                   /* HFCLK选择HFRCO*/
    CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFRCO);                  /* LFCLK选择LFRCO*/
//	CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);	
//	CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFXO); 
    /*
     *  配置PA1、PA2输出时钟类型
     */
	CMU->CTRL |= CMU_CTRL_CLKOUTSEL0_HFRCO + CMU_CTRL_CLKOUTSEL1_LFRCO;
//	CMU->CTRL |= CMU_CTRL_CLKOUTSEL0_HFXO + CMU_CTRL_CLKOUTSEL1_LFXO;
    /*
     *  允许GPIO的复用功能
     */
	CMU->ROUTE = CMU_ROUTE_CLKOUT0PEN | CMU_ROUTE_CLKOUT1PEN | CMU_ROUTE_LOCATION_LOC0;         
}

main

/*********************************************Copyright (c)***********************************************
** File name:             	  	main.c
** Created by:					Gui              
** Version:               		V1.0.0        
** Descriptions:            	CMU测试,输出时钟
*********************************************************************************************************/
#include "system.h"
#include "em_device.h"
#include "em_chip.h"
#include "em_cmu.h"
#include "em_emu.h"
#include "delay.h"
#include "cmu.h"

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
	cmu_init();//PA1 PA2 
	
	while(1){
	}
}

你可能感兴趣的:(EFM32)