////////////////////////////////////////////////////////////////////////////////
// Description : 背光亮度选择
// Input : Bright:亮度选择(0-4095)
// Return : None
////////////////////////////////////////////////////////////////////////////////
void BacklightInit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
DAC_InitTypeDef DAC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
/* Once the DAC channel is enabled, the corresponding GPIO pin is automatically
connected to the DAC converter. In order to avoid parasitic consumption,
the GPIO pin should be configured in analog */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* DAC channel1 Configuration */
DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software;
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_Noise;
DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bits11_0;
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
DAC_Init(DAC_Channel_1, &DAC_InitStructure);
/* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.04 is
automatically connected to the DAC converter. */
DAC_Cmd(DAC_Channel_1, ENABLE);
}
void BacklightOut(unsigned int Bright)
{
/* Set DAC Channel1 DHR12R register */
DAC_SetChannel1Data(DAC_Align_12b_R, Bright & 0x0fff);
DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);
}
DAC_Align_12b_R,DAC_Align_12b_L,DAC_Align_8b_R这几种都试过了,都是不能线性输出(0-3)V输出
下面给几个数据转换得到的电压
0x0000: 0.437V
0x0200: 2.312
0x0400: 2.75
0x0600: 3
0x0800: 3.094
0x0A00: 3.125
0x0C00: 1.594
0x0E00: 0.812
|
|