5921|14

57

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

我制作的会唱歌的STM32实验板 [复制链接]

可以用过PWM控制无源蜂鸣器唱歌:
此帖出自stm32/stm8论坛

最新回复

                                 那PWM怎么变声音出来,直接RC滤波?那失真,噪声不是很大?我试过WAV是可以读出来,可是做不到到声音的转换下面是我淘宝上的地址:http://auction1.taobao.com/auction/item_detail-0db1-b8d83af207f1916f6d6bfc886bd9f586.jhtml欢迎大家捧场哦   详情 回复 发表于 2008-10-24 11:36
点赞 关注
 

回复
举报

75

帖子

0

TA的资源

一粒金砂(初级)

沙发
 

这是使用说明书

                                  
此帖出自stm32/stm8论坛
 
 

回复

83

帖子

0

TA的资源

一粒金砂(初级)

板凳
 

主要程序

#include "Include.h"

//音调表
//C 262 
//D 294 
//E 330 
//F 349 
//G 392 
//A 440 
//B 494 
//C 523 
//D 587 
//E 659 
//F 698 
//G 784 
//A 880 
//B 988 
//C 1047 
//D 1175 
//E 1319 
//F 1397 
//G 1568 
//A 1760 
//B 1976 

//低音1~7
const unsigned int MusicDataD[7] = {61069,54422,48485,45845,40816,36364,32389};
//中音1~7
const unsigned int MusicData[7] = {30592,27257,24297,22922,20408,18182,16194};
//高音1~7
const unsigned int MusicDataG[7] = {15282,13617,12130,11453,10204,9091,8097};

//音乐数据格式:
//0x11~0x17 表示低音1~7
//0x21~0x27 表示中音1~7
//0x31~0x37 表示高音1~7
//0         表示静音
//每个音后面数据表示该音为多少个时间单位:1个16分音符定为1个时间单位

