EFM32例程——DAC

硬件:EFM32GG230512
工具:keil5

DAC实验
DAC测试,使用DAC输出固定电压值

初始化

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

/*********************************************************************************************************
** Function name:      DACInit
** Descriptions:       DAC配置函数
** input parameters:   none
** output parameters:  none
** Returned value:     none
*********************************************************************************************************/
void dac_init(void)
{
    CMU_ClockEnable(cmuClock_DAC0, true);                               /* 使能DAC模块时钟              */
	
    DAC_Init_TypeDef stdacinit = {
        .refresh        = dacRefresh8,                                  /* 配置刷新率                   */
        .reference      = dacRef2V5,                                    /* 参考电压配置           		*/
        .outMode        = dacOutputPin,                                 /* 配置DAC输出          		 */
        .convMode       = dacConvModeContinuous,                        /* 配置DAC转换模式        		 */
        .prescale       = DAC_PrescaleCalc(1000000, 0),                 /* 配置DAC模块时钟        		 */
        .lpEnable       = false,                                        /* 禁能低功耗模式       		 */
        .ch0ResetPre    = false,
        .outEnablePRS   = false,
        .sineEnable     = false,                                        /* 禁能正弦波输出	       		*/
        .diff           = false,                                        /* 禁能差分输出	       			*/
    };
	/* 
	 *  DAC通道配置
	 */
    DAC_InitChannel_TypeDef stdacinitChannel = {
        .enable         = false,
        .prsEnable      = false,
        .refreshEnable  = false,
        .prsSel         = dacPRSSELCh0,									/* DAC通道0       			*/
    };

    DAC_Init(DAC0, &stdacinit);
    DAC_InitChannel(DAC0, &stdacinitChannel, 0);
}

void dac_out(void){
    DAC_Enable(DAC0, 0, true);                                          /* 使能DAC0通道0                */
    DAC0->CH0DATA = (int)((1.3 * 4095) / 2.5);                          /* 在PB11管脚输出         		*/
}


main

/*********************************************Copyright (c)***********************************************
** File name:             	  	main.c
** Created by:					Gui              
** Version:               		V1.0.0        
** Descriptions:            	DAC测试,使用DAC输出固定电压值
*********************************************************************************************************/
#include "system.h"
#include "em_device.h"
#include "em_chip.h"
#include "em_cmu.h"
#include "delay.h"
#include "adc.h"
#include "dac.h"
#include "bsp_led.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
	dac_init();//PB11
	dac_out();//DAC输出电压
	
	while(1){
	}
}


你可能感兴趣的:(EFM32)