示例#1
0
int main(void) {
	initSleep();
	*((int*)GPREG0)=0;
	while(1){
		/*
		blink_led();
		runFib(3);
		runFib(3);
		blink_led();
		blink_led();
		*/
		runFib(48);
		runFib(24);
		runFib(12);
		runFib(3);
		//fibonacci(30);
		EnterDeepSleep();
		//test_int++;
		(*(int*)GPREG0)++;
		int wakeTemp=*((int*)GPREG0);
		//int wakeTemp = test_int+1;

		for(i=0;i<wakeTemp;i++){
			blink_led();
		}
	}
}
示例#2
0
int main(void)
{
    LPC_SYSCON->PDRUNCFG      = BF_PDRUNCFG_RUN; // Initialize power to chip modules
    LPC_SYSCON->SYSAHBCLKCTRL = BF_SYSAHBCLKCTRL_RUN; // Initialize clocks

    InitGPIOForSleep(); // Set all GPIO as outputs driving low

    InitDeepSleep();

    while(1)
    {
        Wait1mS(PROCDURATION_MS); // Active mode: Do some work
        //while(1);
#ifdef FLASH_LED
        SetBitsPort0(1<<7);  // Turn on LED on LPCXpresso board
#else
        SetBitsPort0(1<<6);
#endif

        Wait1mS(LEDDURATION_MS); // Active mode: Do some work
        // Current consumption is about the same (20% or so) no
        // matter what code is running. Sleep mode can be entered
        // in idle times to lower it dramatically.

#ifdef FLASH_LED
        ClrBitsPort0(1<<7);  // Turn off LED on LPCXpresso board
#else
        ClrBitsPort0(1<<6);
#endif

        EnterDeepSleep();
    }

    while(1);
}
示例#3
0
文件: main.c 项目: dacan84/u-mote
void main(void) {
    // Enable UART for serial output display
    Open1USART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_EIGHT_BIT & USART_ASYNCH_MODE & USART_ADDEN_OFF, BAUDRG);

#ifdef INVERT_UART
    baud1USART(BAUD_IDLE_TX_PIN_STATE_LOW & BAUD_IDLE_RX_PIN_STATE_LOW & BAUD_AUTO_OFF & BAUD_WAKEUP_OFF & BAUD_16_BIT_RATE & USART_RX_INT_ON);
#else
    baud1USART(BAUD_IDLE_TX_PIN_STATE_HIGH & BAUD_IDLE_RX_PIN_STATE_HIGH & BAUD_AUTO_OFF & BAUD_WAKEUP_OFF & BAUD_16_BIT_RATE & USART_RX_INT_ON);
#endif

    // I/O states will be held until DSCONL.RELEASE = 0, but we must still initialize
    // to what we want before clearing the RELEASE bit.
    InitializeIO();

#ifdef USE_32KHZ_CRYSTAL
    // Enable the Secondary Oscillator for RTCC use.
    OpenTimer1(TIMER_INT_OFF & T1_SOURCE_PINOSC & T1_PS_1_1 & T1_OSC1EN_ON & T1_SYNC_EXT_OFF, 0);
