移植与电子模块通信相关代码
This commit is contained in:
69
source/elec_det/hardware/dac_cfg.c
Normal file
69
source/elec_det/hardware/dac_cfg.c
Normal file
@@ -0,0 +1,69 @@
|
||||
#include "dac_cfg.h"
|
||||
#include "gpio_cfg.h"
|
||||
/*
|
||||
@brief 默认初始化
|
||||
*/
|
||||
void DAC_Definit(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
DAC_InitTypeDef DAC_InitStructure;
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = C_H_DAC_Pin|C_M_DAC_Pin;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||
|
||||
|
||||
DAC_DeInit();
|
||||
DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software;
|
||||
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
|
||||
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
|
||||
|
||||
|
||||
DAC_Init(DAC_Channel_1, &DAC_InitStructure);
|
||||
|
||||
|
||||
DAC_Init(DAC_Channel_2, &DAC_InitStructure);
|
||||
|
||||
DAC_Cmd(DAC_Channel_1, ENABLE);
|
||||
|
||||
DAC_Cmd(DAC_Channel_2, ENABLE);
|
||||
|
||||
|
||||
|
||||
C_H_DAC_Set(4000);
|
||||
/* configure the DAC1 */
|
||||
C_M_DAC_Set(4000);
|
||||
}
|
||||
/*
|
||||
@brief 设置高电平电压
|
||||
@param dac_val DAC0输出值 0-4096
|
||||
*/
|
||||
void C_H_DAC_Set(uint16_t dac_val)
|
||||
{
|
||||
DAC_SetChannel1Data(DAC_Align_12b_R, dac_val);
|
||||
DAC_SoftwareTriggerCmd(DAC_Channel_1,ENABLE);
|
||||
// dac_output_buffer_enable(DAC0);
|
||||
// dac_data_set(DAC0,DAC_ALIGN_12B_R,dac_val);
|
||||
// dac_trigger_enable(DAC0);
|
||||
// dac_enable(DAC0);
|
||||
// dac_software_trigger_enable(DAC0);
|
||||
}
|
||||
/*
|
||||
@brief 设置高电平电压
|
||||
@param dac_val DAC1输出值 0-4096
|
||||
*/
|
||||
void C_M_DAC_Set(uint16_t dac_val)
|
||||
{
|
||||
DAC_SetChannel2Data(DAC_Align_12b_R, dac_val);
|
||||
DAC_SoftwareTriggerCmd(DAC_Channel_2,ENABLE);
|
||||
// dac_output_buffer_enable(DAC1);
|
||||
// dac_data_set(DAC1,DAC_ALIGN_12B_R,dac_val);
|
||||
// dac_trigger_enable(DAC1);
|
||||
// dac_enable(DAC1);
|
||||
// dac_software_trigger_enable(DAC1);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user