Пример #1
0
/*********************************************************************************************************
** Function name:           pwrDown
** Descriptions:            pwrDown
*********************************************************************************************************/
void xadow::pwrDown(unsigned long tSleep)
{
#if defined(__AVR_ATmega32U4__)
    power_adc_disable();
    power_usart0_disable();
    power_spi_disable();
    power_twi_disable();
    power_timer1_disable();
    power_timer2_disable();
    power_timer3_disable();
    power_usart1_disable();
    power_usb_disable();
#endif
    sleep.pwrDownMode();        //set sleep mode
    sleep.sleepDelay(tSleep);   //sleep for: sleepTime
}
Пример #2
0
void	Low_Power::idle(Period_t period, ADC_t adc,
                        Timer4_t timer4, Timer3_t timer3,
                        Timer1_t timer1, Timer0_t timer0,
                        SPI_t spi, USART1_t usart1,	TWI_t twi, usb_t usb)
{
    if (adc == ADC_OFF)
    {
        ADCSRA &= ~(1 << ADEN);
        power_adc_disable();
    }

    if (timer4 == TIMER4_OFF)	power_timer4_disable();
    if (timer3 == TIMER3_OFF)	power_timer3_disable();
    if (timer1 == TIMER1_OFF)	power_timer1_disable();
    if (timer0 == TIMER0_OFF)	power_timer0_disable();
    if (spi == SPI_OFF)				power_spi_disable();
    if (usart1 == USART1_OFF)	power_usart1_disable();
    if (twi == TWI_OFF)				power_twi_disable();
    if (usb == USB_OFF)				power_usb_disable();

    if (period != SLEEP_FOREVER)
    {
        wdt_enable(period);
        WDTCSR |= (1 << WDIE);
    }

    lowPowerBodOn(SLEEP_MODE_IDLE);

    if (adc == ADC_OFF)
    {
        power_adc_enable();
        ADCSRA |= (1 << ADEN);
    }

    if (timer4 == TIMER4_OFF)	power_timer4_enable();
    if (timer3 == TIMER3_OFF)	power_timer3_enable();
    if (timer1 == TIMER1_OFF)	power_timer1_enable();
    if (timer0 == TIMER0_OFF)	power_timer0_enable();
    if (spi == SPI_OFF)				power_spi_enable();
    if (usart1 == USART1_OFF)	power_usart1_enable();
    if (twi == TWI_OFF)				power_twi_enable();
    if (usb == USB_OFF)				power_usb_enable();
}
Пример #3
0
int main(void)
{

	unsigned char tmp;
	
	wdt_disable();		/* Disable watchdog if enabled by bootloader/fuses */
	power_usb_disable() ;
	power_usart1_disable();
	power_spi_disable();
	
	Buttons_Init();
	LEDs_Init();
	clock_prescale_set(clock_div_1);	// run at x-tal frequency 16Mhz
	
	
	eeprom_read_block( &EE_data,0,sizeof(EE_data));
		
	if (EE_data.bright_level == 0xff && EE_data.dim_level == 0xff)
	{
		EE_data.bright_level = LED_BRIGHT;
		EE_data.dim_level = LED_DIMM;
		eeprom_write_block(&EE_data,0,sizeof(EE_data));
		eeprom_busy_wait();
	}
	
	OCR0A = EE_data.bright_level;
	OCR0B = EE_data.dim_level;

	// Timer 0 setup for simple count mode, used as timebase LED PWM
	TCCR0A = 0;		// simple count more 		
	TCCR0B = 4;		// system Clock 16Mhz/256 = 16us per counter tick 
	//TCCR0B = 3;		// system Clock 16Mhz/64 = 4us per counter tick 
	//TCCR0B = 5;		// system Clock 16Mhz/1024 = 64us per counter tick 
	//TCCR0B = 2;		// system Clock 1Mhz/8 = 8us per counter tick 
	TIMSK0 = 0x7;	// Enable OverFLow , OCR0A and OCR0B interrupt enables
	
	MCUSR =0; //MCU status register clear 
	
	// Timer 1 setup for  fast PWM mode for servo pulse generation 1 to 2ms 

	TIMSK1 = 0x2;		// Enable OCR1A interrupt 
	TCCR1A = 0x00;		// No pin toggles on compare -- CTC (normal) mode
	TCCR1B = 0x0D;		// CTC mode, F_CPU 16mhz/1024 clock ( 64us)
	//TCCR1B = 0x0B;		// CTC mode, F_CPU 1Mhz/64 clock ( 64us)
	OCR1A = 15625-1;	// counting 15625 counts of 64 us == 1 second

	sei();
		
    while(1)	// for ever
    {
		
		if (IsButtonPressed(BUTTON1) )
		{

			// de-bounce -- 10 consecutive reads of switch open 
			for (tmp =0; tmp<=10; tmp++)
			{
				_delay_ms(2);
				if (IsButtonPressed(BUTTON1))
					tmp = 0;
			}
			
			if ( mode < 3)
				mode++;
			else
			{
				eeprom_write_block(&EE_data,0,sizeof(EE_data));
				eeprom_busy_wait();
				mode = 0; // enter running mode
			}				
		
		}			
				
		if (IsButtonPressed(BUTTON2) ) // increases Minutes and decrease brightness 
		{

			// de-bounce -- 10 consecutive reads of switch open
			for (tmp =0; tmp<=10; tmp++)
			{
				_delay_ms(2);
				if (IsButtonPressed(BUTTON2))
				tmp = 0;
			}
			
			switch (mode) 
			{
				case 1:
					Minutes++;
					ripple();
					break;
					
				case 2:
					if (OCR0B < 0xff )		// dim level
					{
						OCR0B++;
						EE_data.dim_level = OCR0B;
					}						
					break;
					
				case 3:						// bright level
					if (OCR0A < OCR0B-10  )		// make sure that bright is at least 10 counts brighter than dim
					{
						OCR0A +=10;				// step in increments of 10
						EE_data.bright_level =OCR0A;
					}						
					break;
			}			
			
		}	
		
		if (IsButtonPressed(BUTTON3) )	// Increases Hours and increase brightness
		{

			// de-bounce -- 10 consecutive reads of switch open
			for (tmp =0; tmp<=10; tmp++)
			{
				_delay_ms(2);
				if (IsButtonPressed(BUTTON3))
				tmp = 0;
			}
						
			switch (mode)
			{
				case 1:
					Hours++;
					ripple();
					break;
					
				case 2:
					if (OCR0B > OCR0A+10)		// dim level
					{	

						OCR0B--;
						EE_data.dim_level = OCR0B;
					}						
					break;
					
				case 3:						// bright level
					if (OCR0A > 20)	
					{
						OCR0A -=10;		//step in increments of 10
						EE_data.bright_level =OCR0A;
					}						
					break;
			}
		}
				
    } // end of for-ever
}