diff options
| author | Yuval Adam <yuv.adm@gmail.com> | 2014-09-29 23:50:08 +0300 |
|---|---|---|
| committer | Yuval Adam <yuv.adm@gmail.com> | 2014-09-29 23:50:08 +0300 |
| commit | 74b45e98fb536b6e69979fde2af191fa9c024e6c (patch) | |
| tree | 0dd1d62be004426fcb1e55f3534f6e1736132f42 /hello.c | |
| parent | 11d6bd49b0606fc23e04076e040e5971229ffbb7 (diff) | |
Diffstat (limited to 'hello.c')
| -rw-r--r-- | hello.c | 73 |
1 files changed, 53 insertions, 20 deletions
@@ -1,35 +1,68 @@ +#include <avr/eeprom.h> #include <avr/io.h> #include <util/delay.h> -int -main (void) -{ +uint8_t state; + + +int main() { + state = eeprom_read_byte((uint8_t*)0) & 1; + if ((MCUSR & (1 << PORF)) != 0) { + MCUSR = 1; + state ^= 1; + eeprom_write_byte((uint8_t*)0, state); + } + DDRB |= _BV(DDB0); DDRB |= _BV(DDB1); DDRB |= _BV(DDB2); DDRB |= _BV(DDB3); DDRB |= _BV(DDB4); - while(1) { - PORTB ^= _BV(PB0); - _delay_ms(500); - PORTB ^= _BV(PB0); - PORTB ^= _BV(PB1); - _delay_ms(500); - PORTB ^= _BV(PB1); + while (1) { + if (state == 1) { + PORTB ^= _BV(PB4); + _delay_ms(500); + PORTB ^= _BV(PB4); + + PORTB ^= _BV(PB3); + _delay_ms(500); + PORTB ^= _BV(PB3); + + PORTB ^= _BV(PB2); + _delay_ms(500); + PORTB ^= _BV(PB2); + + PORTB ^= _BV(PB1); + _delay_ms(500); + PORTB ^= _BV(PB1); + + PORTB ^= _BV(PB0); + _delay_ms(500); + PORTB ^= _BV(PB0); + } + else { + PORTB ^= _BV(PB0); + _delay_ms(500); + PORTB ^= _BV(PB0); + + PORTB ^= _BV(PB1); + _delay_ms(500); + PORTB ^= _BV(PB1); - PORTB ^= _BV(PB2); - _delay_ms(500); - PORTB ^= _BV(PB2); + PORTB ^= _BV(PB2); + _delay_ms(500); + PORTB ^= _BV(PB2); - PORTB ^= _BV(PB3); - _delay_ms(500); - PORTB ^= _BV(PB3); + PORTB ^= _BV(PB3); + _delay_ms(500); + PORTB ^= _BV(PB3); - PORTB ^= _BV(PB4); - _delay_ms(500); - PORTB ^= _BV(PB4); - } + PORTB ^= _BV(PB4); + _delay_ms(500); + PORTB ^= _BV(PB4); + } + } } |