const unsigned char SuperStarData[] = //SuperStar S.H.E.
{
        0x22,4,0x22,2,0x23,2,0x21,4,0x15,2,0x15,2,
        0x22,2,0x21,2,0x22,2,0x23,2,0x21,4,0,2,0x23,2,
        0x24,2,0x23,2,0x21,2,0x21,1,0x22,1,0x22,4,0,2,0x23,2,
        0x24,2,0x23,2,0x21,2,0x21,2,0x21,2,0x22,1,0x21,1,0x17,4,
        0x22,2,0x22,2,0x22,2,0x23,2,0x21,4,0x15,2,0x15,2,
        0x22,2,0x21,2,0x22,2,0x23,2,0x21,4,0,2,0x23,2,
        0x24,2,0x23,2,0x21,2,0x21,1,0x22,1,0x22,4,0,2,0x23,2,
        0x24,2,0x23,2,0x24,2,0x25,2,0x25,4,0x15,2,0x16,2,
        
        0x21,4,0x22,2,0x23,2,0x25,4,0x23,2,0x25,2,
        0x26,2,0x27,2,0x26,2,0x25,2,0x23,4,0x22,2,0x23,2,
        0x25,2,0x23,2,0,2,0x23,2,0x22,2,0x23,2,0x22,2,0x21,2,
        0x15,8,0,4,0x15,2,0x16,2,
        0x21,4,0x22,2,0x23,2,0x25,4,0x23,2,0x25,2,
        0x26,2,0x27,2,0x26,2,0x25,2,0x23,4,0x22,2,0x23,2,
        0x25,2,0x23,2,0,2,0x23,2,0x22,2,0x23,2,0x22,2,0x21,2,
        //1
        0x15,16,
        0,32,
        
        0x22,4,0x22,2,0x23,2,0x21,4,0x15,2,0x15,2,
        0x22,2,0x21,2,0x22,2,0x23,2,0x21,4,0,2,0x23,2,
        0x24,2,0x23,2,0x21,2,0x21,1,0x22,1,0x22,4,0,2,0x23,2,
        0x24,2,0x23,2,0x21,2,0x21,2,0x21,2,0x22,1,0x21,1,0x17,4,
        0x22,2,0x22,2,0x22,2,0x23,2,0x21,4,0x15,2,0x15,2,
        0x22,2,0x21,2,0x22,2,0x23,2,0x21,4,0,2,0x23,2,
        0x24,2,0x23,2,0x21,2,0x21,1,0x22,1,0x22,4,0,2,0x23,2,
        0x24,2,0x23,2,0x24,2,0x25,2,0x25,4,0x15,2,0x16,2,
        0x21,4,0x22,2,0x23,2,0x25,4,0x23,2,0x25,2,
        0x26,2,0x27,2,0x26,2,0x25,2,0x23,4,0x22,2,0x23,2,
        0x25,2,0x23,2,0,2,0x23,2,0x22,2,0x23,2,0x22,2,0x21,2,
        0x15,8,0,4,0x15,2,0x16,2,
        0x21,4,0x22,2,0x23,2,0x25,4,0x23,2,0x25,2,
        0x26,2,0x27,2,0x26,2,0x25,2,0x23,4,0x22,2,0x23,2,
        0x25,2,0x23,2,0,2,0x23,2,0x22,2,0x23,2,0x22,2,0x21,2,

        //2
        0x15,16,
        0,4,0x26,2,0x25,6,0x22,2,0x23,10,0,8,
        0,4,0x26,2,0x25,6,0x22,2,0x23,4,0x24,2,0x23,1,0x22,1,0x21,1,0x21,9,
        0,4,0x26,2,0x25,6,0x27,2,0x27,6,0,2,0x27,2,0x31,4,0x27,2,0x26,2,
        0x26,4,0x22,2,0x23,2,0x21,4,0x15,2,0x15,2,
        0x22,2,0x21,2,0x22,2,0x23,2,0x21,4,0,2,0x23,2,
        0x24,2,0x23,2,0x21,2,0x22,2,0x22,4,0,2,0x23,2,

        0x24,2,0x23,2,0x21,2,0x21,2,0x21,2,0x22,1,0x21,1,0x17,4,
        0x22,2,0x22,2,0x22,2,0x23,2,0x21,4,0x15,2,0x15,2,
        0x22,2,0x21,2,0x22,2,0x23,2,0x21,4,0,2,0x23,2,
        0x24,2,0x23,2,0x21,2,0x22,2,0x22,4,0,2,0x23,2,
        0x24,2,0x23,2,0x24,2,0x25,2,0x25,20,0x15,2,0x16,2,

        0x21,4,0x22,2,0x23,2,0x25,4,0x23,2,0x25,2,
        0x26,2,0x27,2,0x26,2,0x25,2,0x23,4,0x22,2,0x23,2,
        0x25,2,0x23,2,0,2,0x23,2,0x22,2,0x23,2,0x22,2,0x21,2,
        0x15,8,0,4,0x15,2,0x16,2,
        0x21,4,0x22,2,0x23,2,0x25,4,0x23,2,0x25,2,
        0x26,2,0x27,2,0x26,2,0x25,2,0x23,4,0x22,2,0x23,2,
        0x25,2,0x23,2,0,2,0x23,2,0x22,2,0x23,2,0x22,2,0x21,2,
        0x15,12,0,4,
};

void SetBellF(unsigned int SetV)
{
        TIM_OCInitTypeDef TIM_OCInitStructure;
        TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;

        RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
        
        TIM_TimeBaseInitStructure.TIM_Period = SetV;
        TIM_TimeBaseInitStructure.TIM_Prescaler = 0;
        TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
        TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
        TIM_TimeBaseInit(TIM2,&TIM_TimeBaseInitStructure);

        TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
        TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
        TIM_OCInitStructure.TIM_Pulse = (SetV/2);
        TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
        TIM_OC2Init(TIM2, &TIM_OCInitStructure);
}


void Timer2Init(void)
{
        TIM_OCInitTypeDef TIM_OCInitStructure;
        TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;

        RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
        
        TIM_TimeBaseInitStructure.TIM_Period = 10000;
        TIM_TimeBaseInitStructure.TIM_Prescaler = 0;
        TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
        TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
        TIM_TimeBaseInit(TIM2,&TIM_TimeBaseInitStructure);

        TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
        TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
        TIM_OCInitStructure.TIM_Pulse = 5000;
        TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
        TIM_OC2Init(TIM2, &TIM_OCInitStructure);
}

