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);
??????? }
??? }
}
?
總結
以上是生活随笔為你收集整理的EFM32片内外设--VCMP 基本操作的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 六一儿童节,悼念天堂的小朋友
- 下一篇: GVRP-LNP-VCMP讲解