#include <avr/io.h> // deal with port registers
#include <util/delay.h> // used for _delay_us function
#include <stdlib.h>
#include <stdio.h>
#include <avr/interrupt.h>
#include <avr/sleep.h> //Needed for sleep_mode
#include <avr/power.h> //Needed for powering down perihperals such as the ADC/TWI and Timers
#include <avr/wdt.h>
#define F_CPU 8000000
#define LED PC0 // Indikacni LED - blika, kdyz bezi odpocet
void msDelay(int delay) // put into a routine
{ // to remove code inlining
for (int i=0;i<delay;i++) // at cost of timing accuracy
_delay_ms(1);
}
void FlashLed(void)
{
PORTC &= ~(_BV(LED)); //ON
msDelay(50);
PORTC |= _BV(LED); //OFF
}
void Timer2Init(void)
{
TCCR2B= (1<<CS22)|(1<<CS21)|(1<<CS20);
TCNT2=0x00;
OCR2B=0x00;
ASSR = (1<<AS2); //Enable asynchronous operation
TIMSK2 = (1<<TOIE2); //Enable the timer 2 interrupt
}
ISR(TIMER2_OVF_vect)
{
// sleep_disable();
asm volatile("nop");
// FlashLed();
}
int main(void)
{
DDRC |= _BV(LED); //LED pin is output
Timer2Init();
while(1)
{
msDelay(100);
set_sleep_mode (SLEEP_MODE_PWR_DOWN);
// set_sleep_mode (SLEEP_MODE_STANDBY);
cli();
sleep_enable();
sei();
sleep_cpu();
sleep_disable();
sei();
FlashLed();
}
}