您的位置:控制工程论坛网论坛 » 教程与手册 » 汉化STM32F2.02版固件库之二十二(DAC)

常青树

常青树   |   当前状态:在线

总积分:1421  2025年可用积分:0

注册时间: 2008-09-28

最后登录时间: 2012-05-30

空间 发短消息加为好友

汉化STM32F2.02版固件库之二十二(DAC)

常青树  发表于 2008/10/13 7:21:32      1131 查看 0 回复  [上一主题]  [下一主题]

手机阅读


/*******************************************************************************
* 函数名称: DAC_DeInit
* 功能描述: Deinitializes the DAC peripheral registers to their default
*                  reset values[还原DAC外设寄存器到默认复位值].
* 输入参数: 无.
* 输出参数: 无
* 返回参数: 无
*******************************************************************************/
void DAC_DeInit(void)
{
  /* Enable DAC reset state [使能DAC复位状态]*/
  RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC, ENABLE);
  /* Release DAC from reset state [解除DAC复位状态]*/
  RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC, DISABLE);
}

/*******************************************************************************
* 函数名称: DAC_Init
* 功能描述: Initializes the DAC peripheral according to the specified
*                  parameters in the DAC_InitStruct[依照DAC_InitStruct指定的参数初始化DAC外部设备].
* 输入参数: (1) DAC_Channel: the selected DAC channel[选择DAC通道].
*                    This parameter can be one of the following values[这个参数可以是下面的值之一]:
*                       - DAC_Channel_1: DAC Channel1 selected[选择DAC通道1]
*                       - DAC_Channel_2: DAC Channel2 selected[选择DAC通道2]
*           (2) DAC_InitStruct: pointer to a DAC_InitTypeDef structure that
*                    contains the configuration information for the specified
*                    DAC channel.[指向包含了指定DAC通道配置信息的DAC_InitTypeDef结构指针]
* 输出参数: 无
* 返回参数: 无
*******************************************************************************/
void DAC_Init(u32 DAC_Channel, DAC_InitTypeDef* DAC_InitStruct)
{
  u32 tmpreg1 = 0, tmpreg2 = 0;

  /* Check the DAC parameters [检查DAC参数]*/
  assert_param(IS_DAC_TRIGGER(DAC_InitStruct->DAC_Trigger));
  assert_param(IS_DAC_GENERATE_WAVE(DAC_InitStruct->DAC_WaveGeneration));
  assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(DAC_InitStruct->DAC_LFSRUnmask_TriangleAmplitude));
  assert_param(IS_DAC_OUTPUT_BUFFER_STATE(DAC_InitStruct->DAC_OutputBuffer));

/*---------------------------- DAC CR Configuration --------------------------*/
  /* Get the DAC CR value [获得DAC CR的值]*/
  tmpreg1 = DAC->CR;
  /* Clear BOFFx, TENx, TSELx, WAVEx and MAMPx bits [清BOFFx, TENx, TSELx, WAVEx和MAMPx位]*/
  tmpreg1 &= ~(CR_CLEAR_Mask << DAC_Channel);
  /* Configure for the selected DAC channel: buffer output, trigger, wave generation,
     mask/amplitude for wave generation [配置选择的DAC通道:缓存输出,触发器,波形发生器,波形发生器的时标/振幅]*/
  /* Set TSELx and TENx bits according to DAC_Trigger value [依照DAC_Trigger的值设置TSELx和TENx位]*/
  /* Set WAVEx bits according to DAC_WaveGeneration value [依照DAC_WaveGeneration的值设置WAVEx位]*/
  /* Set MAMPx bits according to DAC_LFSRUnmask_TriangleAmplitude value [依照DAC_LFSRUnmask_TriangleAmplitude的值设置MAMPx位]*/
  /* Set BOFFx bit according to DAC_OutputBuffer value [依照DAC_OutputBuffer的值设置BOFFx位]*/  
  tmpreg2 = (DAC_InitStruct->DAC_Trigger | DAC_InitStruct->DAC_WaveGeneration |
             DAC_InitStruct->DAC_LFSRUnmask_TriangleAmplitude | DAC_InitStruct->DAC_OutputBuffer);
  /* Calculate CR register value depending on DAC_Channel [根据DAC_Channel计算CR寄存器值]*/
  tmpreg1 |= tmpreg2 << DAC_Channel;
  /* Write to DAC CR [写DAC CR]*/
  DAC->CR = tmpreg1;
}

从二十一篇往后都是ST新器件的功能,原来MXCHIP翻译的固件库说明已经没的参考了,全靠我自己了,所以没有把原文替换掉,而是在后面加了括号。

点击此处查看原文 >>

1楼 0 0 回复