diff options
author | Keith Packard <keithp@keithp.com> | 2011-05-11 19:50:57 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2011-05-11 19:50:57 -0700 |
commit | c519966530f980340f0362076b62d063d2387448 (patch) | |
tree | e490d2e42c59c4526655d5b661e6d332f286f305 | |
parent | cb0192d389d6c76b8653ee6b7552f6c5ddc74c95 (diff) |
ao-bringup-avr: Initialize crystal clock and 100Hz timer interrupt
Just demonstrating further features of the chip
Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r-- | ao-bringup-avr/ao-blink.c | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/ao-bringup-avr/ao-blink.c b/ao-bringup-avr/ao-blink.c index 4d726fd9..fa958315 100644 --- a/ao-bringup-avr/ao-blink.c +++ b/ao-bringup-avr/ao-blink.c @@ -25,7 +25,35 @@ #define LEDDDR DDRB #define LEDDDRPIN DD7 -int main(void) +ISR(TIMER1_COMPA_vect) +{ + static int x; + + if (++x > 50) { + x = 0; + LEDPORT ^= (1 << LEDOUT); + } +} + +static void +timer_init(void) +{ + TCCR1A = ((0 << WGM11) | /* CTC mode, OCR1A */ + (0 << WGM10)); /* CTC mode, OCR1A */ + TCCR1B = ((0 << ICNC1) | /* no input capture noise canceler */ + (0 << ICES1) | /* input capture on falling edge (don't care) */ + (0 << WGM13) | /* CTC mode, OCR1A */ + (1 << WGM12) | /* CTC mode, OCR1A */ + (3 << CS10)); /* clk/64 from prescaler */ + + OCR1A = 2500; /* 16MHz clock */ + // OCR1A = 1250; /* 8MHz clock */ + + TIMSK1 = (1 << OCIE1A); /* Interrupt on compare match */ +} + +static void +clock_init(void) { /* disable RC clock */ CLKSEL0 &= ~(1 << RCE); @@ -65,13 +93,23 @@ int main(void) PLLCSR |= (1 << PLLE); while (!(PLLCSR & (1 << PLOCK))) ; +} + +int main(void) +{ + clock_init(); + timer_init(); LEDDDR |= (1 << LEDDDRPIN); + for (;;) { + } +#if 0 while (1) { LEDPORT |= (1 << LEDOUT); _delay_ms(1000); LEDPORT &= ~(1 << LEDOUT); _delay_ms(1000); } +#endif } |