⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stm32f10x_dac.c

📁 stm32f10xx的中文译文例程
💻 C
📖 第 1 页 / 共 2 页
字号:
* 输入参数  (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) NewState: new state of the selected DAC channel software trigger[选择的DAC通道软件触发新状态].
*                    This parameter can be: ENABLE or DISABLE.[这个参数可以是:ENABLE or DISABLE]
* 输出参数: 无
* 返回参数: 无
*******************************************************************************/
void DAC_SoftwareTriggerCmd(u32 DAC_Channel, FunctionalState NewState)
{
  /* Check the parameters [检查参数]*/
  assert_param(IS_DAC_CHANNEL(DAC_Channel));
  assert_param(IS_FUNCTIONAL_STATE(NewState));

  if (NewState != DISABLE)
  {
    /* Enable software trigger for the selected DAC channel [使能选择的DAC通道软件触发]*/
    DAC->SWTRIGR |= SWTRIGR_SWTRIG_Set << (DAC_Channel >> 4);
  }
  else
  {
    /* Disable software trigger for the selected DAC channel [禁止选择的DAC通道软件触发]*/
    DAC->SWTRIGR &= ~(SWTRIGR_SWTRIG_Set << (DAC_Channel >> 4));
  }
}

/*******************************************************************************
* 函数名称: DAC_DualSoftwareTriggerCmd
* 功能描述: Enables or disables simultaneously the two DAC channels software
*                  triggers[使能或禁止两个DAC通道同步软件触发].
* 输入参数  - NewState: new state of the DAC channels software triggers[DAC通道软件触发新状态].
*                    This parameter can be: ENABLE or DISABLE.[这个参数可以是:ENABLE or DISABLE]
* 输出参数: 无
* 返回参数: 无
*******************************************************************************/
void DAC_DualSoftwareTriggerCmd(FunctionalState NewState)
{
  /* Check the parameters [检查参数]*/
  assert_param(IS_FUNCTIONAL_STATE(NewState));

  if (NewState != DISABLE)
  {
    /* Enable software trigger for both DAC channels [使能软件触发两个DAC通道]*/
    DAC->SWTRIGR |= DUAL_SWTRIG_Set ;
  }
  else
  {
    /* Disable software trigger for both DAC channels [禁止软件触发两个DAC通道]*/
    DAC->SWTRIGR &= DUAL_SWTRIG_Reset;
  }
}

/*******************************************************************************
* 函数名称: DAC_WaveGenerationCmd
* 功能描述: Enables or disables the selected DAC channel wave generation[使能或禁止选择的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_Wave: Specifies the wave type to enable or disable[指定的波形类型].
*                    This parameter can be one of the following values[这个参数可以选择下面的值之一]:
*                       - DAC_Wave_Noise: noise wave generation[噪音波形发生]
*                       - DAC_Wave_Triangle: triangle wave generation[三角波形发生]
*                  - NewState: new state of the selected DAC channel wave generation[DAC通道波形发生新状态].
*                    This parameter can be: ENABLE or DISABLE.[这个参数可以是:ENABLE or DISABLE]
* 输出参数: 无
* 返回参数: 无
*******************************************************************************/
void DAC_WaveGenerationCmd(u32 DAC_Channel, u32 DAC_Wave, FunctionalState NewState)
{
  /* Check the parameters [检查参数]*/
  assert_param(IS_DAC_CHANNEL(DAC_Channel));
  assert_param(IS_DAC_WAVE(DAC_Wave)); 
  assert_param(IS_FUNCTIONAL_STATE(NewState));

  if (NewState != DISABLE)
  {
    /* Enable the selected wave generation for the selected DAC channel [使能选择的DAC通道选择的波形]*/
    DAC->CR |= DAC_Wave << DAC_Channel;
  }
  else
  {
    /* Disable the selected wave generation for the selected DAC channel [禁止选择的DAC通道选择的波形]*/
    DAC->CR &= ~(DAC_Wave << DAC_Channel);
  }
}

/*******************************************************************************
* 函数名称: DAC_SetChannel1Data
* 功能描述: Set the specified data holding register value for DAC channel1[设置DAC通道1指定的数据保持寄存器值].
* 输入参数: (1) DAC_Align: Specifies the data alignment for DAC channel1[DAC通道1指定的数据对齐].
*                    This parameter can be one of the following values[这个参数可以选择下面的值之一]:
*                       - DAC_Align_8b_R: 8bit right data alignement selected[选择8位数据右对齐]
*                       - DAC_Align_12b_L: 12bit left data alignement selected[选择12位数据左对齐]
*                       - DAC_Align_12b_R: 12bit right data alignement selected[选择12位数据右对齐]
*           (2) Data : Data to be loaded in the selected data holding 
*                    register[装入选择的数据保持寄存器的数据].
* 输出参数: 无
* 返回参数: 无
*******************************************************************************/
void DAC_SetChannel1Data(u32 DAC_Align, u16 Data)
{
  /* Check the parameters [检查参数]*/
  assert_param(IS_DAC_ALIGN(DAC_Align));
  assert_param(IS_DAC_DATA(Data));

  /* Set the DAC channel1 selected data holding register [设置DAC通道1选择的数据保持寄存器]*/
  *((vu32 *)(DAC_BASE + DHR12R1_Offset + DAC_Align)) = (u32)Data;
}

