Here is a demo program for the successfully tested Nuvoton M051 MCU interrupt wakeup (sleep):
Reference address:Nuvoton M051 interrupt wake-up (sleep) demonstration program
#include "SmartM_M0.h"
#define __KEYISR EINT1_IRQHandler
#define DEBUGMSG printf
/******************************************
*Function name:KeyIntInit
* Input: None
*Output: None
*Function: key interrupt initialization
******************************************/
VOID KeyIntInit(VOID)
{
P3_MFP = (P3_MFP & (~P33_EINT1_MCLK)) | EINT1; //P3.2 pin is set as external interrupt
DBNCECON &= ~ICLK_ON;
DBNCECON &= DBCLK_HCLK;
DBNCECON |= SMP_256CK; //Set the anti-rebound sampling cycle selection
P3_DBEN |= DBEN3; //Enable P3.2 anti-rebound function
P3_IMD &= IMD3_EDG;
P3_IEN |= IF_EN3; //Set external interrupt 1 to falling edge trigger
NVIC_ISER |= EXT_INT1;
}
/******************************************
*Function name:McuSleepDeep
* Input: None
*Output: None
*Function: MCU enters sleep mode
******************************************/
VOID McuSleepDeep(VOID)
{
Delayms(20);
PROTECT_REG
(
/* Enter sleep mode */
SCR |= SLEEPDEEP;
/* Disable interrupt enable for wake-up in power-down mode*/
PWRCON &= ~PD_WU_IE;
PWRCON &= ~PD_WAIT_CPU;
PWRCON |= PWR_DOWN_EN;
)
Delayms(20);
}
/******************************************
*Function name: main
* Input: None
*Output: None
*Function: Function body
******************************************/
INT32 main(VOID)
{
PROTECT_REG //Protect FLASH memory during ISP download
(
PWRCON |= XTL12M_EN; //The default clock source is external crystal oscillator
while((CLKSTATUS & XTL12M_STB) == 0); //Wait for 12MHz clock to stabilize
CLKSEL0 = (CLKSEL0 & (~HCLK)) | HCLK_12M; //Set the external crystal oscillator as the system clock
P2_PMD = 0x5555;
)
KeyIntInit(); //Key interrupt initialization
while(1)
{
P2_DOUT = 0x00;
Delayms(500);
P2_DOUT = 0xFF;
Delayms(500);
McuSleepDeep(); //MCU enters sleep mode
}
}
/******************************************
*Function name:__KEYISR
* Input: None
*Output: None
*Function: key interrupt service function
******************************************/
VOID __KEYISR(VOID)
{
Delayms(100);
P3_ISRC = P3_ISRC; //Write 1 to clear
}
Previous article:Nuvoton M051 Timer 3 Cycle Mode Test Program
Next article:Nuvoton M051 ISP (LDROM, FMC, equivalent to 8-bit EEPROM operation) program
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
MoreDaily News
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
Guess you like
- National Technology: N32G45x_Library.1.3.0_for_gcc and documentation for using the GCC development environment under Windows
- MOSFET turn-on schedule question
- Introduction to DA14585 Bluetooth chip and its application range
- [2022 Digi-Key Innovation Design Competition] Material Unboxing - STM32F7508 Development Board + BLDC Brushless Motor Driver Board
- What are some good ways to protect the algorithm programs in the equipment in the industrial control industry?
- VMM Image Measurement Software
- msp430F149 PWM adjustment
- Album information compilation: Power supply simulation, those who need it, please enter!
- Detection circuit
- A scientist who continues to live as a cyborg