From bedbcdc4de680720deff4b6e113a3ec1a0690482 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Tue, 22 Jul 2014 15:58:55 +0200 Subject: Speaker and LED pwm Something is not correct here, stack overflow? --- speaker.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'speaker.c') diff --git a/speaker.c b/speaker.c index 2eace8d..92c1e78 100644 --- a/speaker.c +++ b/speaker.c @@ -1,49 +1,45 @@ /* speaker control, uses timer2 */ +#include "common.h" + #include #include +#include #include +#include +#include #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); } -- cgit v1.2.3