小学生
最后登录1970-1-1
在线时间 小时
注册时间2013-12-18
|
#include "dac.h"
#include "stm32f10x.h"
void DAC_CH_CONFIG()
{
GPIO_InitTypeDef GPIO_InitStructure;
DAC_InitTypeDef DAC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE );
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE );
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AIN;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software ; //软件触发
//以下两句的作用为关闭DAC端口的输出三角波形功能以及关闭其输出波形的电压幅值
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude=DAC_LFSRUnmask_Bit0;
//关闭缓存,DAC端口不接负载时可不用缓存
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
DAC_Init( DAC_Channel_1, &DAC_InitStructure ); //初始化
DAC_Cmd(DAC_Channel_1, ENABLE); //使能DAC1 通
DAC_SetChannel1Data(DAC_Align_12b_R, 0x0000); //写入初始值0
DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE); ///软件触发转换
}
void DAC_SET()
{
DAC_SetChannel1Data(DAC_Align_12b_R,1000);
DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);
}
main 函数:
int main(void)
{
DAC_CH_CONFIG();
DAC_SET();
while(1)
{
}
}
改变DAC_SetChannel1Data(DAC_Align_12b_R,1000); 中的参数值,PA4口输出 不变,用万用表测量的电压始终为3.26V, 按理说参数设置为1000时,端口输出电压应该为0.79V 啊 !
CPU :STM32F103VET6 野火的板子 火哥及各位大侠 ,帮忙看下啊,谢谢!
|
|