STM32_3.5Lib_MIDI音乐实现
MIDI.c函数
uc16 music1[78]={ //音乐1的数据表(奇数是音调,偶数是长度)
330,750,440,375,494,375,523,750,587,375,659,375,587,750,494,375,392,375,440,1500,330,750,440,375,494,375,
523,750,587,375,659,375,587,750,494,375,392,375,784,1500,659,750,698,375,784,375,880,750,784,375,698,375,
659,750,587,750,659,750,523,375,494,375,440,750,440,375,494,375,523,750,523,750,494,750,392,750,440,3000
};
void MIDI_PLAY(void)
{ //MIDI音乐
u16 i,e;
for(i=0;i<39;i++)
{
for(e=0;e<music1[i*2]*music1[i*2+1]/1000;e++)
{
GPIO_WriteBit(BUZZERPORT,BUZZER,(BitAction)(0)); //蜂鸣器接口输出0
delay_us(500000/music1[i*2]); //延时
GPIO_WriteBit(BUZZERPORT,BUZZER,(BitAction)(1)); //蜂鸣器接口输出高电平1
delay_us(500000/music1[i*2]); //延时
}
}
}
MIDI.h头文件
#ifndef __LED_H
#define __LED_H
#include "sys.h"
//#define LED1 PBout(0)// PB0
//#define LED2 PBout(1)// PB1
#define LEDPORT GPIOB //定义IO接口
#define LED1 GPIO_Pin_0 //定义IO接口
#define LED2 GPIO_Pin_1 //定义IO接口
void LED_Init(void);//初始化
#endif
1 条评论
不错不错,我喜欢看 https://www.ea55.com/