完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
单片机低功耗的关键就是休眠,休眠的最高境界就是掉电模式
/**************************************************************************//** * @file main.c * @version V3.00 * $Revision: 2 $ * $Date: 16/10/25 4:29p $ * @brief Show how to wake up system from Power-down mode by GPIO interrupt. * @note * Copyright (C) 2016 Nuvoton Technology Corp. All rights reserved. ******************************************************************************/ #include #include "NUC029xGE.h" #define PLLCTL_SETtiNG CLK_PLLCTL_72MHz_HXT #define PLL_CLOCK 72000000 /*---------------------------------------------------------------------------------------------------------*/ /* Function for System Entry to Power Down Mode */ /*---------------------------------------------------------------------------------------------------------*/ void PowerDownFunction(void) { /* Check if all the debug messages are finished */ UART_WAIT_TX_EMPTY(UART0); /* Enter to Power-down mode */ CLK_PowerDown(); } /** * @brief PortA/PortB IRQ * * @param None * * @return None * * @Details The PortA/PortB default IRQ, declared in startup_NUC029xGE.s. */ void GPAB_IRQHandler(void) { /* To check if PB.3 interrupt occurred */ if(GPIO_GET_INT_FLAG(PB, BIT3)) { GPIO_CLR_INT_FLAG(PB, BIT3); printf("PB.3 INT occurred.n"); } else { /* Un-expected interrupt. Just clear all PB interrupts */ PB->INTSRC = PB->INTSRC; printf("Un-expected interrupts.n"); } } void SYS_Init(void) { /*---------------------------------------------------------------------------------------------------------*/ /* Init System Clock */ /*---------------------------------------------------------------------------------------------------------*/ /* Enable HIRC clock (Internal RC 22.1184MHz) */ CLK_EnableXtalRC(CLK_PWRCTL_HIRCEN_Msk); /* Wait for HIRC clock ready */ CLK_WaitClockReady(CLK_STATUS_HIRCSTB_Msk); /* Select HCLK clock source as HIRC and HCLK source divider as 1 */ CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HIRC, CLK_CLKDIV0_HCLK(1)); /* Enable HXT clock (external XTAL 12MHz) */ CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk); /* Wait for HXT clock ready */ CLK_WaitClockReady(CLK_STATUS_HXTSTB_Msk); /* Set core clock as PLL_CLOCK from PLL */ CLK_SetCoreClock(PLL_CLOCK); /* Enable UART module clock */ CLK_EnableModuleClock(UART0_MODULE); /* Select UART module clock source as HXT and UART module clock divider as 1 */ CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UARTSEL_HXT, CLK_CLKDIV0_UART(1)); /*---------------------------------------------------------------------------------------------------------*/ /* Init I/O Multi-function */ /*---------------------------------------------------------------------------------------------------------*/ /* Set multi-function pins for UART0 RXD and TXD */ SYS->GPA_MFPL &= ~(SYS_GPA_MFPL_PA2MFP_Msk | SYS_GPA_MFPL_PA3MFP_Msk); SYS->GPA_MFPL |= (SYS_GPA_MFPL_PA3MFP_UART0_RXD | SYS_GPA_MFPL_PA2MFP_UART0_TXD); } void UART0_Init() { /*---------------------------------------------------------------------------------------------------------*/ /* Init UART */ /*---------------------------------------------------------------------------------------------------------*/ /* Reset UART0 */ SYS_ResetModule(UART0_RST); /* Configure UART0 and set UART0 baud rate */ UART_Open(UART0, 115200); } /*---------------------------------------------------------------------------------------------------------*/ /* MAIN function */ /*---------------------------------------------------------------------------------------------------------*/ int main(void) { /* Unlock protected registers */ SYS_UnlockReg(); /* Init System, peripheral clock and multi-function I/O */ SYS_Init(); /* Lock protected registers */ SYS_LockReg(); /* Init UART0 for printf */ UART0_Init(); printf("nnCPU @ %d Hzn", SystemCoreClock); printf("+-------------------------------------------------------+n"); printf("| GPIO Power-Down and Wake-up by PB.3 Sample Code |n"); printf("+-------------------------------------------------------+nn"); /* Configure PB.3 as Input mode and enable interrupt by rising edge trigger */ GPIO_SetMode(PB, BIT3, GPIO_MODE_INPUT); GPIO_EnableInt(PB, 3, GPIO_INT_RISING); NVIC_EnableIRQ(GPAB_IRQn); /* Enable interrupt de-bounce function and select de-bounce sampling cycle time is 1024 clocks of LIRC clock */ GPIO_SET_DEBOUNCE_TIME(GPIO_DBCTL_DBCLKSRC_LIRC, GPIO_DBCTL_DBCLKSEL_1024); GPIO_ENABLE_DEBOUNCE(PB, BIT3); /* Unlock protected registers before entering Power-down mode */ SYS_UnlockReg(); /* Waiting for PB.3 rising-edge interrupt event */ printf("Enter to Power-Down ......n"); /* Enter to Power-down mode */ PowerDownFunction(); printf("System waken-up done.nn"); while(1); } /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/ |
|
相关推荐
3个回答
|
|
CLK_PowerDown();
掉电模式的关键函数BSP已经提供了,我们看看到底怎么实现的 /** * @brief Enter to Power-down mode * @param None * @return None * @details This function is used to let system enter to Power-down mode. n * The register write-protection function should be disabled before using this function. */ void CLK_PowerDown(void) { /* Set the processor uses deep sleep as its low power mode */ SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; /* Set system Power-down enabled*/ CLK->PWRCTL |= CLK_PWRCTL_PDEN_Msk; /* Chip enter Power-down mode after CPU run WFI instruction */ __WFI(); } |
|
|
|
掉电会触发“低压” or "什么“中断,得有个后备电源(电容,UPS)吧,然后进入”休眠“?
|
|
|
|
所以掉电是休眠的一种
|
|
|
|
只有小组成员才能发言,加入小组>>
3278 浏览 9 评论
2951 浏览 16 评论
3455 浏览 1 评论
8984 浏览 16 评论
4045 浏览 18 评论
1096浏览 3评论
567浏览 2评论
const uint16_t Tab[10]={0}; const uint16_t *p; p = Tab;//报错是怎么回事?
564浏览 2评论
用NUC131单片机UART3作为打印口,但printf没有输出东西是什么原因?
2299浏览 2评论
NUC980DK61YC启动随机性出现Err-DDR是为什么?
1855浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-20 13:28 , Processed in 0.885985 second(s), Total 52, Slave 43 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号