设定:1ms 0-16
输出:
16 3.000V
15 2.813V
14 2.625V
13 2.438V
12 2.250V
11 2.063V
10 1.875V
9 1.688V
8 1.500V
7 1.313V
6 1.125V
5 0.938V
4 0.750V
3 0.563V
2 0.375V
1 0.188V
0 0
#include "stm32f10x.h"
void DAC_Configuration(void);
uint16_t Step_No;
uint16_t Vvalue[17];
int main(void)
{
Vvalue[0] = 0x0000;
Vvalue[1] = 0x00FF;
Vvalue[2] = 0x01FF;
Vvalue[3] = 0x02FF;
Vvalue[4] = 0x03FF;
Vvalue[5] = 0x04FF;
Vvalue[6] = 0x05FF;
Vvalue[7] = 0x06FF;
Vvalue[8] = 0x07FF;
Vvalue[9] = 0x08FF;
Vvalue[10] = 0x09FF;
Vvalue[11] = 0x0AFF;
Vvalue[12] = 0x0BFF;
Vvalue[13] = 0x0CFF;
Vvalue[14] = 0x0DFF;
Vvalue[15] = 0x0EFF;
Vvalue[16] = 0x0FFF;
Step_No = 0;
SysTick_Config(SystemCoreClock / 1000); //1ms
DAC_Configuration();
while(1);
}
void DAC_Configuration(void) {
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
DAC_InitTypeDef DAC_InitStructure;
DAC_InitStructure.DAC_Trigger = DAC_Trigger_None;
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
DAC_Init(DAC_Channel_1, &DAC_InitStructure);
DAC_Cmd(DAC_Channel_1, ENABLE);
}
void SysTick_Handler(void){
DAC_SetChannel1Data(DAC_Align_12b_R, Vvalue[Step_No]);
Step_No++;
if(Step_No == 17) Step_No = 0;
}
文章评论(0条评论)
登录后参与讨论