PUYA COMP — COMP_CompareGpioVsVrefint_HYST

PUYA PY32F0xx_Firmware V1.5.0 COMP COMP_CompareGpioVsVrefint_HYST 示例教学

COMP — COMP_CompareGpioVsVrefint_HYST

固件库: PY32F0xx_Firmware V1.5.0
芯片: PUYA
源文件: PUYA/PY32F0xx_Firmware_V1.5.0/Projects/PY32F030-STK/Example/COMP/COMP_CompareGpioVsVrefint_HYST/Src/main.c


功能简介

本示例演示 COMP 的基本用法。

完整代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "main.h"

int main(void)
{
  /* Reset of all peripherals, Initializes the Systick */
  HAL_Init();                                                         

  hcomp.Instance = COMP2;                                              /* Select COMP2 */
  hcomp.Init.InputMinus      = COMP_INPUT_MINUS_VREFINT;               /* Negative input is VREF (1.2V) */
  hcomp.Init.InputPlus       = COMP_INPUT_PLUS_IO3;                    /* Positive input is PA3 */
  hcomp.Init.OutputPol       = COMP_OUTPUTPOL_NONINVERTED;             /* COMP2 polarity is non-inverted */
  hcomp.Init.Mode            = COMP_POWERMODE_HIGHSPEED;               /* COMP2 power mode is set to High speed */
  hcomp.Init.Hysteresis      = COMP_HYSTERESIS_ENABLE;                 /* Hysteresis function is enabled */
  hcomp.Init.WindowMode      = COMP_WINDOWMODE_DISABLE;                /* Window mode is disabled */
  hcomp.Init.TriggerMode     = COMP_TRIGGERMODE_NONE;                  /* External trigger for COMP2 is disabled */
  hcomp.Init.DigitalFilter   = 0;

  /* Initialize COMP2 */
  if (HAL_COMP_Init(&hcomp) != HAL_OK)                                 
  {
    APP_ErrorHandler();
  }
  /* Start COMP2 */
  HAL_COMP_Start(&hcomp);                                              

  while (1)
  {
  }
}

代码讲解

板级初始化:初始化开发板上的 LED、按键等基础外设。

世界是你们
使用 Hugo 构建
主题 StackJimmy 设计