Files
30dayMakeOS/25_day/beepdown.c
2016-05-13 10:32:51 +08:00

25 lines
536 B
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
void api_end(void);
int api_getkey(int mode);
int api_alloctimer(void);
void api_inittimer(int timer, int data);
void api_settimer(int timer, int time);
void api_beep(int tone);
void HariMain(void)
{
int i, timer;
timer = api_alloctimer();
api_inittimer(timer, 128);
for (i = 20000000; i >= 20000; i -= i / 100) {
/* 20KHz20Hz即人类可以听到的声音范围*/
/* i以1%的速度递减*/
api_beep(i);
api_settimer(timer, 1); /* 0.01秒*/
if (api_getkey(1) != 128) {
break;
}
}
api_beep(0);
api_end();
}