#endif

    // Did we wake up from Deep Sleep? Or is this the first initial power on?
    if (WDTCONbits.DS) {
        // woke up from Deep Sleep
        DSCONLbits.RELEASE = 0; // release control and data bits for all I/Os

        wait(); // allow time for INTOSC to stablize before using UART
        printf("Woke from Deep Sleep via ");
        if (DSWAKEHbits.DSINT0 != 0) {
            printf("RB0/INT0\r\n");
        } else if (DSWAKELbits.DSMCLR != 0) {
            printf("MCLR\r\n");
        } else if (DSWAKELbits.DSFLT != 0) {
            printf("DSFLT\n");
        } else if (DSWAKELbits.DSWDT != 0) {
            printf("DSWDT\n");
        } else if (DSWAKELbits.DSRTC != 0) {
            printf("RTCC Alarm\n");
        }
    } else {
        // first initial power up of the device.
        // unlock the RTCC registers so that we can write to them
        EECON2 = 0x55;
        EECON2 = 0xAA;
        RTCCFGbits.RTCWREN = 1;

        // reset RTCC date/time (only on first power on)
        RTCCFGbits.RTCPTR1 = 1;
        RTCCFGbits.RTCPTR0 = 1;
        RTCVALL = 0x09; // reserved | year
        RTCVALH = 0xFF;

        RTCVALL = 0x01; // month | day
        RTCVALH = 0x01;

        RTCVALL = 0x12; // weekday | hours
        RTCVALH = 0x01;

        RTCVALL = 0x00; // minutes | seconds
        RTCVALH = 0x00;

        RTCCFGbits.RTCEN = 1; // enable RTCC module
        RTCCAL = RTCCALIBRATION;

        wait(); // allow time for INTOSC to stablize before using UART
    }

    // Application Tasks
    DoApplicationTasks();

    // Power down into Deep Sleep mode.
    printf("Powering down into deep sleep, push RB0/INT0 down to wake...\r\n");
    Flush1USART();
    Close1USART();
    RB0ReleasedWait(); // wait for user to release INT0 so we don't get spurious wake up

EnterDeepSleepMode:
    EnableINT0();
    EnterDeepSleep();

    // Execution should normally never reach here, as Deep Sleep powers up
    // at the Reset Vector.
    //
    // However, there exists a small possibility an INT0 wake up is triggered
    // before the processor has fully enter Deep Sleep mode. As a result, gaurd
    // code is required here to handle re-initiating Deep Sleep entry.
    goto EnterDeepSleepMode;
}
示例#4
0
int main (void)
{
    if((*rom)->pPWRD == (void *)0xFFFFFFFF)
    {
    	// This LPC does not have the power API
    	while(1);
    }

    LPC_GPIO0->DIR |= (1<<7); //set led direction
    LPC_GPIO0->MASKED_ACCESS[(1<<7)] = (0<<7);	//turn off the LED

    LPC_SYSCON->SYSAHBCLKCTRL = (0xFFFFFFFF & (~(1<<15))); //enable all clocks except the WDT

    /* user must select correct PLL input source before calling power/pll routines */
    LPC_SYSCON->PDRUNCFG &= ~(1<<5);            //power-up the system oscillator
    for (i = 0; i != 24000; i++);               //wait for it to stabilize
    LPC_SYSCON->SYSPLLCLKSEL = 0x01;            //system PLL source is the system oscillator
    LPC_SYSCON->SYSPLLCLKUEN = 0x00;            //update the system PLL source...
    LPC_SYSCON->SYSPLLCLKUEN = 0x01;            //...
    LPC_SYSCON->MAINCLKSEL = 0x01;              //main clock source is the PLL input
    LPC_SYSCON->MAINCLKUEN = 0x00;              //update the main clock source...
    LPC_SYSCON->MAINCLKUEN = 0x01;              //...

    LPC_SYSCON->CLKOUTCLKSEL = 0x03;            //CLKOUT = main clock
    LPC_SYSCON->CLKOUTUEN = 0x01;               //update CLKOUT selection...
    LPC_SYSCON->CLKOUTUEN = 0x00;               //...
    LPC_SYSCON->CLKOUTUEN = 0x01;               //...
    LPC_SYSCON->CLKOUTDIV = 10;                 //generate ouptut @ 1/10 rate

    LPC_IOCON->PIO0_1 &= ~0x07;                 //select CLKOUT @ PIO0_1...
    LPC_IOCON->PIO0_1 |= 1;                     //...

	//configure CT16B1_MAT0 as a system/10 clock out (P0_21)
//	LPC_IOCON->PIO0_21 = (LPC_IOCON->PIO0_21 & ~0x7) | 1;	//select CT16B1_MAT0 @ P0_21
    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<8);           	//enable CT16B1 clock
	LPC_TMR16B1->TCR	= 0x00;						//stop the timer
	LPC_TMR16B1->TCR	= 0x02;						//reset the timer
	LPC_TMR16B1->TCR	= 0x00;						//release the reset
	LPC_TMR16B1->CTCR	= 0x00;						//count on peripheral clock rising edges only
  	LPC_TMR16B1->PR		= 0;						//max rate (no prescaler)
	LPC_TMR16B1->MR0 	= 10/2-1;					//match output = 1/10 timer's clock
  	LPC_TMR16B1->MCR	= 1<<1;						//reset on MR0
  	LPC_TMR16B1->EMR	= 3<<4;						//toggle MAT0
	LPC_TMR16B1->TCR	= 0x01;						//let the timer run

    /* user must select the correct operating frequency before setting up the PLL   */
    /* or the voltage regulator and the flash interface setup might not be able     */
    /* to support application running at higher frequencies                         */
    command[0] = 48;                            //system freq 48 MHz
