eecs-bsp-test-code/music/main.c

111 lines
3.0 KiB
C

// This project is used for demonstrating digital tubes of BSP library.
#include "STC15F2K60S2.H"
#include "displayer.h"
#include "key.H"
#include "music.h"
#include "Beep.h"
#include "sys.H"
#include "huahai.h"
code unsigned long SysClock = 11059200; //必须。定义系统工作时钟频率(Hz),用户必须修改成与实际工作频率(下载时选择的)一致
#ifdef _displayer_H_ //显示模块选用时必须。(数码管显示译码表,用戶可修改、增加等)
code char decode_table[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x00, 0x08, 0x40, 0x01, 0x41, 0x48,
/* 序号: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */
/* 显示: 0 1 2 3 4 5 6 7 8 9 (无) 下- 中- 上- 上中- 中下- */
0x3f | 0x80, 0x06 | 0x80, 0x5b | 0x80, 0x4f | 0x80, 0x66 | 0x80, 0x6d | 0x80, 0x7d | 0x80, 0x07 | 0x80, 0x7f | 0x80, 0x6f | 0x80};
/* 带小数点 0 1 2 3 4 5 6 7 8 9 */
#endif
char result;
char changeBit(char x, char n, char y)
{
char temp = x;
temp &= ~(1 << n);
temp |= (y << n);
return temp;
}
void makeNoise()
{
static char led = 0x0;
char key1 = GetKeyAct(enumKey1), key2 = GetKeyAct(enumKey2), key3 = GetKeyAct(enumKey3);
if (key1 == enumKeyPress)
{
led = changeBit(led, 0, 1);
// G tone, 60 bpm, 1 beat
result=PlayTone(0xf9, 60, 0x13, 16);
}
else if (key1 == enumKeyRelease)
{
led = changeBit(led, 0, 0);
}
if (key2 == enumKeyPress)
{
led = changeBit(led, 1, 1);
SetPlayerMode(enumModePlay);
}
else if (key2 == enumKeyRelease)
{
led = changeBit(led, 1, 0);
}
LedPrint(led);
}
void checkMode()
{
static char status[8] = {10, 10, 10, 10, 10, 10, 10, 10};
char m = GetPlayerMode();
switch (m)
{
case enumModeInvalid:
status[0] = 1;
break;
case enumModePlay:
status[0] = 2;
break;
case enumModePause:
status[0] = 3;
break;
case enumModeStop:
status[0] = 4;
break;
default:
break;
}
switch(result)
{
case enumBeepFree:
status[1]=1;
break;
case enumBeepBusy:
status[1]=2;
break;
case enumSetBeepOK:
status[1]=3;
break;
case enumSetBeepFail:
status[1]=4;
break;
}
Seg7Print(status[0], status[1], status[2], status[3], status[4], status[5], status[6], status[7]);
}
void main()
{
DisplayerInit();
KeyInit();
MusicPlayerInit();
SetDisplayerArea(0, 7);
SetEventCallBack(enumEventKey, makeNoise);
SetEventCallBack(enumEventSys1mS, checkMode);
MySTC_Init();
LedPrint(0xff);
Seg7Print(10, 10, 10, 10, 10, 10, 10, 10);
while (1)
{
MySTC_OS();
}
}