#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
#include "leds.h"
#include "beep.h"
Uint16 Musi[23]={ //单位us,不同频率下,不同声调的声音
0,
3816, //L_do
3496, //L_re
3215, //L_mi
2865, //L_fa
2551, //L_so
2272, //L_la
2024, //L_xi
1912, //do
1703, //re
1517, //mi
1432, //fa
1275, //so
1136, //la
1013, //xi
956, //H_do
851, //H_re
758, //H_mi
716, //H_fa
638, //H_so
568, //H_la
506, //H_xi
0xFF //STOP
};
//Uint16 Song[]={1,1,5,5,6,6,5,4,4,3,3,2,2,1,5,5,4,4,3,3,2,5,5,4,4,3,3,2,22}; //一闪一闪亮晶晶
//Uint16 DT[] ={2,2,2,2,2,2,4,2,2,2,2,2,2,4,2,2,2,2,2,2,4,2,2,2,2,2,2,4}; //节拍
//Uint16 Song[]={5,5,6,5,8,7,5,5,6,5,8,7,5,5,5,10,8,7,6,11,10,8,9,8,22}; //祝你生日快乐
//Uint16 DT[] ={2,2,5,4,6,8,2,2,5,6,6,9,4,2,5,4,6,12,2,2,5,6,8,12 }; //节拍
Uint16 Song[]={15,16,13,15,12,19,21,20,19,17,19,16,16,17,14,13,
12,13,15,16,10,15,13,12,13,15,12,17,19,14,16,13,
15,12,10,12,10,12,13,14,16,13,12,13,15,16,19,17,
16,17,16,15,13,12,10,10,15,13,15,13,12,10,12,13,
15,12,22}; //梁祝
Uint16 DT[] ={3,1,1,1,2,3,1,1,1,1,1,4,3,1,2,2,
3,1,2,2,2,2,1,1,1,1,4,3,1,2,2,1,
1,4,1,2,2,1,1,1,1,4,1,1,3,1,2,2,
2,1,1,2,1,1,2,4,4,3,1,1,1,1,1,1,
1,4}; //节拍
Uint32 gain = 600000;
void ledSelect(int a)
{
switch(a)
{
case 0: LED1_TOGGLE; break;
case 1: LED2_TOGGLE; break;
case 2: LED3_TOGGLE; break;
case 3: LED4_TOGGLE; break;
case 4: LED5_TOGGLE; break;
case 5: LED6_TOGGLE; break;
case 6: LED7_TOGGLE; break;
}
}
/*******************************************************************************
* 函 数 名 : main
* 函数功能 : 主函数
* 输 入 : 无
* 输 出 : 无
*******************************************************************************/
void main()
{
InitSysCtrl();
LED_Init();
BEEP_Init();
KEY_Init();
while(1)
{
Uint16 addr = 0;
while(1)
{
if(Musi[Song[addr]] == 0xFF)
{
break;
}
else
{
Uint32 countTime = 0;
ledSelect((Song[addr]+1) % 7);
while(countTime < gain * DT[addr])
{
if(countTime % Musi[Song[addr]] == 0)
BEEP_TOGGLE;
countTime++;
}
ledSelect((Song[addr]+1) % 7);
Uint32 i = 0;
for(i = 0;i < gain; i++);
addr++;
}
}
}
}
成功!