Revision 276
cleaned up library - dos2unix and delete-trailing-whitespace
buzzer.c | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (c) 2007 Colony Project |
3 |
*
|
|
3 |
* |
|
4 | 4 |
* Permission is hereby granted, free of charge, to any person |
5 | 5 |
* obtaining a copy of this software and associated documentation |
6 | 6 |
* files (the "Software"), to deal in the Software without |
... | ... | |
9 | 9 |
* copies of the Software, and to permit persons to whom the |
10 | 10 |
* Software is furnished to do so, subject to the following |
11 | 11 |
* conditions: |
12 |
*
|
|
12 |
* |
|
13 | 13 |
* The above copyright notice and this permission notice shall be |
14 | 14 |
* included in all copies or substantial portions of the Software. |
15 |
*
|
|
15 |
* |
|
16 | 16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
17 | 17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
18 | 18 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
... | ... | |
70 | 70 |
* @see buzzer_init, buzzer_set_freq, buzzer_off |
71 | 71 |
**/ |
72 | 72 |
void buzzer_set_val(unsigned int buzz_value) |
73 |
{
|
|
73 |
{ |
|
74 | 74 |
TCCR2 = _BV(COM20) | _BV(WGM21) | _BV(CS22); |
75 | 75 |
DDRB |= _BV(DDB7); |
76 | 76 |
OCR2 = buzz_value; |
... | ... | |
89 | 89 |
void buzzer_set_freq(unsigned int buzz_freq) |
90 | 90 |
{ |
91 | 91 |
int buzz_value; |
92 |
|
|
92 |
|
|
93 | 93 |
buzz_value = 62500/buzz_freq - 1; |
94 | 94 |
|
95 | 95 |
if(buzz_value > 255){ |
... | ... | |
97 | 97 |
}else if(buzz_value < 0){ |
98 | 98 |
buzz_value = 0; |
99 | 99 |
} |
100 |
|
|
100 |
|
|
101 | 101 |
buzzer_set_val(buzz_value); |
102 | 102 |
} |
103 | 103 |
|
... | ... | |
112 | 112 |
* |
113 | 113 |
* @see buzzer_init, buzzer_set_freq |
114 | 114 |
**/ |
115 |
void buzzer_chirp(unsigned int ms, unsigned int buzz_freq)
|
|
116 |
{
|
|
115 |
void buzzer_chirp(unsigned int ms, unsigned int buzz_freq) |
|
116 |
{ |
|
117 | 117 |
buzzer_set_freq(buzz_freq); |
118 | 118 |
delay_ms(ms); |
119 | 119 |
buzzer_off(); |
... | ... | |
128 | 128 |
{ |
129 | 129 |
// Disable clock, to halt counter |
130 | 130 |
TCCR2 &= 0xF8;//0b11111000; |
131 |
|
|
131 |
|
|
132 | 132 |
// Set buzzer pin low in case it's high |
133 | 133 |
PORTB &= 0xBF;//0b10111111; |
134 | 134 |
} |
Also available in: Unified diff