• Main Page
  • Related Pages
  • Files
  • File List
  • Globals

buzzer.c

Go to the documentation of this file.
00001 
00012 #define _BUZZER_C_ 1
00013 
00014 #include <avr/io.h>
00015 #include <avr/interrupt.h>
00016 #include <util/delay.h>
00017 
00018 #include "buzzer.h"
00019 
00020 uint16_t buzzer_time=0;
00021 
00022 
00023 void buzzer_init(void) {
00024         
00025         ICR1 = BUZZER_FREQ;
00026         OCR1A = BUZZER_FREQ/2;
00027         OCR1B = BUZZER_FREQ/2;
00028         TCCR1A = (1<<WGM11);
00029         TCCR1B = (1<<CS10) | (1<<WGM13) | (1<<WGM12);
00030         
00031         TIMSK |= (1<<TOIE1);
00032         
00033         DDRB |= (1<<PB1) | (1<<PB2);
00034         
00035 }
00036 
00037 void buzzer_start(uint16_t time) {
00038         
00039         TCCR1A = (1<<COM1A1) | (1<<COM1B1) | (1<<COM1B0) | (1<<WGM11);
00040         buzzer_time=time;
00041         
00042 }
00043 
00044 
00045 void buzzer_stop(void) {
00046         
00047         TCCR1A = (1<<WGM11);
00048         
00049 }
00050 
00051 ISR(TIMER1_OVF_vect) {
00052         if(buzzer_time) {
00053                 
00054                 if(buzzer_time==1) {
00055                         buzzer_stop();
00056                 }
00057                 buzzer_time--;
00058                 
00059         }
00060 }

Generated on Thu Feb 23 2012 13:31:37 for UartDisplay by  doxygen 1.7.2