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);
}
}
}