//    command[1] = PARAM_DEFAULT;                 //specify system power to default
//    command[1] = PARAM_CPU_EXEC;                //specify system power for cpu performance run
//    command[1] = PARAM_EFFICIENCY;              //specify system power for efficiency
    command[1] = PARAM_LOW_CURRENT;             //specify system power for low active current
    (*rom)->pPWRD->set_power(command,result);   //set system power
    if (result[0] != PARAM_CMD_CUCCESS){        //if a failure is reported...
        while(1);                               //... stay in the loop
    }

    /* the pll setup routine is searching for a setup based on the specified input  */
    /* and output frequency and after setting up the main PLL switches main clock   */
    /* source from PLL in to PLL out                                                */
    command[0] = 12000;                         //PLL's input freq 12000
    command[1] = 48000;                         //CPU's freq 48000
    command[2] = CPU_FREQ_EQU;                  //specify exact frequency
    command[3] = 0;                             //infinitely wait for the PLL to lock
    (*rom)->pPWRD->set_pll(command,result);     //set the PLL
    if ((result[0] != PLL_CMD_CUCCESS)){        //if a failure is reported...
        while(1);                               //... stay in the loop
    }

    /* before changing the PLL setup main clock source must be switched from        */
    /* PLL in to PLL out!!!                                                         */
    while(1){
        //48 MHz setup begin
        LPC_SYSCON->MAINCLKSEL = 0x01;              //main clock source is the PLL input
        LPC_SYSCON->MAINCLKUEN = 0x00;              //update the main clock source...
        LPC_SYSCON->MAINCLKUEN = 0x01;              //...
        for (i = 0; i != 10000; i++);               //wait for a while
        command[0] = 48;                            //system freq 48 MHz
        command[1] = PARAM_LOW_CURRENT;             //specify system power for low active current
        (*rom)->pPWRD->set_power(command,result);   //set system power
        if (result[0] != PARAM_CMD_CUCCESS){        //if a failure is reported...
            while(1);                               //... stay in the loop
        }
        command[0] = 12000;                         //PLL's input freq 12000
        command[1] = 48000;                         //CPU's freq 48000
        command[2] = CPU_FREQ_EQU;                  //specify exact frequency
        command[3] = 0;                             //infinitely wait for the PLL to lock
        (*rom)->pPWRD->set_pll(command,result);     //set the PLL
        if ((result[0] != PLL_CMD_CUCCESS)){        //if a failure is reported...
            while(1);                               //... stay in the loop
        }
        for (i = 0; i != 10000; i++);
        //48 MHz setup end
        fibonacci(30);
        LPC_GPIO0->MASKED_ACCESS[(1<<7)]=(1<<7);
        Wait1mS(100);
    	LPC_GPIO0->MASKED_ACCESS[(1<<7)]=(0<<7);

        //24 MHz setup begin
        LPC_SYSCON->MAINCLKSEL = 0x01;              //main clock source is the PLL input
        LPC_SYSCON->MAINCLKUEN = 0x00;              //update the main clock source...
        LPC_SYSCON->MAINCLKUEN = 0x01;              //...
        for (i = 0; i != 10000; i++);               //wait for a while
        command[0] = 24;                            //system freq 24 MHz
        command[1] = PARAM_LOW_CURRENT;             //specify system power for low active current
        (*rom)->pPWRD->set_power(command,result);   //set system power
        if (result[0] != PARAM_CMD_CUCCESS){        //if a failure is reported...
            while(1);                               //... stay in the loop
        }
        command[0] = 12000;                         //PLL's input freq 12000
        command[1] = 24000;                         //CPU's freq 24000
        command[2] = CPU_FREQ_EQU;                  //specify exact frequency
        command[3] = 0;                             //infinitely wait for the PLL to lock
        (*rom)->pPWRD->set_pll(command,result);     //set the PLL
        if ((result[0] != PLL_CMD_CUCCESS)){        //if a failure is reported...
            while(1);                               //... stay in the loop
        }
        for (i = 0; i != 5000; i++);
        //24 MHz setup end
        fibonacci(30);
        LPC_GPIO0->MASKED_ACCESS[(1<<7)]=(1<<7);
        Wait1mS(100);
    	LPC_GPIO0->MASKED_ACCESS[(1<<7)]=(0<<7);
        //18 MHz setup begin
        LPC_SYSCON->MAINCLKSEL = 0x01;              //main clock source is the PLL input
        LPC_SYSCON->MAINCLKUEN = 0x00;              //update the main clock source...
        LPC_SYSCON->MAINCLKUEN = 0x01;              //...
        for (i = 0; i != 10000; i++);               //wait for a while
        command[0] = 18;                            //system freq 18 MHz
        command[1] = PARAM_LOW_CURRENT;             //specify system power for low active current
        (*rom)->pPWRD->set_power(command,result);   //set system power
        if (result[0] != PARAM_CMD_CUCCESS){        //if a failure is reported...
            while(1);                               //... stay in the loop
        }
        command[0] = 12000;                         //PLL's input freq 12000
        command[1] = 18000;                         //CPU's freq 18000
        command[2] = CPU_FREQ_EQU;                  //specify exact frequency
        command[3] = 0;                             //infinitely wait for the PLL to lock
        (*rom)->pPWRD->set_pll(command,result);     //set the PLL
        if ((result[0] != PLL_CMD_CUCCESS)){        //if a failure is reported...
            while(1);                               //... stay in the loop
        }
        for (i = 0; i != 3750; i++);
        //18 MHz setup end
        fibonacci(30);
        LPC_GPIO0->MASKED_ACCESS[(1<<7)]=(1<<7);
        Wait1mS(100);
    	LPC_GPIO0->MASKED_ACCESS[(1<<7)]=(0<<7);
        //3 MHz setup begin
        LPC_SYSCON->MAINCLKSEL = 0x01;              //main clock source is the PLL input
        LPC_SYSCON->MAINCLKUEN = 0x00;              //update the main clock source...
        LPC_SYSCON->MAINCLKUEN = 0x01;              //...
        for (i = 0; i != 10000; i++);               //wait for a while
        command[0] = 3;                             //system freq 3 MHz
        command[1] = PARAM_LOW_CURRENT;             //specify system power for low active current
        (*rom)->pPWRD->set_power(command,result);   //set system power
        if (result[0] != PARAM_CMD_CUCCESS){        //if a failure is reported...
            while(1);                               //... stay in the loop
        }
        command[0] = 12000;                         //PLL's input freq 12000
        command[1] = 3000;                          //CPU's freq 3000
        command[2] = CPU_FREQ_EQU;                  //specify exact frequency
        command[3] = 0;                             //infinitely wait for the PLL to lock
        (*rom)->pPWRD->set_pll(command,result);     //set the PLL
        if ((result[0] != PLL_CMD_CUCCESS)){        //if a failure is reported...
            while(1);                               //... stay in the loop
        }
        for (i = 0; i != 625; i++);
        //3 MHz setup end
        fibonacci(30);
        LPC_GPIO0->MASKED_ACCESS[(1<<7)]=(1<<7);
        Wait1mS(100);
    	LPC_GPIO0->MASKED_ACCESS[(1<<7)]=(0<<7);

        InitGPIOForSleep(); // Set all GPIO as outputs driving low

        InitDeepSleep();
        EnterDeepSleep();
    }
}