void Timer2OutEnable(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;

        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
}

void Timer2OutDisable(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;

        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
}

void Timer2Start(void)
{
        TIM_Cmd(TIM2, ENABLE);
}

void Timer2Stop(void)
{
        TIM_Cmd(TIM2, DISABLE);
}

//播放歌曲
void PlayMusicFile(unsigned int DataNumber,unsigned char* p,unsigned char UnitTime)
{
        unsigned int i = 0;
        unsigned int PlayWord;

        for(i=0;i<DataNumber;i++)
        {
                switch (*p)
                {
                        case 0x11:
                                PlayWord = MusicDataD[0];
                                break;
                        case 0x12:
                                PlayWord = MusicDataD[1];
                                break;
                        case 0x13:
                                PlayWord = MusicDataD[2];
                                break;
                        case 0x14:
                                PlayWord = MusicDataD[3];
                                break;
                        case 0x15:
                                PlayWord = MusicDataD[4];
                                break;
                        case 0x16:
                                PlayWord = MusicDataD[5];
                                break;
                        case 0x17:
                                PlayWord = MusicDataD[6];
                                break;
                        case 0x21:
                                PlayWord = MusicData[0];
                                break;
                        case 0x22:
                                PlayWord = MusicData[1];
                                break;
                        case 0x23:
                                PlayWord = MusicData[2];
                                break;
                        case 0x24:
                                PlayWord = MusicData[3];
                                break;
                        case 0x25:
                                PlayWord = MusicData[4];
                                break;
                        case 0x26:
                                PlayWord = MusicData[5];
                                break;
                        case 0x27:
                                PlayWord = MusicData[6];
                                break;
                        case 0x31:
                                PlayWord = MusicDataG[0];
                                break;
                        case 0x32:
                                PlayWord = MusicDataG[1];
                                break;
                        case 0x33:
                                PlayWord = MusicDataG[2];
                                break;
                        case 0x34:
                                PlayWord = MusicDataG[3];
                                break;
                        case 0x35:
                                PlayWord = MusicDataG[4];
                                break;
                        case 0x36:
                                PlayWord = MusicDataG[5];
                                break;
                        case 0x37:
                                PlayWord = MusicDataG[6];
                                break;
                        default:
                                PlayWord = 0;//表示无声音
                                break;
                }
                p++;
                i++;
                if(PlayWord != 0)
                {
                        Timer2OutEnable();
                        SetBellF(PlayWord);
                }
                else
                {
                        Timer2OutDisable();
                }
                DelayNmS(UnitTime*(*p));
                p++;

        }
}

void Timer2Test(void)
{
        unsigned char i = 0;

        Timer2Start();

        while(1)
        {
                while(NO_KEY == GetKey());
                PlayMusicFile(sizeof(SuperStarData),(unsigned char*)SuperStarData,100);
                Timer2OutDisable();
        }

        //一句简单的歌曲
        while(0)
        {
                Timer2OutEnable();
                SetBellF(MusicData[0]);
                DelayNmS(400);
                SetBellF(MusicData[0]);
                DelayNmS(400);
                SetBellF(MusicData[4]);
                DelayNmS(400);
                SetBellF(MusicData[4]);
                DelayNmS(400);
                SetBellF(MusicData[5]);
                DelayNmS(400);
                SetBellF(MusicData[5]);
                DelayNmS(400);
                SetBellF(MusicData[4]);
                DelayNmS(400);
                DelayNmS(400);
                SetBellF(MusicData[3]);
                DelayNmS(400);
                SetBellF(MusicData[3]);
                DelayNmS(400);
                SetBellF(MusicData[2]);
                DelayNmS(400);
                SetBellF(MusicData[2]);
                DelayNmS(400);
                SetBellF(MusicData[1]);
                DelayNmS(400);
                SetBellF(MusicData[1]);
                DelayNmS(400);
                SetBellF(MusicData[0]);
                DelayNmS(400);
                DelayNmS(400);
                Timer2OutDisable();
                DelayNmS(1000);
        }

        //从C播放到B
        while(1)
        {
                SetBellF(MusicData);
                Timer2OutEnable();
                DelayNmS(200);
                i++;
                if(i>=7)
                {
                        i = 0;
                        Timer2OutDisable();
                        DelayNmS(2000);
                }
        }
}
此帖出自stm32/stm8论坛
 
 

