我将以前的MIDI键盘程序弄到万利的STM32板上来了,哈哈~~~
[复制链接]
代码看得比较晕,经过一个晚上加一个上午的奋斗,终于把程序改好了~~~~
我是拿原来的USB摇杆的那个程序来改的,所以里面还有很多原来的摇杆方面的东东,
懒得去改它了,能用就行了。
源代码包下载:
https://bbs.eeworld.com.cn/upfiles/img/20076/20076221556505.rar
下载后将其解压缩到万利的USB DEMO路径下,即:
ManleyEKBoardEKSTM32FUSBDemo(8M osc)USBDemoUSBLibdemos
然后编译,烧入,插上USB口就可以发现新硬件了,是一个USB AUDIO设备。
然后就可以使用一些支持MIDI接口的软件来弹琴了~~~不过这个板子上的开关太少了,
我就用了那个摇杆的,4个方向有4个音。中间那个压是播放里面存储的一个歌,
进入播放后,再动一下那个摇杆就会退出播放了。
这个是我以前在HappyEO下录的自动弹奏的曲子:
http://computer00.2 1ic.org/uploadfile-/2007-12/1215456159.rar
这个是HappyEO电子琴小软件:
http://computer00. 2 1ic.org/uploadfile-/2007-12/1215291213.rar
打开HappyEO电子琴(或者其它类似能够接收MIDI输入的软件),点
击HappyEO面板上的Option按钮,在弹出的对话框中,单击MIDI输入标签,
然后将“用MIDI输入设备”勾上,在下面的“使用下列MIDI输入设备:”
列表框中选中“USB Audio Device”,然后单击确定。这时再按STM32
板上的按键,电脑应该能发声。如果不能发声,检查音量是否打开。双击
任务栏右下角的小喇叭,里边有个“MIDI Synth”,这个是控制MIDI合成
音量的。最左边那个总音量。按下摇杆中键,就会自动弹奏内置的一首曲子。在HappyEO面板的右半部分可以选择不同的乐器,右击一个数字,在弹出的框中可以选择具体的乐器。只放了一个测试的歌在里面,大家可以根据我的格式,自己放自己喜欢的歌进去^_^。
部分源代码:
/*******************************************************************************
* Function Name : main.
* Description : main routine.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
int main(void)
{
#ifdef DEBUG
debug();
#endif
Set_System();
USB_Interrupts_Config();
Set_USBClock();
USB_Init();
Led_Config();
while (1)
{
DelayXms(5);
KeyScan();
if(KeyDown)
{
GPIO_SetBits(GPIOC,KeyPress<<3);
}
if(KeyUp)
{
GPIO_ResetBits(GPIOC,KeyUp<<3);
}
if (KeyDown || KeyUp)
{
Midi_Send();
}
}
}
unsigned char Volume=0x64;
// 5 6 7 1 2 3 4 5 6 7 1
// 55 57 59 60 62 64 65 67 69 71 72
//C 48 55 60 64
//Em 40 55 59 64
//Am 45 57 60 64
//D 50 57 62 66
//Dm 50 57 62 65
//F 41 57 60 65
//G 43 55 59 67
//《容易受伤的女人》,4/4拍,78拍每分,每个4分音符时值约为769ms,实际取768ms。
//结构说明:
//第一行为歌曲的总长度(行数)
//接下来的每一行第一个元素表示本行内有多少个音符
//第二个元素表示音高,第三个表示音量(0表示关闭),第四个又表示音高,如此循环,最后一个为时值。
#define BT1 32,24
#ifdef debug
const unsigned char SongTable1[]=
{
5/256, 5%256,
//第一小节
//C和弦
1, 48,101,BT1/2,
1, 55,70,BT1/2,
2, 55,0, 60,70,BT1/2,
2, 60,0, 64,70,BT1/2,
2, 48,0, 64,0,BT1
};
#else
const unsigned char SongTable1[]=
{
352/256, 352%256,
//第一小节
//C和弦
1, 48,101,BT1/2,
1, 55,70,BT1/2,
2, 55,0, 60,70,BT1/2,
2, 60,0, 64,70,BT1/2,
//C和弦
1, 64,70,BT1/2,
1, 55,70,BT1/2,
4, 48,0, 55,0, 60,70, 55,100,BT1/2, //5
4, 60,0, 55,0, 64,70, 57,100,BT1/2, //6
//第二小节
//C和弦
4, 64,0, 57,0, 48,101, 60,100,BT1/2, //1
3, 60,0, 55,70, 60,100,BT1/2, //1
4, 55,0, 60,0, 60,70, 60,100,BT1/2, //1
5, 48,0, 60,0, 60,0, 64,70, 62,100,BT1/4, //2
2, 62,0, 64,100,BT1/4, //3
//Em和弦
1, 40,101,BT1/2, //
1, 55,70,BT1/2,
2, 55,0, 59,70,BT1/2, //0
4, 40,0, 59,0, 64,70, 64,100,BT1/4, //3
1, 67,100,BT1/4, //5
//第三小节
//Am和弦
4, 64,0, 67,0, 45,101, 69,100, BT1/2, //6
2, 57,70, 69,100,BT1/2, //6
4, 57,0, 69,0, 60,70, 71,100,BT1/3, //7
2, 71,0, 69,100,BT1/6, //6
3, 45,0, 60,0, 64,70,BT1/6,
2, 69,0, 67,100,BT1/3,//5
//Em和弦
4, 64,0, 67,0, 40,101, 64,100,BT1/2, //3
1, 55,70,BT1/2,
3, 55,0, 64,0, 59,70,BT1/2, //0
4, 40,0, 59,0, 64,70, 64,100,BT1/2, //3
//第四小节
//Dm和弦
3, 64,0, 50,101, 62,100, BT1/2, //2
1, 57,70,BT1/2,
4, 57,0, 62,0, 62,70, 62,100, BT1/4, //2
1, 60,100,BT1/4, //1
5, 62,0, 60,0, 50,0, 65,70, 57,100, BT1/4, //6
2, 57,0, 55,100,BT1/4, //5
//Am和弦
4, 65,0, 55,0, 45,101, 57,100,BT1/2, //6
1, 57,70,BT1/2,
2, 57,0, 60,70,BT1/2,
3, 45,0, 60,0, 64,70,BT1/4, //0
1, 55,100,BT1/4, //5
//第五小节
//F和弦
4, 64,0, 55,0, 41,101, 60,100, BT1/2, //1
1, 57,70, BT1/2,
3, 57,0, 60,70, 60,100,BT1/2, //1
4, 41,0, 60,0, 64,70, 60,100,BT1/2, //1
//G和弦
4, 64,0, 60,0, 43,101, 62,100,BT1/2, //2
1, 55,70,BT1/2,
2, 55,0, 59,70,BT1/2, //0
4, 59,0, 43,0, 67,70, 55,100,BT1/4, //5
2, 55,0, 57,100,BT1/4, //6
//第六小节
//C和弦
4, 67,0, 57,0, 48,101, 60,100,BT1/2, //1
3, 60,0, 55,70, 60,100,BT1/2, //1
4, 55,0, 60,0, 60,70, 60,100,BT1/2, //1
5, 48,0, 60,0, 60,0, 64,70, 62,100,BT1/4, //2
2, 62,0, 64,100,BT1/4, //3
//Em和弦
1, 40,101,BT1/2, //
1, 55,70,BT1/2,
2, 55,0, 59,70,BT1/2, //0
4, 40,0, 59,0, 64,70, 64,100,BT1/4, //3
1, 67,100,BT1/4, //5
//第七小节
//Am和弦
4, 64,0, 67,0, 45,101, 69,100, BT1/2, //6
2, 57,70, 69,100,BT1/2, //6
4, 57,0, 69,0, 60,70, 71,100,BT1/3, //7
2, 71,0, 69,100,BT1/6, //6
3, 45,0, 60,0, 64,70,BT1/6,
2, 69,0, 67,100,BT1/3,//5
//Em和弦
4, 64,0, 67,0, 40,101, 64,100,BT1/2, //3
1, 55,70,BT1/2,
3, 55,0, 64,0, 59,70,BT1/2, //0
4, 40,0, 59,0, 64,70, 64,100,BT1/2, //3
//第八小节
//Dm和弦
3, 64,0, 50,101, 62,100, BT1/2, //2
1, 57,70,BT1/2,
4, 57,0, 62,0, 62,70, 62,100, BT1/4, //2
1, 60,100,BT1/4, //1
5, 62,0, 60,0, 50,0, 65,70, 57,100, BT1/4, //6
2, 57,0, 55,100,BT1/4, //5
//Am和弦
4, 65,0, 55,0, 45,101, 57,100,BT1/2, //6
1, 57,70,BT1/2,
2, 57,0, 60,70,BT1/2,
3, 45,0, 60,100, 64,70,BT1/2, //1
//到这里是78个
//第九小节
//Em和弦
4, 60,0, 64,0, 40,101, 59,100,BT1/2, //7
1, 55,70,BT1/2,
4, 55,0, 59,0, 59,70, 57,100, BT1/2, //6
5, 40,0, 59,0, 57,0, 64,70, 55,100, BT1/2, //5
//Am和弦
4, 64,0, 55,0, 45,101, 57,100, BT1/2, //6
1, 57,70,BT1/2,
3, 57,0, 60,70, 60,100,BT1/2, //1
4, 60,0, 45,0, 64,70, 62,100,BT1/2, //2
//第十小节
//C和弦
4, 64,0, 62,0, 48,101, 64,100, BT1/2, //3
3, 64,0, 55,70, 67,100,BT1/2, //5
4, 55,0, 67,0, 60,70, 64,100,BT1/4, //3
2, 64,0, 62,100,BT1/4, //2
5, 48,0, 60,0, 62,0, 64,70, 60,100,BT1/4, //1
2, 60,0, 62,100,BT1/4, //2
//Am和弦
4, 64,0, 62,0, 45,101, 64,100, BT1/2, //3
3, 64,0, 57,70, 69,100,BT1/2, //6
4, 57,0, 69,0, 60,70, 64,100,BT1/4, //3
2, 64,0, 62,100,BT1/4, //2
5, 45,0, 60,0, 62,0, 64,70, 60,100,BT1/4, //1
2, 60,0, 62,100,BT1/4, //2
//到这里是98个
//第十一小节
//Em和弦
4, 62,0, 64,0, 40,101, 64,100, BT1/2, //3
3, 64,0, 55,70, 71,100, BT1/2, //7
4, 55,0, 71,0, 59,70, 71,100,BT1/2, //7
5, 40,0, 59,0, 71,0, 64,70, 67,100,BT1/2, //5
//Am和弦
4, 64,0, 67,0, 45,101, 69,100, BT1/2, //6
1, 57,70,BT1/2,
3, 57,0, 60,70, 69,100,BT1/2, //6
5, 45,0, 60,0, 69,0, 64,70, 67,100,BT1/2, //5
//第十二小节
//F和弦
4, 64,0, 69,0, 41,101, 69,100, BT1/2, //6
3, 69,0, 57,70, 67,100,BT1/2, //5
4, 57,0, 67,0, 60,70, 69,100,BT1/4, //6
2, 69,0, 67,100, BT1/4, //5
5, 41,0, 60,0, 67,0, 65,70, 64,100,BT1/4, //3
2, 64,0, 62,100,BT1/4, //2
//C和弦
4, 65,0, 62,0, 48,101, 64,100, BT1/2, //3
3, 64,0, 55,70, 67,100, BT1/2, //5
4, 55,0, 67,0, 60,70, 64,100,BT1/2, //3
5, 48,0, 60,0, 64,0, 64,70, 64,100, BT1/2, //3
//第十三小节
//Dm和弦
3, 64,0, 50,101, 62,100,BT1/2, //2
1, 57,70,BT1/2,
3, 57,0, 62,70, 60,100,BT1/2, //1
5, 50,0, 62,0, 60,0, 65,70, 62,100,BT1/2, //2
//Em和弦
4, 65,0, 62,0, 40,101, 64,100, BT1/2, //3
1, 55,70, BT1/2,
3, 55,0, 59,70, 60,100,BT1/2, //1
5, 40,0, 59,0, 60,0, 64,70, 62,100,BT1/2, //2
//第十四小节
//C和弦
4, 64,0, 62,0, 48,101, 64,100, BT1/2, //3
3, 64,0, 55,70, 67,100,BT1/2, //5
4, 55,0, 67,0, 60,70, 64,100,BT1/4, //3
2, 64,0, 62,100,BT1/4, //2
5, 48,0, 60,0, 62,0, 64,70, 60,100,BT1/4, //1
2, 60,0, 62,100,BT1/4, //2
//Am和弦
4, 64,0, 62,0, 45,101, 64,100, BT1/2, //3
3, 64,0, 57,70, 69,100,BT1/2, //6
4, 57,0, 69,0, 60,70, 64,100,BT1/4, //3
2, 64,0, 62,100,BT1/4, //2
5, 45,0, 60,0, 62,0, 64,70, 60,100,BT1/4, //1
2, 60,0, 62,100,BT1/4, //2
//第十五小节
//Em和弦
4, 62,0, 64,0, 40,101, 64,100, BT1/2, //3
3, 64,0, 55,70, 71,100, BT1/2, //7
4, 55,0, 71,0, 59,70, 71,100,BT1/2, //7
5, 40,0, 59,0, 71,0, 64,70, 67,100,BT1/2, //5
//Am和弦
4, 64,0, 67,0, 45,101, 69,100, BT1/2, //6
1, 57,70,BT1/2,
3, 57,0, 60,70, 69,100,BT1/2, //6
5, 45,0, 60,0, 69,0, 64,70, 67,100,BT1/4, //5
2, 67,0, 69,100,BT1/4, //6
//第十六小节
//D和弦
4, 64,0, 59,0, 50,101, 69,100,BT1/2, //6
1, 57,70, BT1/2,
2, 57,0, 62,70, BT1/2,
5, 50,0, 62,0, 69,0, 66,70, 67,100, BT1/2, //5
//D和弦
4, 66,0, 67,0, 50,101, 69,100,BT1/2, //6
3, 69,0, 57,70, 72,100, BT1/2, //1
2, 57,0, 62,70, BT1/2,
5, 50,0, 62,0, 72,0, 66,70, 69,100,BT1/2, //6
//第十七小节
//G和弦
4, 66,0, 69,0, 43,101, 64,100, BT1/2, //3
3, 64,0, 55,70, 67,100, BT1/2, //5
2, 55,0, 59,70, BT1/2,
3, 43,0, 59,0, 67,70,BT1/2,
//G和弦
1, 43,60,BT1/2,
1, 55,50,BT1/2,
3, 55,0, 67,0, 59,50,BT1/2,
4, 43,0, 59,0, 67,60, 55,100, BT1/4, //5
2, 55,0, 57,100, BT1/4, //6
//到这里是162个
//第十八小节
//C和弦
4, 67,0, 57,0, 48,101, 60,100,BT1/2, //1
3, 60,0, 55,70, 60,100,BT1/2, //1
4, 55,0, 60,0, 60,70, 60,100,BT1/2, //1
5, 48,0, 60,0, 60,0, 64,70, 62,100,BT1/4, //2
2, 62,0, 64,100,BT1/4, //3
//Em和弦
1, 40,101,BT1/2, //
1, 55,70,BT1/2,
2, 55,0, 59,70,BT1/2, //0
4, 40,0, 59,0, 64,70, 64,100,BT1/4, //3
1, 67,100,BT1/4, //5
//第十九小节
//Am和弦
4, 64,0, 67,0, 45,101, 69,100, BT1/2, //6
2, 57,70, 69,100,BT1/2, //6
4, 57,0, 69,0, 60,70, 71,100,BT1/3, //7
2, 71,0, 69,100,BT1/6, //6
3, 45,0, 60,0, 64,70,BT1/6,
2, 69,0, 67,100,BT1/3,//5
//Em和弦
4, 64,0, 67,0, 40,101, 64,100,BT1/2, //3
1, 55,70,BT1/2,
3, 55,0, 64,0, 59,70,BT1/2, //0
4, 40,0, 59,0, 64,70, 64,100,BT1/2, //3
//第二十小节
//Dm和弦
3, 64,0, 50,101, 62,100, BT1/2, //2
1, 57,70,BT1/2,
4, 57,0, 62,0, 62,70, 62,100, BT1/4, //2
1, 60,100,BT1/4, //1
5, 62,0, 60,0, 50,0, 65,70, 57,100, BT1/4, //6
2, 57,0, 55,100,BT1/4, //5
//Am和弦
4, 65,0, 55,0, 45,101, 57,100,BT1/2, //6
1, 57,70,BT1/2,
2, 57,0, 60,70,BT1/2,
3, 45,0, 60,100, 64,70,BT1/2, //1
//到这里是192个
//第二十一小节
//Em和弦
4, 60,0, 64,0, 40,101, 59,100,BT1/2, //7
1, 55,70,BT1/2,
4, 55,0, 59,0, 59,70, 57,100, BT1/2, //6
5, 40,0, 59,0, 57,0, 64,70, 55,100, BT1/2, //5
//Am和弦
4, 64,0, 55,0, 45,101, 57,100, BT1/2, //6
1, 57,70,BT1/2,
3, 57,0, 60,70, 60,100,BT1/2, //1
4, 60,0, 45,0, 64,70, 62,100,BT1/2, //2
//到这里是200个
//第二十二小节
//C和弦
4, 64,0, 62,0, 48,101, 64,100, BT1/2, //3
3, 64,0, 55,70, 67,100,BT1/2, //5
4, 55,0, 67,0, 60,70, 64,100,BT1/4, //3
2, 64,0, 62,100,BT1/4, //2
5, 48,0, 60,0, 62,0, 64,70, 60,100,BT1/4, //1
2, 60,0, 62,100,BT1/4, //2
//Am和弦
4, 64,0, 62,0, 45,101, 64,100, BT1/2, //3
3, 64,0, 57,70, 69,100,BT1/2, //6
4, 57,0, 69,0, 60,70, 64,100,BT1/4, //3
2, 64,0, 62,100,BT1/4, //2
5, 45,0, 60,0, 62,0, 64,70, 60,100,BT1/4, //1
2, 60,0, 62,100,BT1/4, //2
//到这里是212个
//第二十三小节
//Em和弦
4, 62,0, 64,0, 40,101, 64,100, BT1/2, //3
3, 64,0, 55,70, 71,100, BT1/2, //7
4, 55,0, 71,0, 59,70, 71,100,BT1/2, //7
5, 40,0, 59,0, 71,0, 64,70, 67,100,BT1/2, //5
//Am和弦
4, 64,0, 67,0, 45,101, 69,100, BT1/2, //6
1, 57,70,BT1/2,
3, 57,0, 60,70, 69,100,BT1/2, //6
5, 45,0, 60,0, 69,0, 64,70, 67,100,BT1/2, //5
//第二十四小节
//F和弦
4, 64,0, 69,0, 41,101, 69,100, BT1/2, //6
3, 69,0, 57,70, 67,100,BT1/2, //5
4, 57,0, 67,0, 60,70, 69,100,BT1/4, //6
2, 69,0, 67,100, BT1/4, //5
5, 41,0, 60,0, 67,0, 65,70, 64,100,BT1/4, //3
2, 64,0, 62,100,BT1/4, //2
//C和弦
4, 65,0, 62,0, 48,101, 64,100, BT1/2, //3
3, 64,0, 55,70, 67,100, BT1/2, //5
4, 55,0, 67,0, 60,70, 64,100,BT1/2, //3
5, 48,0, 60,0, 64,0, 64,70, 64,100, BT1/2, //3
//第二十五小节
//Dm和弦
3, 64,0, 50,101, 62,100,BT1/2, //2
1, 57,70,BT1/2,
3, 57,0, 62,70, 60,100,BT1/2, //1
5, 50,0, 62,0, 60,0, 65,70, 62,100,BT1/2, //2
//Em和弦
4, 65,0, 62,0, 40,101, 64,100, BT1/2, //3
1, 55,70, BT1/2,
3, 55,0, 59,70, 60,100,BT1/2, //1
5, 40,0, 59,0, 60,0, 64,70, 62,100,BT1/2, //2
//第二十六小节
//C和弦
4, 64,0, 62,0, 48,101, 64,100, BT1/2, //3
3, 64,0, 55,70, 67,100,BT1/2, //5
4, 55,0, 67,0, 60,70, 64,100,BT1/4, //3
2, 64,0, 62,100,BT1/4, //2
5, 48,0, 60,0, 62,0, 64,70, 60,100,BT1/4, //1
2, 60,0, 62,100,BT1/4, //2
//Am和弦
4, 64,0, 62,0, 45,101, 64,100, BT1/2, //3
3, 64,0, 57,70, 69,100,BT1/2, //6
4, 57,0, 69,0, 60,70, 64,100,BT1/4, //3
2, 64,0, 62,100,BT1/4, //2
5, 45,0, 60,0, 62,0, 64,70, 60,100,BT1/4, //1
2, 60,0, 62,100,BT1/4, //2
//到这里是250个
//第二十七小节
//Em和弦
4, 62,0, 64,0, 40,101, 64,100, BT1/2, //3
3, 64,0, 55,70, 71,100, BT1/2, //7
4, 55,0, 71,0, 59,70, 71,100,BT1/2, //7
5, 40,0, 59,0, 71,0, 64,70, 67,100,BT1/2, //5
//Am和弦
4, 64,0, 67,0, 45,101, 69,100, BT1/2, //6
1, 57,70,BT1/2,
3, 57,0, 60,70, 69,100,BT1/2, //6
5, 45,0, 60,0, 69,0, 64,70, 67,100,BT1/4, //5
2, 67,0, 69,100,BT1/4, //6
//第二十八小节
//D和弦
4, 64,0, 59,0, 50,101, 69,100,BT1/2, //6
1, 57,70, BT1/2,
2, 57,0, 62,70, BT1/2,
5, 50,0, 62,0, 69,0, 66,70, 67,100, BT1/2, //5
//D和弦
4, 66,0, 67,0, 50,101, 69,100,BT1/2, //6
3, 69,0, 57,70, 72,100, BT1/2, //1
2, 57,0, 62,70, BT1/2,
5, 50,0, 62,0, 72,0, 66,70, 69,100,BT1/2, //6
//第二十九小节
//G和弦
4, 66,0, 69,0, 43,101, 64,100, BT1/2, //3
3, 64,0, 55,70, 67,100, BT1/2, //5
2, 55,0, 59,70, BT1/2,
3, 43,0, 59,0, 67,70,BT1/2,
//G和弦
1, 43,60,BT1/2,
1, 55,50,BT1/2,
3, 55,0, 67,0, 59,50,BT1/2,
4, 43,0, 59,0, 67,60, 55,100, BT1/4, //5
2, 55,0, 57,100, BT1/4, //6
//到这里是276个
//第三十小节
//C和弦
4, 67,0, 57,0, 48,101, 60,100,BT1/2, //1
3, 60,0, 55,70, 60,100,BT1/2, //1
4, 55,0, 60,0, 60,70, 60,100,BT1/2, //1
5, 48,0, 60,0, 60,0, 64,70, 62,100,BT1/4, //2
2, 62,0, 64,100,BT1/4, //3
//Em和弦
1, 40,101,BT1/2, //
1, 55,70,BT1/2,
2, 55,0, 59,70,BT1/2, //0
4, 40,0, 59,0, 64,70, 64,100,BT1/4, //3
1, 67,100,BT1/4, //5
//第三十一小节
//Am和弦
4, 64,0, 67,0, 45,101, 69,100, BT1/2, //6
2, 57,70, 69,100,BT1/2, //6
4, 57,0, 69,0, 60,70, 71,100,BT1/3, //7
2, 71,0, 69,100,BT1/6, //6
3, 45,0, 60,0, 64,70,BT1/6,
2, 69,0, 67,100,BT1/3,//5
//Em和弦
4, 64,0, 67,0, 40,101, 64,100,BT1/2, //3
1, 55,70,BT1/2,
3, 55,0, 64,0, 59,70,BT1/2, //0
4, 40,0, 59,0, 64,70, 64,100,BT1/2, //3
//到这里是296个
//第三十二小节
//Dm和弦
3, 64,0, 50,101, 62,100, BT1/2, //2
1, 57,70,BT1/2,
4, 57,0, 62,0, 62,70, 62,100, BT1/4, //2
1, 60,100,BT1/4, //1
5, 62,0, 60,0, 50,0, 65,70, 57,100, BT1/4, //6
2, 57,0, 55,100,BT1/4, //5
//Am和弦
4, 65,0, 55,0, 45,101, 57,100,BT1/2, //6
1, 57,70,BT1/2,
2, 57,0, 60,70,BT1/2,
3, 45,0, 60,100, 64,70,BT1/2, //1
//到这里是306个
//第三十三小节
//Em和弦
4, 60,0, 64,0, 40,101, 59,100,BT1/2, //7
1, 55,70,BT1/2,
4, 55,0, 59,0, 59,70, 57,100, BT1/2, //6
5, 40,0, 59,0, 57,0, 64,70, 55,100, BT1/2, //5
//Am和弦
4, 64,0, 55,0, 45,101, 57,100, BT1/2, //6
1, 57,70,BT1/2,
2, 57,0, 60,70,BT1/2,
4, 60,0, 45,0, 64,70, 57,0,BT1/2,
//到这里是314个
//第三十四小节
//Dm和弦
3, 64,0, 50,101, 62,100, BT1/2, //2
1, 57,70,BT1/2,
4, 57,0, 62,0, 62,70, 62,100, BT1/4, //2
1, 60,100,BT1/4, //1
5, 62,0, 60,0, 50,0, 65,70, 57,100, BT1/4, //6
2, 57,0, 55,100,BT1/4, //5
//Am和弦
4, 65,0, 55,0, 45,101, 57,100,BT1/2, //6
1, 57,70,BT1/2,
2, 57,0, 60,70,BT1/2,
3, 45,0, 60,100, 64,70,BT1/2, //1
//到这里是324个
//第三十五小节
//Em和弦
4, 60,0, 64,0, 40,101, 59,100,BT1/2, //7
1, 55,70,BT1/2,
4, 55,0, 59,0, 59,70, 57,100, BT1/2, //6
5, 40,0, 59,0, 57,0, 64,70, 55,100, BT1/2, //5
//Am和弦
4, 64,0, 55,0, 45,101, 57,100, BT1/2, //6
1, 57,70,BT1/2,
2, 57,0, 60,70,BT1/2,
4, 60,0, 45,0, 64,70, 57,0,BT1/2,
//第三十六小节
//Dm和弦
3, 64,0, 50,101, 62,100, BT1/2, //2
1, 57,70,BT1/2,
4, 57,0, 62,0, 62,70, 62,100, BT1/4, //2
1, 60,100,BT1/4, //1
5, 62,0, 60,0, 50,0, 65,70, 57,100, BT1/4, //6
2, 57,0, 55,100,BT1/4, //5
//Am和弦
4, 65,0, 55,0, 45,101, 57,100,BT1/2, //6
1, 57,70,BT1/2,
2, 57,0, 60,70,BT1/2,
3, 45,0, 60,100, 64,70, 36,24/2, //1
//到这里是342个
//第三十七小节
//Em和弦
4, 60,0, 64,0, 40,101, 59,100, 40,24/2, //7
1, 55,70, 44,24/2,
4, 55,0, 59,0, 59,70, 57,100, 48,24/2, //6
5, 40,0, 59,0, 57,0, 64,70, 55,100, 52,24/2, //5
//Am和弦
4, 64,0, 55,0, 45,101, 57,100, 56,18, //6
// 1, 57,70, 64,24/2,
// 2, 57,0, 60,70, 68,24/2,
// 3, 60,0, 45,0, 64,70, 72,24/2,
3, 45,0, 56,0, 76-12,70,BT1/4,
1, 81-12,70,BT1/4,
1, 84-12,70,BT1/4,
1, 100-12,70,BT1,
4, 76,0, 81,0, 84,0, 100,0, BT1
//到这里是352个
};
#endif
/***************** 延时x毫秒函数 ***********/
void DelayXms(unsigned int x)
{
unsigned int i,j;
for(i=0;i<x;i++)
for(j=0;j<5150;j++);
}
/********************************************/
/***********************自动播放歌曲*******************************/
void PlaySong(unsigned char index)
{
unsigned short int i,k,d;
unsigned char j,t;
unsigned char *p;
unsigned char MidiBuffer[4];
MidiBuffer[0]=0x09;
MidiBuffer[1]=0x90;
switch(index)
{
case 1: p=(unsigned char*)SongTable1; break;
default: return;
}
i=0;
k=p[i++];
k=(k<<8)+p[i++];
while(k--)
{
if(JoyState() != 0) //用户按下任意键,停止播放
{
break;
}
t=p[i++];
for(j=0;j<t;j++)
{
//Note on
MidiBuffer[2]=p[i++];
MidiBuffer[3]=p[i++];
//等待发送完毕.
while(_GetEPTxStatus(ENDP1)!=(0x02<<4));
/*copy midi buffer to ENDP1 Tx Packet Memory Area*/
UserToPMABufferCopy(MidiBuffer, GetEPTxAddr(ENDP1), 4);
/* enable endpoint for transmission */
SetEPTxValid(ENDP1);
}
d=p[i++];
d*=p[i++];
DelayXms(d);
}
//关所有音符
MidiBuffer[3]=0x00;
for(i=20;i<128;i++)
{
MidiBuffer[2]=i;
//等待发送完毕.
while(_GetEPTxStatus(ENDP1)!=(0x02<<4));
/*copy midi buffer to ENDP1 Tx Packet Memory Area*/
UserToPMABufferCopy(MidiBuffer, GetEPTxAddr(ENDP1), 4);
/* enable endpoint for transmission */
SetEPTxValid(ENDP1);
}
}
/*******************************************************************/
/*******************************************************************************
* Function Name : Midi_Send.
* Description : prepares buffer to be sent containing Midi event infos.
* Input : None.
* Output : None.
* Return value : None.
*******************************************************************************/
void Midi_Send(void)
{
u8 MidiBuffer[4] = {0, 0, 0, 0};
if(KeyDown & KEY_LEFT)
{
//Note on
MidiBuffer[0]=0x09;
MidiBuffer[1]=0x90;
MidiBuffer[2]=60; //1 中央C
MidiBuffer[3]=Volume;
}
if(KeyUp & KEY_LEFT)
{
//Note off
MidiBuffer[0]=0x09;
MidiBuffer[1]=0x90;
MidiBuffer[2]=60; //1 中央C
MidiBuffer[3]=0;
}
if(KeyDown & KEY_UP)
{
//Note on
MidiBuffer[0]=0x09;
MidiBuffer[1]=0x90;
MidiBuffer[2]=62; //2
MidiBuffer[3]=Volume;
}
if(KeyUp & KEY_UP)
{
//Note off
MidiBuffer[0]=0x09;
MidiBuffer[1]=0x90;
MidiBuffer[2]=62; //2
MidiBuffer[3]=0;
}
if(KeyDown & KEY_RIGHT)
{
//Note on
MidiBuffer[0]=0x09;
MidiBuffer[1]=0x90;
MidiBuffer[2]=64; //3
MidiBuffer[3]=Volume;
}
if(KeyUp & KEY_RIGHT)
{
//Note off
MidiBuffer[0]=0x09;
MidiBuffer[1]=0x90;
MidiBuffer[2]=64; //3
MidiBuffer[3]=0;
}
if(KeyDown & KEY_DOWN)
{
//Note on
MidiBuffer[0]=0x09;
MidiBuffer[1]=0x90;
MidiBuffer[2]=65; //4
MidiBuffer[3]=Volume;
}
if(KeyUp & KEY_DOWN)
{
//Note off
MidiBuffer[0]=0x09;
MidiBuffer[1]=0x90;
MidiBuffer[2]=65; //4
MidiBuffer[3]=0;
}
if(KeyUp & KEY_SEL)
{
PlaySong(1);
//Note off
MidiBuffer[0]=0x09;
MidiBuffer[1]=0x90;
MidiBuffer[2]=60;
MidiBuffer[3]=0;
}
KeyUp=0;
KeyDown=0;
//等待发送完毕.
while(_GetEPTxStatus(ENDP1)!=(0x02<<4));
/*copy midi buffer to ENDP1 Tx Packet Memory Area*/
UserToPMABufferCopy(MidiBuffer, GetEPTxAddr(ENDP1), 4);
/* enable endpoint for transmission */
SetEPTxValid(ENDP1);
}
/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
|