基于单片机的音乐发声器

单片机音乐发声器

单片机音乐发声器

摘 要

近年来随着科技的飞速发展,单片机的应用正在不断地走向深入,同时带动传统控制检测日新月异更新。在实时检测和自动控制的单片机应用系统中,单片机往往是作为一个核心部件来使用,仅单片机方面知识是不够的,还应根据具体硬件结构,以及针对具体应用对象特点的软件结合,加以完善。

现当今,利用单片机控制音乐播放多不胜举.音乐芯片也相当之多,而利用单片机存储音乐,控制播放最为广泛.它有功能多﹑价格优﹑外围电路简单的特点,很受音乐爱好者及音乐芯片制造商的青昧.本文中,用单片机芯片及少数外围电路控制音乐播放。

对于单片机产生音乐,关键是控制频率的输出.我们知道,不同的声音对应不同的频率,产生有规律的频率输出就可以得到相应规律的声音.有8个基本音符:do﹑re﹑mi﹑fa﹑so﹑la﹑xi﹑do,八个不同的音符对应着不同的频率.只要我们对照音符输出相对应的频率,就可以产生美妙的音乐.本文中采用了T0中断方式产生不同频率, 并用按键控制音乐的播放和停止。用三极管、电阻等组成的放大电路驱动扬声器。

关键词 单片机/音乐/按键/频率

I

单片机音乐发声器

ABSTRACT

In recent years along with science and technology develop fast, the application of single flat machine is moving towards thorough continuously, at the same time drive traditional control detection day the benefit of new moon update. In the only flat machine application system of the automatic control and detection of real time, only flat machine is often to use as a key parts, only single flat machine aspect knowledge is insufficient ,

return should basis specificly hardware structure, as well as aim at the software that applies object characteristic specificly combination, perfect.

Now, music playing is a lots which micro chip control. The music chip is very much. But it is at best to apply the micro chip.It has the characteristic which function is much and price is a little and out’s circuit is a few.So it is used by people who like music and

manufacture the music chip.This chapter,using micro chip and a few out circuit control the playing of music,and give birth to music of happy birthday, withing lampion swichover working.Music and light have synchronous effect.

For the micro chip giving birth to music,the importance is controlling output of frequence.the output of frequence which has rule can gain music that rule accordingly.Have eight basic music’s bits:do,re,mi,fa,so,la,xi,do,eight basic bits have different frequence.So if we output frequence of music basic bit accordingly,music can gain accordingly too.The output of frequence used method of T0 stopping in this

chapter,and two keypress control playing and stop.

We control music by micro chip,the keypress control playing,and control speaker by in-phase blowing up method of counting blowing up.

KEY WORDS single flat machine ,music ,keypress,frequency

2

单片机音乐发声器

1 绪 论 ...............................................1 2 单片机概述...........................................2 3 硬件设计.............................................3 3.1 芯片简介........................................3 3.2 引脚说明........................................4 3.3 主要电路设计....................................7

3.3.1 时钟电路.........................................8

3.3.2 复位电路.........................................8

3.4 电路图的设计 ....................................8 4 软件设计.............................................10

4.1 程序流程图......................................10

4.2 程序............................................11 4.3 定时器的初始化设置..............................14 4.4 音乐发声器发音原理..............................15 5 焊接及调试...........................................16 5.1 焊接...........................................16 5.2 调试............................................16

5.2.1硬件调试..........................................17 5.2.2软件调试..........................................17 5.2.3软硬联调..........................................17

结束语.................................................18 致谢...................................................19

3

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4