58 lines
1.7 KiB
C
58 lines
1.7 KiB
C
/********************************************************/
|
||
// CPU需要:STM32F103--RAM内存不小于64K Flash内存不小于128K
|
||
// 本代码已在STM32F103RDT、VET6测试通过
|
||
// 编辑日期:20150909
|
||
// editor by 小小晟
|
||
// 网店:shop182385147.taobao.com
|
||
/********************************************************/
|
||
|
||
#include "stm32f10x.h"
|
||
#include "stm32f10x_dac.h"
|
||
#include "stm32f10x_dma.h"
|
||
#include "PLC_CONF.H"
|
||
|
||
|
||
void DAC_out_init(void)
|
||
{
|
||
DAC_InitTypeDef DAC_InitStructure;
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
|
||
/* GPIOA Periph clock enable */
|
||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
|
||
/* DAC Periph clock enable */
|
||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
|
||
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
|
||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||
|
||
// DAC_InitStructure.DAC_Trigger = DAC_Trigger_None;
|
||
DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software;
|
||
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
|
||
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
|
||
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);
|
||
DAC_SoftwareTriggerCmd(DAC_Channel_1,ENABLE);
|
||
DAC_SoftwareTriggerCmd(DAC_Channel_2,ENABLE);
|
||
|
||
DAC_SetChannel1Data(DAC_Align_12b_R,0);
|
||
DAC_SetChannel2Data(DAC_Align_12b_R,0);
|
||
|
||
DAC_SoftwareTriggerCmd(DAC_Channel_1,ENABLE);
|
||
DAC_SoftwareTriggerCmd(DAC_Channel_2,ENABLE);
|
||
|
||
}
|
||
|
||
void DAC_data(void)
|
||
{
|
||
DAC_SetChannel1Data(DAC_Align_12b_R,D8080);
|
||
DAC_SetChannel2Data(DAC_Align_12b_R,D8081);
|
||
|
||
DAC_SoftwareTriggerCmd(DAC_Channel_1,ENABLE);
|
||
DAC_SoftwareTriggerCmd(DAC_Channel_2,ENABLE);
|
||
}
|
||
|
||
|