Skip to content

Commit

Permalink
Work in Progress
Browse files Browse the repository at this point in the history
  • Loading branch information
st3fan committed Dec 28, 2009
1 parent 0784457 commit 6f04ab2
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions tinyhacks-007-sleep/main.c
@@ -1,4 +1,4 @@
// Blink2313 - Blink a LED on PD5 of a ATTiny 2313
// tinyhacks-007-sleep/main.c

#include <avr/io.h>
#include <avr/delay.h>
Expand All @@ -9,34 +9,37 @@ volatile uint8_t count = 0;

ISR(INT0_vect)
{
// Disable the INT0 interrupt to prevent it from firing before we are ready to handle it again
GIMSK &= ~(1 << INT0);
// Increment our interrupt counter
count++;
}

int main(void)
{
// PB0 is connected to a LED
DDRB |= (1 << PB0);
MCUCR &= ~(1 << ISC00);
MCUCR &= ~(1 << ISC01);

// Disable all internal systems during power down mode
PRR = (1 << PRTIM1) | (1 << PRTIM0) | (1 << PRUSI) | (1 << PRADC);

sei();

while (1)
{
// Sleep
GIMSK |= (1 << INT0); // This needs to be before the sleep instruction

// Sleep in power down mode. Before we sleep we enable the INT0 interrupt.

set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
GIMSK |= (1 << INT0);
sleep_cpu();

// If we have been woken up 4 times then it is time to do 'work'

if (count == 4)
if (count >= 4)
{
// Flash the led three times

for (uint8_t i = 0; i < 3; i++) {
PORTB |= (1 << PB0);
_delay_ms(50);
Expand All @@ -45,7 +48,6 @@ int main(void)
}

// Reset the counter

count = 0;
}

Expand Down

0 comments on commit 6f04ab2

Please sign in to comment.