📄 k60-keil
字号:
/*============================================================================
文件名称:DAC.c
功能概要:K60 DAC
版权所有:卿丞数码
============================================================================*/
#include <MK60N512MD100.h> // MK60N512MD100 Definitions
#include "DAC.h" //包含DAC驱动程序头文件
/*============================================================================
函数名称:DAC_init
函数返回:无
参数说明:DAC_Channel:通道号DAC0 DAC1。
功能概要:初始化DAC模块设定。
=============================================================================*/
void DAC_Init(DAC_Type *DAC_Channel)
{
if(DAC_Channel == DAC0)
{
SIM->SCGC2 |= SIM_SCGC2_DAC0_MASK ; //使能DAC 0
}
else
{
SIM->SCGC2 |= SIM_SCGC2_DAC1_MASK ; //使能DAC 1
}
SIM->SCGC4 |= SIM_SCGC4_VREF_MASK ; // 参考电压初始化
VREF->SC |= VREF_SC_VREFEN_MASK; //The module is enabled
VREF->SC |= VREF_SC_REGEN_MASK; // This bit is used to enable the 1.75 V regulator that can reduce supply variation of the Voltage Reference
while (!(VREF->SC & VREF_SC_VREFST_MASK)); //wait for The module is disabled or not stable.
DAC_Channel->C1 &=~ DAC_C1_DMAEN_MASK ; //DMA enable select 0
DAC_Channel->C0 |= DAC_C0_DACRFS_MASK ; //DACREF_2 参考电压 0=1.75V,1=VDDA=3.3V
DAC_Channel->C0 |= DAC_C0_DACTRGSEL_MASK; //The DAC software trigger is selected.
DAC_Channel->C0 |= DAC_C0_LPEN_MASK; //low power mode.
DAC_Channel->C0 |= DAC_C0_DACEN_MASK ; //The DAC system is enabled
}
/*============================================================================
函数名称:DAC_Convert
函数返回:void
参数说明:DAC_Channel:通道号DAC0 DAC1。
VolSetValue: 电压转换设置值 范围(0~4095)
功能概要:执行DAC转换。
When the DAC Buffer is not enabled, DATA[11:0] controls the output voltage based on the following
formula. Vout = Vin * (1 + DACDAT0[11:0])/4096
When the DAC Buffer is enabled, DATA is mapped to the 16-word buffer.
=============================================================================*/
void DAC_Convert(DAC_Type *DAC_Channel, unsigned short VolSetValue)
{
DAC_Channel->DAT[0].DATL=VolSetValue&0x00ff;
DAC_Channel->DAT[0].DATH=(VolSetValue&0x0f00)>>8;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -