forked from igkov/bcomp11
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeep.c
54 lines (47 loc) · 912 Bytes
/
beep.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "timer.h"
#include "event.h"
#include "beep.h"
#include "notes.h"
#if defined( NO_SOUND )
#define timer1_pwm_on()
#endif
static int *pmelody;
static void event_beep(void) {
timer1_pwm_off();
if (*pmelody == END) {
pmelody = (void*)0;
return;
} else if (*pmelody != R) {
timer1_pwm_freq(*pmelody);
}
pmelody++;
event_set(event_beep, *pmelody);
pmelody++;
}
void beep_init(void) {
timer1_init();
pmelody = (void*)0;
}
void beep(int time, int freq) {
timer1_pwm_on();
timer1_pwm_freq(freq);
delay_ms(time);
timer1_pwm_off();
}
void beep_play(int *melody) {
timer1_pwm_on();
pmelody = melody;
event_set(event_beep, 5);
}
int beep_is_play(void) {
if (pmelody == (void*)0) {
return 0;
}
return 1;
}
void beep_sound(int time, int freq) {
timer1_pwm_on();
timer1_pwm_freq(freq);
delay_ms(time);
timer1_pwm_off();
}