#include "LPC11xx.h" /* LPC11xx definitions */ #include "stdio.h" #include "string.h" #include "uart.h" #include "sysTime.h" #define DPDEN (1<<1) #define DPDFLAG (1<<11) #define IS_WAKE_FROM_DDOWN ( ( LPC_PMU->PCON & DPDFLAG ) == DPDFLAG ) void deep_power_down(){ printf("ENTERING POWER DOWN MODE!\n"); printf("BYE\n"); // Specify DPDEN to power control register LPC_PMU->PCON = DPDEN; // Specify Deep Power-down mode before entering mode SCB->SCR |= (1<<2); // Enable IRC before deep power-down mode LPC_SYSCON->PDRUNCFG &= ~( (1<<0) | (1<<1) ); // Enter deep power-down mode __WFI(); return; } int main(void) { int tick; SystemInit(); UARTInit(19200); // Initialize serial port if ( IS_WAKE_FROM_DDOWN ){ LPC_PMU->PCON |= DPDFLAG; printf("Starting from deep down...\n"); } else { printf("Starting normal...\n"); } tick = 0; while(1) { tick++; if ( tick > 3 ){ tick = 0; deep_power_down(); } delay_ms(1000); printf("Tick:%u\n",tick); } } |