回复

99

帖子

0

TA的资源

一粒金砂(初级)

4
 

卖的?

                                  
此帖出自stm32/stm8论坛
 
 
 

回复

70

帖子

0

TA的资源

一粒金砂(初级)

5
 

是的

希望用STM32的人更多点
STM32是好东西啊
此帖出自stm32/stm8论坛
 
 
 

回复

83

帖子

0

TA的资源

一粒金砂(初级)

6
 

我制作的会唱歌的STM32实验板

                                 顶
此帖出自stm32/stm8论坛
 
 
 

回复

84

帖子

0

TA的资源

一粒金砂(初级)

7
 

32位玩音频数据才合适吧?

这个,这个,好像用8位也可以吧,为啥要用32位?
32位要有32位应用的特点,MP3解码加数据流播放才是正题吧?
此帖出自stm32/stm8论坛
 
 
 

回复

70

帖子

0

TA的资源

一粒金砂(初级)

8
 

不错,不错,很好的东东

                                 顶
此帖出自stm32/stm8论坛
 
 
 

回复

70

帖子

0

TA的资源

一粒金砂(初级)

9
 

呵呵,玩还是可以

                                 要音质,这种搞法不行。不过学习学习还是不错的。
此帖出自stm32/stm8论坛
 
 
 

回复

73

帖子

0

TA的资源

一粒金砂(中级)

10
 

可以唱吉祥三宝吗?-嵌入式版的?歌词如下

嵌入式吉祥三宝

小女儿:  阿爸
爸爸:    哎
小女儿:  ARM公司就像那个谁呀?
爸爸  :  爸爸
小女儿:  KEIL公司又像那个谁呀?
爸爸  :  妈妈
小女儿:  那么MDK又是什么呀?
爸爸:    他们的孩子
合:      ARM KEIL MDK就是吉祥的一家
小女儿:  阿妈
妈妈:    哎
小女儿:  MDK有RealView编译器吗?
妈妈:    有啊
小女儿:  MDK有uVision3 IDE吗?
妈妈:    有啊
小女儿:  加起来不是很强大吗?
妈妈:    是啊
合:      ARM KEIL MDK就是如意的一家
爸爸妈妈:宝贝
小女儿:  啊
爸爸妈妈:你知道你支持Cortex-M3吗?
小女儿:  知道呀
爸爸妈妈:你知道你支持ARM7/9吗?
小女儿:  知道呀
爸爸妈妈:希望你能够快快地长大
小女儿:  呵呵呵
合:      我们三个就像吉祥如意的一家
此帖出自stm32/stm8论坛
 
 
 

回复

66

帖子

0

TA的资源

一粒金砂(初级)

11
 
 

回复

60

帖子

0

TA的资源

一粒金砂(初级)

12
 

哈哈,做得不错,这年头用STM32时髦+实用

                                  
此帖出自stm32/stm8论坛
 
 
 

回复

67

帖子

0

TA的资源

一粒金砂(初级)

13
 

哈哈 定位就是学习啦

                                 当然要放出mp3的声音是不可能啦
此帖出自stm32/stm8论坛
 
 
 

回复

83

帖子

0

TA的资源

一粒金砂(中级)

14
 

放出mp3的声音怎么不可能呀

用它的PWM完全可以做出播放WAV的声音呀,如果是带有IIS总线的那就更不用说了,,IIS不就是专门的语音的总线吗,,LS说的应该就是普通的声音吧,WAV的音质比MP3的要好呀,,,,如果真正做MP3解码是挺难的,
此帖出自stm32/stm8论坛
 
 
 

回复

81

帖子

0

TA的资源

一粒金砂(初级)

15
 

请教楼上

那PWM怎么变声音出来,直接RC滤波?那失真,噪声不是很大?
我试过WAV是可以读出来,可是做不到到声音的转换

下面是我淘宝上的地址:
http://auction1.taobao.com/auction/item_detail-0db1-b8d83af207f1916f6d6bfc886bd9f586.jhtml

欢迎大家捧场哦
此帖出自stm32/stm8论坛
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/7 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表