#include "stm32f10x.h"
#include "Includes.h"
#include "Constants.h"
#include "Functions.h"
#include "Globals.h"
/*************************************************************
@Fn: ConfigCPU()
@Br: Config the MCU
@Pa: None
@Rt: None
*************************************************************/
void ConfigCPU( void ){
...
/* Enable DAC clocks */
RCC_APB1PeriphClockCmd( RCC_APB1Periph_DAC, ENABLE );
...
}
#include "stm32f10x.h"
#include "Includes.h"
#include "Constants.h"
#include "Functions.h"
#include "Globals.h"
const uint SIN_TABLE[36] = {
2047, 2403, 2747, 3071, 3363, 3616,
3821, 3971, 4064, 4094, 4064, 3971,
3821, 3616, 3363, 3071, 2747, 2403,
2047, 1691, 1347, 1023, 731, 478,
273, 123, 30, 0, 30, 123,
273, 478, 731, 1023, 1347, 1691
};
/*************************************************************
@Fn: ConfigDAC()
@Br: 配置PA4端口上的DAC1输出为无中断模式应用
@Pa: 无
@Rt: 无
*************************************************************/
void ConfigDAC( void ){
DAC_InitTypeDef DAC_InitStruct;
DAC_StructInit( &DAC_InitStruct );
DAC_InitStruct.DAC_Trigger = DAC_Trigger_Software;
/* 软件触发 */
DAC_InitStruct.DAC_WaveGeneration = DAC_WaveGeneration_Noise;
/* 波形产生模式,非三角波幅度模式 */
DAC_InitStruct.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bit0;
/* 波形产生模式时,线性反馈移位寄存器等于1 */
DAC_InitStruct.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
/* 使能缓冲器 */
DAC_Init( DAC_Channel_1, &DAC_InitStruct );
DAC_Cmd( DAC_Channel_1, ENABLE );
DAC_SetChannel1Data( DAC_Align_12b_R, 0 );
DAC_SoftwareTriggerCmd( DAC_Channel_1, ENABLE );
}
/************************************************************
@Fn: GeneratingSinWave()
@Br: 产生60Hz正弦波
@Pa: 无
@Rt: 无
@Specification: 定时器4定时后软件触发
************************************************************/
void GeneratingSinWave( void ){
ucIndexCntDAC++;
if( ucIndexCntDAC >= 36 )ucIndexCntDAC = 0;
DAC_SetChannel1Data( DAC_Align_12b_R, SIN_TABLE[ ucIndexCntDAC ] );
DAC_SoftwareTriggerCmd( DAC_Channel_1, ENABLE );
} |