diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2014-07-22 15:58:55 +0200 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2014-07-22 15:59:09 +0200 |
commit | bedbcdc4de680720deff4b6e113a3ec1a0690482 (patch) | |
tree | 448003d0a8d8a356c956baa427bc3c35f620d314 /speaker.c | |
parent | 42e32ed74655e98e9f2d5a0152a047dcf9e72806 (diff) | |
download | hourglass-bedbcdc4de680720deff4b6e113a3ec1a0690482.tar.gz hourglass-bedbcdc4de680720deff4b6e113a3ec1a0690482.tar.bz2 hourglass-bedbcdc4de680720deff4b6e113a3ec1a0690482.zip |
Speaker and LED pwm
Something is not correct here, stack overflow?
Diffstat (limited to 'speaker.c')
-rw-r--r-- | speaker.c | 32 |
1 files changed, 14 insertions, 18 deletions
@@ -1,49 +1,45 @@ /* speaker control, uses timer2 */ +#include "common.h" + #include <avr/io.h> #include <avr/interrupt.h> +#include <util/delay.h> #include <stdbool.h> +#include <assert.h> +#include <stdlib.h> #include "speaker.h" -static bool value = false; - -static void speakerSet () { - if (value) { - PORTD = PORTD | (1 << PD6); - } else { - PORTD = PORTD & ~(1 << PD6); - } -} - ISR(TIMER2_OVF_vect) { - value = !value; - speakerSet (); + PORTD ^= (1 << PD6); } void speakerInit () { /* set PD6 to output */ DDRD |= (1 << PD6); - /* value is false */ - speakerSet (); + /* turn off */ + PORTD = PORTD & ~(1 << PD6); } -void speakerStart () { +void speakerStart (const speakerMode mode) { /* reset timer value */ TCNT2 = 0; - /* set normal mode timer0 */ + /* set normal mode */ TCCR2A = 0; /* enable overflow interrupt */ TIMSK2 = (1 << TOIE2); /* io clock with 1024 prescaler */ TCCR2B = ((TCCR2B & ~(1 << CS21)) | (1 << CS22) | (1 << CS20)); + _delay_ms (50); + speakerStop (); } void speakerStop () { /* zero clock source */ TCCR2B = 0; - value = false; - speakerSet (); + /* turn off */ + PORTD = PORTD & ~(1 << PD6); } |