首页 新闻 会员 周边 捐助

DSP28335利用键盘作电子琴,不同按键声音不一样,亮不同的灯

0
悬赏园豆:200 [待解决问题]

include "DSP2833x_Device.h" // DSP2833x Headerfile Include File

include "DSP2833x_Examples.h" // DSP2833x Examples Include File

include "leds.h"

include "beep.h"

include "key.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(char key)
{
int k=0;
while(1)
{
key=KEY_Scan(0);
switch(key)
{
case KEY1_PRESS: LED2_TOGGLE;break;
case KEY2_PRESS: LED3_TOGGLE;break;
case KEY3_PRESS: LED4_TOGGLE;break;
case KEY4_PRESS: LED5_TOGGLE;break;
case KEY5_PRESS: LED6_TOGGLE;break;
case KEY6_PRESS: LED7_TOGGLE;break;
}
k++;
if(k%2000==0)
{
LED1_TOGGLE;
}
DELAY_US(100);
}
}
//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++;
          }
      }
    

    }
    }

include "DSP2833x_Device.h" // DSP2833x Headerfile Include File

include "DSP2833x_Examples.h" // DSP2833x Examples Include File

include "leds.h"

include "key.h"

include "beep.h"

int tune[]= //根据简谱列出各频率
{
M3,M3,M3,M2,M3,M5,M5,M5,
M6,M6,M6,M5,M3,M6,M5,M5,
H1,H1,H1,M6,H2,H1,M5,M5,

M6,M6,M6,H1,M6,M5,M3,M2,
M3,M3,M3,M2,M3,M5,M5,M5,
M6,M6,M6,M5,M3,M5,M6,M5,

H1,H1,M6,H2,H1,M5,M5,
M6,M6,M6,M5,M6,H3,H2,
H2,M5,H1,H2,
H3,H2,H1,M7,H1,M7,M6,M5,

M6,0,0,H1,H2,
H3,H2,H1,M7,H1,M7,M3,M5,
M6,0,M6,M5,
M6,H1,H1,0,H1,H2,

H3,H1,H2,H1,H1,M6,M6,
H4,H3,H2,H1,H4,H4,H3,H2,H1,
H2,H3,H2,H1,
H1,H1,H2,H3,H1,

H6,H5,H3,H2,H1,M6,
0,M5,H1,H3,H5,H6,H3,H3,H2,H1,
M6,H1,H1,H2,H1,H1
};

float beat[]= //根据简谱列出各节拍
{
0.25,0.25,0.25,0.25,0.5,0.25,0.25,2,
0.25,0.25,0.25,0.25,0.5,0.25,0.25,2,
0.25,0.25,0.25,0.25,0.5,0.25,0.25,2,

0.25,0.25,0.25,0.25,0.25,0.5,0.25,2,
0.25,0.25,0.25,0.25,0.5,0.25,0.25,2,
0.25,0.25,0.25,0.25,0.5,0.25,0.25,2,

0.25,0.5,0.25,0.5,0.25,0.25,2,
0.25,0.25,0.25,0.25,0.5,0.5,2,
0.5,0.5,0.5,0.5,
0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,

2,1,0.5,0.25,0.25,
0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,
3,0.5,0.25,0.25,
0.5,0.5,1,0.5,1,0.5,

0.5,0.5,0.5,0.5,1.5,0.25,0.25,
0.5,0.5,0.5,0.25,0.25,0.5,0.5,0.5,0.5,
3,0.5,0.25,0.25,
1,0.5,0.5,1.5,0.5,

0.5,0.5,0.25,0.25,0.5,2,
0.5,0.5,0.5,0.5,0.5,0.25,0.25,0.25,0.25,0.5,
0.5,0.5,0.25,0.5,0.25,2
};

void main()
{
int k=0;
char key=0;
key=KEY_Scan(0);

InitSysCtrl();

BEEP_Init();
LED_Init();
KEY_Init();
while(1)
{

    switch(key)
    {
        case KEY1_PRESS: LED2_TOGGLE;break;
        case KEY2_PRESS: LED3_TOGGLE;break;
        case KEY3_PRESS: LED4_TOGGLE;break;
        case KEY4_PRESS: LED5_TOGGLE;break;
        case KEY5_PRESS: LED6_TOGGLE;break;
        case KEY6_PRESS: LED7_TOGGLE;break;
    }
    BEEP_TOGGLE;
    k++;
    if(k%2000==0)
    {
        LED1_TOGGLE;
    }
    DELAY_US(100);
}

}

威威111闪烁的主页 威威111闪烁 | 初学一级 | 园豆:2
提问于:2021-12-15 15:41
< >
分享
所有回答(1)
0

你这个是源代码吗?

echo_lovely | 园豆:1584 (小虾三级) | 2021-12-16 17:15
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册