PUYA PY32L020_Firmware V1.2.1 COMP COMP_CompareGpioVs1_2VCC_IT 示例教学
COMP — COMP_CompareGpioVs1_2VCC_IT
固件库: PY32L020_Firmware V1.2.1
芯片: PUYA
源文件: PUYA/PY32L020_Firmware_V1.2.1/Projects/PY32L020-STK/Example/COMP/COMP_CompareGpioVs1_2VCC_IT/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
30
31
32
33
|
#include "main.h"
int main(void)
{
/* Reset of all peripherals, Initializes the Systick. */
HAL_Init();
/* Initialize LED */
BSP_LED_Init(LED_GREEN);
hcomp2.Instance = COMP2; /* COMP2 */
hcomp2.Init.InputMinus = COMP_INPUT_MINUS_IO1; /* Minus Input PA4 */
hcomp2.Init.InputPlus = COMP_INPUT_PLUS_IO2; /* Plus Input VrefCmp */
hcomp2.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED; /* Output None Inverted */
hcomp2.Init.WindowMode = COMP_WINDOWMODE_DISABLE; /* Window mode Disable */
hcomp2.Init.VrefSrc = COMP_VREFCMP_SOURCE_VCC; /* VrefCmp Select VCC */
hcomp2.Init.VrefDiv = COMP_VREFCMP_DIV_8_16VREFCMP; /* Vrefbuf 8/16 */
hcomp2.Init.DigitalFilter = 0x0; /* Filter Disable */
hcomp2.Init.TriggerMode = COMP_TRIGGERMODE_IT_RISING_FALLING; /* Trigger on Rising/Falling */
/* Initialize COMP */
if (HAL_COMP_Init(&hcomp2) != HAL_OK)
{
APP_ErrorHandler();
}
/* COMP Start */
HAL_COMP_Start(&hcomp2);
while (1)
{
}
}
|
代码讲解
板级初始化:初始化开发板上的 LED、按键等基础外设。