【iCore1S 双核心板_ARM】例程九:DAC实验——输出直流电压

实验原理:

  STM32内部集成12位DAC,可以配置成12位或8位,DAC具有两个独立转换通道,

在双DAC模式下,DA转换可被配置成独立模式或工作模式,iCore1S中DAC参考电压为

2.5V。本实验输出2.0V电压

核心代码:

int main(void)
{

  /* USER CODE BEGIN 1 */
  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DAC_Init();

  /* USER CODE BEGIN 2 */
    HAL_DAC_Start(&hdac, DAC_CHANNEL_1); 

    dac.set_voltage(2.0);                                 

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
        
        LED_RED_ON;                                                
        LED_GREEN_OFF;
        LED_BLUE_OFF;
        HAL_Delay(1000);
        LED_RED_OFF;
        LED_GREEN_ON;
        LED_BLUE_OFF;
        HAL_Delay(1000);
        LED_RED_OFF;
        LED_GREEN_OFF;
        LED_BLUE_ON;
        HAL_Delay(1000);
    }
  /* USER CODE END 3 */

}

源代码下载链接:

链接:http://pan.baidu.com/s/1i5b0kRV 密码:p2h5

posted @ 2017-08-18 08:52  XiaomaGee  阅读(376)  评论(0编辑  收藏  举报