/*******************************************************************************
* 函数名称: DAC_SetChannel2Data
* 功能描述: Set the specified data holding register value for DAC channel2[设置DAC通道2指定的数据保持寄存器值].
* 输入参数: (1) DAC_Align: Specifies the data alignement for DAC channel2[DAC通道2指定的数据对齐].
*                    This parameter can be one of the following values:[这个参数可以选择下面的值之一]
*                       - DAC_Align_8b_R: 8bit right data alignement selected[选择8位数据右对齐]
*                       - DAC_Align_12b_L: 12bit left data alignement selected[选择12位数据左对齐]
*                       - DAC_Align_12b_R: 12bit right data alignement selected[选择12位数据右对齐]
*           (2) Data : Data to be loaded in the selected data holding 
*                    register.[装入选择的数据保持寄存器的数据]
* 输出参数: 无
* 返回参数: 无
*******************************************************************************/
void DAC_SetChannel2Data(u32 DAC_Align, u16 Data)
{
  /* Check the parameters [检查参数]*/
  assert_param(IS_DAC_ALIGN(DAC_Align));
  assert_param(IS_DAC_DATA(Data));

  /* Set the DAC channel2 selected data holding register [设置DAC通道2选择的数据保持寄存器]*/
  *((vu32 *)(DAC_BASE + DHR12R2_Offset + DAC_Align)) = (u32)Data;
}

/*******************************************************************************
* 函数名称: DAC_SetDualChannelData
* 功能描述: Set the specified data holding register value for dual channel
*                  DAC[为双通道DAC设置指定的数据保持寄存器值].
* 输入参数: (1) DAC_Align: Specifies the data alignment for dual channel DAC[为双通道DAC指定数据对齐].
*                    This parameter can be one of the following values:[这个参数可以选择下面的值之一]
*                       - DAC_Align_8b_R: 8bit right data alignement selected[选择8位数据右对齐]
*                       - DAC_Align_12b_L: 12bit left data alignement selected[选择12位数据左对齐]
*                       - DAC_Align_12b_R: 12bit right data alignement selected[选择12位数据右对齐]
*           (2) Data2: Data for DAC Channel2 to be loaded in the selected data 
*                    holding register[为DAC通道2装载到选择的数据保持寄存器的数据].
*           (3) Data1: Data for DAC Channel1 to be loaded in the selected data 
*                    holding register[为DAC通道1装载到选择的数据保持寄存器的数据].
* 输出参数: 无
* 返回参数: 无
*******************************************************************************/
void DAC_SetDualChannelData(u32 DAC_Align, u16 Data2, u16 Data1)
{
  u32 data = 0;

  /* Check the parameters [检查参数]*/
  assert_param(IS_DAC_ALIGN(DAC_Align));
  assert_param(IS_DAC_DATA(Data1));
  assert_param(IS_DAC_DATA(Data2));
  
  /* Calculate and set dual DAC data holding register value [计算并设置双DAC数据保持寄存器的值]*/
  if (DAC_Align == DAC_Align_8b_R)
  {
    data = ((u32)Data2 << 8) | Data1; 
  }
  else
  {
    data = ((u32)Data2 << 16) | Data1;
  }

  /* Set the dual DAC selected data holding register [设置双DAC选择的数据保持寄存器]*/
  *((vu32 *)(DAC_BASE + DHR12RD_Offset + DAC_Align)) = data;
}

/*******************************************************************************
* 函数名称: DAC_GetDataOutputValue
* 功能描述: Returns the last data output value of the selected DAC cahnnel[返回最新的DAC通道数据寄存器输出值].
* 输入参数  - 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]
* 输出参数: 无
* 返回参数: The selected DAC channel data output value[选择的DAC通道数据输出值].
*******************************************************************************/
u16 DAC_GetDataOutputValue(u32 DAC_Channel)
{
  /* Check the parameters [检查参数]*/
  assert_param(IS_DAC_CHANNEL(DAC_Channel));

  /* Returns the DAC channel data output register value [返回DAC通道数据寄存器输出值]*/
  return (u16) (*(vu32*)(DAC_BASE + DOR_Offset + ((u32)DAC_Channel >> 2)));
}

/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -