//源文件 void DACPhyConfig() { RCC->APB1ENR |= 1<<29; //使能 DAC 时钟 RCC->AHB1ENR |= 1<<0; //使能 PORTA 时钟 //PA4 输入模式、下拉、高速 GPIOA->MODER |= (3<<4*2); //输入模式 GPIOA->PUPDR |= (3<<4*2); //下拉 GPIOA->OSPEEDR |= (1<<4*2); //高速 DAC->CR |= 1<<0; //使能 DAC1 DAC->CR |= 1<<1; //DAC1 输出缓存不使能 BOFF1=1 DAC->CR |= 0<<2; //不使用触发功能 TEN1=0 DAC->CR |= 0<<3; //DAC TIM6 TRGO,不过要 TEN1=1 才行 DAC->CR |= 0<<6; //不使用波形发生 DAC->CR |= 0<<8; //屏蔽、幅值设置 DAC->CR |= 0<<12; //DAC1 DMA 不使能 DAC->DHR12R1 = 0; //默认输出 0 } //设置通道 1 输出电压 //vol:0~3300,代表 0~3.3V void Dac1_Set_Vol(uint16_t vol) { double temp = vol; temp /= 1000; temp = temp*4096/3.3; DAC->DHR12R1 = temp; } //头文件 /*****************************dac**************************************/ void DACPhyConfig(void); void Dac1_Set_Vol(uint16_t vol); /**********************************************************************/
标签:1CR,temp,dac,vol,void,0CR,nulceo144,STM32F6xx From: https://www.cnblogs.com/lum0126/p/16883426.html