完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
/******************************************************************************
* @file main.c * @version V3.00 * $Revision: 2 $ * $Date: 15/05/22 2:58p $ * @brief Show how to wake up MCU from Power-down mode by ACMP wake-up function. * * @note * Copyright (C) 2014 Nuvoton Technology Corp. All rights reserved. *****************************************************************************/ #include #include "M051Series.h" /* Function prototype declaration */ void SYS_Init(void); void PowerDownFunction(void); int IsDebugFifoEmpty(void); int32_t main(void) { uint32_t u32DelayCount; /* Unlock protected registers */ SYS_UnlockReg(); /* Init System, IP clock and multi-function I/O. */ SYS_Init(); /* Lock protected registers */ SYS_LockReg(); /* Configure UART0: 115200, 8-bit word, no parity bit, 1 stop bit. */ UART_Open(UART0, 115200); printf("\n\n"); printf("+---------------------------------------+\n"); printf("| M051 ACMP Sample Code |\n"); printf("+---------------------------------------+\n"); printf("\nThis sample code demonstrates ACMP0 wake-up function. Using ACMP0_P (P1.5) as ACMP0\n"); printf("positive input and using internal band-gap voltage as the negative input.\n"); printf("The compare result reflects on ACMP0_O (P3.6).\n"); printf("When the voltage of the positive input is greater than the voltage of the negative input,\n"); printf("the analog comparator outputs logical one; otherwise, it outputs logical zero.\n"); printf("This chip will be waked up from power down mode when detecting a transition of analog comparator's output.\n"); printf("Press any key to enter power down mode ..."); getchar(); printf("\n"); /* Configure ACMP0. Enable ACMP0 and select internal reference voltage as negative input. */ ACMP_Open(ACMP01, 0, ACMP_CR_VNEG_BANDGAP, ACMP_CR_HYSTERESIS_DISABLE); __NOP(); for(u32DelayCount = 0; u32DelayCount < 100; u32DelayCount++); /* For ACMP setup time */ __NOP(); /* Clear ACMP 0 interrupt flag */ ACMP_CLR_INT_FLAG(ACMP01, 0); /* Enable ACMP0 interrupt function */ ACMP_ENABLE_INT(ACMP01, 0); /* Enable ACMP01 interrupt */ NVIC_EnableIRQ(ACMP01_IRQn); /* To program PWRCTL register, it needs to disable register protection first. */ SYS_UnlockReg(); PowerDownFunction(); printf("Wake up by ACMP0!\n"); while(1); } void ACMP01_IRQHandler(void) { printf("\nACMP0 interrupt!\n"); /* Disable interrupt */ ACMP_DISABLE_INT(ACMP01, 0); /* Clear ACMP 0 interrupt flag */ ACMP_CLR_INT_FLAG(ACMP01, 0); } void SYS_Init(void) { /*---------------------------------------------------------------------------------------------------------*/ /* Init System Clock */ /*---------------------------------------------------------------------------------------------------------*/ /* Enable external 12MHz XTAL */ CLK_EnableXtalRC(CLK_PWRCON_XTL12M_EN_Msk); /* Waiting for clock ready */ CLK_WaitClockReady(CLK_CLKSTATUS_XTL12M_STB_Msk); /* Select HXT as the clock source of UART */ CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_HXT, CLK_CLKDIV_UART(1)); /* Enable UART peripheral clock */ CLK_EnableModuleClock(UART0_MODULE); /* Enable ACMP01 peripheral clock */ CLK_EnableModuleClock(ACMP01_MODULE); /* Update System Core Clock */ /* User can use SystemCoreClockUpdate() to calculate SystemCoreClock and CyclesPerUs automatically. */ SystemCoreClockUpdate(); /*---------------------------------------------------------------------------------------------------------*/ /* Init I/O Multi-function */ /*---------------------------------------------------------------------------------------------------------*/ /* Set P1.5 multi-function pin for ACMP0 positive input pin */ SYS->P1_MFP = SYS_MFP_P15_ACMP0_P; /* Disable digital input path of analog pin ACMP0_P to prevent leakage */ GPIO_DISABLE_DIGITAL_PATH(P1, BIT5); /* Set P3 multi-function pins for UART0 RXD, TXD and ACMP0 output */ SYS->P3_MFP = SYS_MFP_P30_RXD0 | SYS_MFP_P31_TXD0 | SYS_MFP_P36_ACMP0_O; } void PowerDownFunction(void) { printf("\nSystem enter power-down mode ... "); /* To check if all the debug messages are finished */ while(IsDebugFifoEmpty() == 0); /* Deep sleep mode is selected */ SCB->SCR = SCB_SCR_SLEEPDEEP_Msk; /* To program PWRCTL register, it needs to disable register protection first. */ CLK->PWRCON &= ~(CLK_PWRCON_PD_WAIT_CPU_Msk | CLK_PWRCON_PWR_DOWN_EN_Msk); CLK->PWRCON |= (CLK_PWRCON_PD_WAIT_CPU_Msk | CLK_PWRCON_PWR_DOWN_EN_Msk | CLK_PWRCON_PD_WU_INT_EN_Msk); __WFI(); } /*** (C) COPYRIGHT 2014 Nuvoton Technology Corp. ***/ |
|
相关推荐
1个回答
|
|
可以,该示例代码演示了如何使用ACMP唤醒M051芯片从掉电模式。在该示例中,ACMP输入通道选择为ADC_CH6,引脚选择为P1.5,唤醒模式选择为电平唤醒,即当ACMP输出电平为高时唤醒M051芯片。唤醒后,程序会进入main函数并通过LED进行闪烁。
|
|
|
|
只有小组成员才能发言,加入小组>>
695 浏览 0 评论
1106 浏览 1 评论
2473 浏览 5 评论
2808 浏览 9 评论
移植了freeRTOS到STMf103之后显示没有定义的原因?
2646 浏览 6 评论
使用eim外接fpga可是端口一点反应都没有有没有大哥指点一下啊
653浏览 9评论
649浏览 7评论
请教大神怎样去解决iMX6Q在linux3.0.35内核上做AP失败的问题呢
781浏览 6评论
628浏览 5评论
668浏览 5评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 12:09 , Processed in 1.142248 second(s), Total 81, Slave 61 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号