EFM32片内外设--VCMP 基本操作

VCMP基本操作例程,是从Application Note中抠出来的。

#include "stdio.h"
#include "efm32.h"
#include "em_cmu.h"
#include "em_vcmp.h"
#include "em_gpio.h"

unsigned char VCMP_Voltage_Get_Level(void)
{
    CMU_ClockEnable(cmuClock_CORELE, true);
    /* Initialize VCMP */
    CMU_ClockEnable(cmuClock_VCMP, true);
   
    /* Declare VCMP Init struct */
    VCMP_Init_TypeDef vcmp =
    {
        false,                              /* Half bias current */
        7,                                  /* Bias current configuration */
        false,                              /* Enable interrupt for falling edge */
        false,                              /* Enable interrupt for rising edge */
        vcmpWarmTime256Cycles,              /* Warm-up time in clock cycles */
        vcmpHystNone,                       /* Hysteresis configuration */
        0,                                  /* Inactive comparator output value */
        false,                              /* Enable low power mode */
        VCMP_VoltageToLevel(3.2),           /* Trigger level */
        true                                /* Enable VCMP after configuration */
    };
   
    /* Initialize VCMP */
    VCMP_Init(&vcmp);

    /* Wait for VCMP warm-up */
    while (!VCMP_Ready()) ;
   
    unsigned char ucFlag = 0;
    /* if VDD > trigger level ==> return ture, else return false*/
    ucFlag = VCMP_VDDHigher();
   
    /*Close VCMP*/
    VCMP_Disable();
   
    return (ucFlag);
}

void main(void)
{
    CMU_ClockEnable(cmuClock_GPIO, true);
   
    GPIO_PinModeSet(gpioPortD, 7, gpioModePushPull, 0);
   
    while(1)
    {
        if(VCMP_Voltage_Get_Level())
        {
            GPIO_PinOutSet(gpioPortD, 7);
        }
        else
        {
            GPIO_PinOutClear(gpioPortD, 7);
        }
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值