xiaoxiaocheng_plc/users/DAC.C

58 lines
1.7 KiB
C++
Raw Permalink Normal View History

2018-11-13 22:25:34 +08:00
/********************************************************/
// CPU<50><55>Ҫ<EFBFBD><D2AA>STM32F103--RAM<41>ڴ治С<E6B2BB><D0A1>64K Flash<73>ڴ治С<E6B2BB><D0A1>128K
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>STM32F103RDT<44><54>VET6<54><36><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8>
// <20><EFBFBD><E0BCAD><EFBFBD>ڣ<EFBFBD>20150909
// editor by СС<D0A1><D0A1>
// <20><><EFBFBD>꣺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);
}