53 #define BUZZER_SHORTBEEP_DURATION 100
54 #define BUZZER_LONGBEEP_DURATION 1000
61 counter_t Buzzer_Counter = 0;
64 const u8* CurrentMelody = 0;
65 const u8* CurrentMelodySTART = 0;
66 u8 DefaultOctave = OCT_880;
67 u8 DefaultDuration = 4;
68 u16 DefaultBeats = 63;
70 CONST_DATA u16 Note_Freq[16] =
109 void BUZZER_PlayNote(
void )
111 u8 duration = DefaultDuration;
115 while ( *CurrentMelody ==
' ' )
121 if ( ( *CurrentMelody >
'0' ) && ( *CurrentMelody <
'9' ) )
123 duration = *CurrentMelody++ -
'0';
125 if ( ( *CurrentMelody >
'0' ) && ( *CurrentMelody <
'9' ) )
128 duration += ( *CurrentMelody++ -
'0' );
135 Buzzer_Counter = 35000 / DefaultBeats * 10 / duration;
138 Buzzer_Counter = ( ( 32 / duration ) * 256L * 32L ) / DefaultBeats;
139 Buzzer_Counter *= ( SYSTEM_CLOCK / 12000L );
140 Buzzer_Counter /= 1000L;
144 c = *CurrentMelody++;
146 if ( ( c >=
'a' ) && ( c <=
'z' ) )
155 else if ( ( c >=
'A' ) && ( c <=
'G' ) )
157 note = ( c -
'A' ) + NOTE_LA;
159 if ( *CurrentMelody ==
'#' )
166 octave = DefaultOctave;
169 if ( ( c >=
'5' ) && ( c <=
'8' ) )
171 octave = OCT_440 + ( c -
'5' );
175 BUZZER_SetFrequency( ( Note_Freq[note] * ( 1 << octave ) ) );
178 if ( *CurrentMelody ==
'.' )
181 Buzzer_Counter += ( Buzzer_Counter / 2 );
186 while ( ( c = *CurrentMelody++ ) != 0 )
216 void BUZZER_Handler(
void )
218 switch ( Buzzer_Mode )
221 if ( Buzzer_Counter <= 0 )
234 if ( Buzzer_Counter++ >= WEIGHTED_TIME( BUZZER_SHORTBEEP_DURATION ) )
241 if ( Buzzer_Counter++ >= WEIGHTED_TIME( BUZZER_LONGBEEP_DURATION ) )
346 DefaultOctave = OCT_880;
349 CurrentMelody = melody;
350 CurrentMelodySTART = melody;
352 while ( *CurrentMelody != RTTTL_SEP )
354 if ( *CurrentMelody == 0 )
364 for ( ++CurrentMelody; *CurrentMelody != RTTTL_SEP; CurrentMelody++ )
366 if ( *CurrentMelody == 0 )
372 while ( *CurrentMelody ==
' ' )
379 if ( c == RTTTL_SEP )
384 if ( ( c >=
'a' ) && ( c <=
'z' ) )
389 if ( ( c >=
'A' ) && ( c <=
'Z' ) )
395 if ( ( c >=
'0' ) && ( c <=
'9' ) )
398 default_val += ( c -
'0' );
399 c = * ( CurrentMelody + 1 );
401 if ( ( c >=
'0' ) && ( c <=
'9' ) )
406 if ( default_id ==
'D' )
408 DefaultDuration = default_val;
410 else if ( default_id ==
'O' )
412 DefaultOctave = default_val - 5;
414 if ( DefaultOctave > OCT_7040 )
415 DefaultOctave = OCT_440;
417 else if ( default_id ==
'B' )
419 DefaultBeats = default_val;
422 if ( ( DefaultBeats < 16 ) || ( DefaultBeats > 500 ) )