当前位置:文档之家› computer science and technology (network) professional

computer science and technology (network) professional

computer science and technology (network) professional
computer science and technology (network) professional

。单片机课程设计

This course design

课程设计题目:数字音乐盒

Course design topic: digital music box

课程设计组:计算机科学与技术(网络方向)专业

Course design: computer science and technology (network) professional direction 0601班第1组

0601 class group 1

课程设计组成员:吉彩霞(2006100102)

Course design JiCaiXia (2006100102) members:

李磊(2006100116)

Li lei (2006100116)

肖海燕(2006100126)

XiaoHaiYan (2006100126)

王臻(2006100138)

Wang zhen (2006100138)

2009年11月2009 November

数字音乐盒

Digital music box

摘要:本文是应用AT89S51单片机原理和控制理论来设计音乐盒的硬件电路,并利用C51单片机语言进行程序设计。通过控制单片机内部的定时器来产生不同频率的方波,驱动喇叭发出不同音调的音乐,再利用延迟来控制发音时间的长短。该程序通过把乐谱转化成相应的定时常数来驱动发音设备演奏出悦耳动听的音乐。这种控制电路结构简单,可靠性高,应用性强;软件程序适应范围广,对于不同的音乐只需要改变相应的定时常数即可。对单片机和音乐爱好者有一定的借鉴价值。

Abstract: this paper is the application of AT89S51 principle and control theory to music box hardware circuit design, and using C51 microcontroller programming language. Through controlling the microcontroller timer to generate the internal of different frequency square-wave, drive horn sends out the different music, tones of reusing delay to control the pronunciation time length. The program through my music into the corresponding timing constants to drive the pronunciation equipment play an euphonic beautiful music. This kind of control circuit of simple structure, high reliability and applicability is strong; Software programs adapt range, for different music only need to change the corresponding timing constants can. The SCM and music enthusiasts is of certain reference value.

关键词:AT89C51单片机音乐盒 C51语言

Keywords: AT89C51 music box C51 language

一、方案的设计与论证

First, the design with argument

1.方案设计

Scheme design. 1.

方案1:

Plan 1:

用四个按键控制音乐的播放。3个按键选择3首不同的音乐播放,另一个按键控制音乐的停止。按下播放键,用一点简单的控制之后,才开始播放音乐。比如,用定时器控制,亮灯倒计时10秒然后触发音乐播放。

With four key control music playback. Three key choice 3 different songs music playback, another button control music stops. Press the play button, with a few simple

control later, just start playing music. For instance, with lights countdown timer control, 10 seconds and then trigger music playback.

方案2:

Plan 2:

用4*4小键盘来实现音乐的选择播放,1~A按键控制播放10首音乐,C~F按键分别实现欢迎页面、上一首、下一首、停止播放。

Use 4 * 4 small keyboards to achieve music selection playback, 1 ~ A button control play music, C ~ 10 tracks F buttons realized respectively welcome pages, on A, the following piece, stop playing.

方案3:

Plan 3:

为了充分利用实验板的功能,进一步扩充音乐盒的功能。设计开机时用七段显示数码管LED 显示英文欢迎提示字符HELLO,播放时显示歌曲序号。一个按键控制播放音乐,按下一次按键播放一首歌曲,另外三个按键分别实现上一首、下一首、暂停。考虑到实验的复杂度和时间上的局限,不再使用亮灯倒计时10秒才出发播放的构思。使用方案三。

In order to make full use of the function of experimental board, further expand the function of music box. Design is powered with seven segment display digital tube LED display English welcome hint characters, broadcasting displayed when songs HELLO serial number. A button control play music, press the next key play a song, another three buttons realized respectively on a poem, pause,. Considering the experimental complexity and time limit, no longer use bright lights countdown to 10 seconds to start broadcast conception. Use plan 3.

2.方案论证

2. Plan demonst

1) 在方案1中,共用了4个按键,其中3个按键控制播放3首音乐,另一个键控制音乐播放的停止。但是我们却只能选择3首音乐,局限性太强了。

1) on the plan 1, share four buttons, three of which button control broadcast three first music, another key control music broadcast stop. But we are only choose 3 first music, limitations is too strong.

2) 在方案2中,由于个人所学知识有限、实践经验太少等原因,我们仅实现了歌曲的播放、开机画面、停止,未能实现歌曲的上一首、下一首选择播放。由于

2) in solution 2, due to personal knowledge learnt limited, practical experience too little and other reasons, we can only achieve songs play, boot screen, stop, failed to achieve songs, a choice on a play. because

二、单片机控制电路的设计

Second, a single chip microcomputer control circuit design

本设计中用到了89C51单片机,4*4键盘,蜂鸣器,16*2 LCD,七段显示数码管LED。

This design using the 89C51, 4 * 4 keyboard, buzzer, 16 * 2 LCD display, seven segment digital tube LED.

当键盘有键按下时,判断键值,启动计数器T0,产生一定频率的脉冲,驱动蜂鸣器,放出乐曲。同时启动定时器T1,显示乐曲播放的时间,并驱动LCD,显示歌曲号及播放时间。也可在LED显示歌曲号。

When the keyboard have keys when pressed, judge keys, start-up counter T0, produce a certain frequency pulse, drive the buzzer and released music. At the same time, show start timer T1 music broadcast time and drive LCD, display songs number and broadcast time. Also available in LED display songs number.

(1)硬件电路中用P1.0~P1.7控制按键,其中P1.0~P1.3扫描行,P1.4~P1.7扫描列。

(1) hardware circuit with P1.0 ~ P1.7 control key, which P1.0 ~ P1.3 scan line, P1.4 ~ P1.7 scanning columns.

(2)用P0.0~P0.7,P2.0~P2.7控制LED,其中P0.0~P0.7控制七段码a,b,c,d,e,f,g,用P2.0~P2.7为数码管位选信号。

(2) using P0.0 ~ P0.7, P2.0 ~ P2.7 control, which LED P0.0 ~ P0.7 control seven bit code a, b, c, d, e, f, g, and with P2.0 ~ P2.7 for digital tube bits choose signal.

(3)用,P2.0~P2.2作为LCD的RS,R/W,E的控制信号。用P0.0~P0.7作为LCD的D0~D7的控制信号。

(3) use, P2.0 ~ P2.2 as LCD of RS, R/W, E control signals. With the P0.0 ~ P0.7 as LCD D0 ~ D7 control signals.

(4)用P3.7口控制蜂鸣器。

(4) with P3.7 mouth control sounders.

(5)电路为12MHZ晶振频率工作,起振电路中C1,C2均为30pf。

(5) circuit for 12MHZ crystal frequency work, initial circuits are 30pf C1, C2.

三、软件实现

Third, software realization

音乐产生的方法:

Music produced methods:

一首音乐是许多不同的音阶组成的,而每个音阶对应着不同的频率,这样我们就可以利用不同的频率的组合,即可构成我们所想要的音乐了,当然对于单片机来产生不同的频率非常方便,我们可以利用单片机的定时/计数器T0来产生这样方波频率信号,因此,我们只要把一首歌曲的音阶对应频率关系弄正确即可。现在以单片机12MHZ晶振为例,例出高中低音符与单片机计数T0相关的计数值如下表4.1所示:

A music is composed of many different scales, and each octave corresponds to different frequency, so we can make use of different frequency combination, can constitute what we want the music, of course, for a singleship produce different frequency is very convenient, and we can of the microcontroller timer/counter to produce such T0 square wave frequency signals, therefore, we just need to get song the octave corresponding frequency relations correctly can get. Now 12MHZ on single crystals, for example, many notes and MCU example out T0 relevant count value counting the list below 4.1 shows:

表4.1 高中低音符与单片机计数T0相关的计数值

Many notes and MCU table 4.1 T0 relevant count value count

音符频率(HZ)简谱码(T值)音符频率(HZ)简谱码(T值)

Note the frequency (HZ) chords yards (T) values notes frequency (HZ) chords yards (T) values

低1 DO 262 63628 # 4 FA# 740 64860

Low 1 DO 63628 # 4 262 FA# 7.4 64860

#1 DO# 277 63731 中 5 SO 784 64898

The # 1 in 5 DO# 277 63731 SO 64898 784 低2 RE 294 63835 # 5 SO# 831 64934

Low 2 RE 294 63835 # 5 SO# 831 64934

#2 RE# 311 63928 中 6 LA 880 64968

# 2 RE# 311 63928 in six 64968 LA 880 低 3 M 330 64021 # 6 932 64994

Low 3 M 330 64021 # 6 932 64994

低 4 FA 349 64103 中 7 SI 988 65030

Low 4 FA 349 64103 7 of SI 65030 988

# 4 FA# 370 64185 高 1 DO 1046 65058

# 4 FA# 370 64185 high 1 DO 65058 1046 低 5 SO 392 64260 # 1 DO# 1109 65085 Low 5 SO 64260 # 1 DO# 1109 392 65085 # 5 SO# 415 64331 高 2 RE 1175 65110

# 5 SO# 415 64331 tall 2 RE 65110 1175 低 6 LA 440 64400 # 2 RE# 1245 65134 Low 6 LA 440 64400 # 2 65134 RE# 1245 # 6 466 64463 高 3 M 1318 65157

# 6 466 64463 high 3 M 65157 1318

低 7 SI 494 64524 高 4 FA 1397 65178 Low 7 SI 494 64524 high 4 FA 65178 1397

中 1 DO 523 64580 # 4 FA# 1480 65198

One of 64580 # 4 DO 523 FA# 1480 65198

# 1 DO# 554 64633 高 5 SO 1568 65217

The # 1 DO# 554 64633 high 5 SO 65217 1568

中 2 RE 587 64684 # 5 SO# 1661 65235

2 RE 64684 # 5 SO# 587 1661 65235

# 2 RE# 622 64732 高 6 LA 1760 65252

# 2 RE# 622 64732 height 6 1760 65252 LA

中 3 M 659 64777 # 6 1865 65268

In 3 M 659 64777 # 6 65268 1865

中 4 FA 698 64820 高 7 SI 1967 65283

4 FA 698 64820 high 7 SI 65283 1967

如表4.2所示:音乐的音拍,一个节拍为单位(C调)

As the chart 4.2 music sound shown: clap, a beat for units (C key 表4.2 音乐的音拍

Watch music sound pat. 4.2

曲调值 DELAY 曲调值 DELAY

Tune value tow vehicle tune value tow vehicle

调4/4 125ms 调4/4 62ms

Adjustable 4/4 125ms adjustable 4/4 62ms

调3/4 187ms 调3/4 94ms

Adjustable 3/4 187ms adjustable 3/4 94ms

调2/4 250ms 调2/4 125ms

Adjustable 2/4 250ms adjustable 2/4 125ms

对于不同的曲调我们也可以用单片机的另外一个定时/计数器来完成。发音部分代码在程序中实现,靠单片机的一个管脚输出,考虑到声音可能不够大所以我们加入了功放电路,利用LM386来对声音信号进行放大。音频输出信号由ADU OUT引出,信号可经功放电路LM386输出到扬声器或耳机。电路如图4-1所示。

For different tunes we can also use the MCU another timing/counter to complete. Pronunciation parts in the program code realization, a tube feet by SCM outputs, considering the voice may not big enough so we joined the amplifier circuit, using LM386 to amplify sound signal. Audio output signal by ADU OUT derivation, signal by amplifier circuit LM386 output to speakers or headphones. Circuit as shown in figure 4-1 shows.

图1-6放音电路

Figure 1-6 playback circuit

流程图如图1-7所示:

Flow chart is shown in figure 1-7 shows:

图1-7流程图

Figure 1-7 flowchart

四、测试结果

Four, testing results

1.使用说明:

Instructions: 1.

键盘如下:

The keyboard is as follows:

K1 K2 K3 K4

K1 K2 ultrachrome K3 K4

按键功能说明如下:

Keys function that is as follows:

K1:开始,显示HELLO欢迎画面

K1: beginning, display HELLO welcome screen

K2:结束,停止播放,并且LED左右来回移动

K2: the end, to stop broadcasting, and LED around move around K3:下一首歌曲(共有6首歌曲)

Ultrachrome K3: next song (six songs)

K4:上一首歌曲

K4: on song

2.程序调试中出现的问题及解决的办法:

2. Program test of the problems and solution:

1) 有时会出现程序一点错误也没有,但就是不能正常运行的现象,最后我们发行是因为程序中有的指令书写得不规范导致的。

1) can appear sometimes program little mistake also have no, but is not the normal operation of the phenomenon, finally we issue because some instructions well written program is not standard lead.

2) 编程时要注意,在程序开始时,要写入各定时器中断的入口地址。

2) when programming to note, that the program starts when, want to write each timer interrupt entry address.

3) 编程过程中要注意加注释或分割线,否则,在程序过长时容易变得很乱,不便于查找或更改。

3) the programming process should pay attention to add comments or rules, otherwise, the program is too long easily when become very disorderly, not easy reference or updates.

4) 程序的结构要设计的合理,避免上下乱调用的现象,这样会使程序更加清晰化。

4) program structure to design the reasonable, avoid fluctuation disorderly invoked the phenomenon, this would make more biaxial streching program.

5) 编程前要加流程图,这样会使思路清晰,例如数字音乐盒的设计思路完全可以按着MP3的工作方式列写流程图。

5) programming flowchart before to add, such meetings make clear thinking, such as digital music box design ideas can completely according to MP3 way of working column write flowchart.

6) LCD计时正常显示的解决办法:

6) LCD timer display properly solution:

a. 两个定时器同时工作,存在中断时序问题,刚开始时我们把定时器1设定在方式3,计250us,

由于定时中断过于频繁,使CPU负载过大,导致音乐不能正常播放,时间不能正常显示。解决办法:将定时器1设定在工作方式1,16位计数,计50ms,效果有很大改观。但还有问题。

A. two timers working at the same time, there exists interrupt timing problems, just start when we put the timer 1 set in the way, 250us, because three project timing interrupt too frequent, make excessive, causing music CPU load cannot normally broadcast, time can't display properly. Solution: will the timer set in working way 1 Tony bits count, plan, the effect is very 50ms change. But there is a problem.

b. 当音乐为全4拍起始时,此时音乐节奏与定时器T1中断频率错开,LCD显示和音乐播放都会好一些。

B. when music for whole 4 shoot, starting at music rhythm and timer T1 interrupt frequency stagger, LCD display and music play will be better.

c. 另外,在歌曲中,当遇到一个音符发音为4拍,在编曲中为*CH,托因时间较长,当定时器T1此时来中断时,就会对歌曲播放产生影响,若改为发音一拍,中断对歌曲播放影响减弱,但音乐效果变差。

C. besides, in the song, when facing a pronunciation notes for 4 shoot, in vocal for * CH, torre for over a long period of time, when the timer T1 at this time to interrupt, will influence of songs played, if the following pronunciation clap, interruption to songs played influence is abate, but music effect becomes poor.

d. 改进方案:若采用可以定时时间更长的单片机,可以避免所有问题。

D. improvement scheme: if you use to regular time longer microcontroller, can avoid all problems.

五、总结

Five, summarizes

本文通过对基于单片机音乐演奏控制设计的研究和设计,分析了设计的实现的意义和可行性。单片机AT889S51是一种非常小巧但功能非常多,应用非常广的一种芯片,功率也非常的小,采用AT89S51作为系统核心制作音乐演奏控制设计电路简单了很多,由于可以反复烧写,为学习降低成本。本设计外部采用单片机的复位电路设计、单片机的震荡电路设计、LED数码管显示正在播放的音乐序号,按键控制等,但由于AT89S51分辨率不是太高,音乐有点单调,另外,由于时间关系具体电路还有的地方不尽完善之处。

This article through to play music based on single-chip microcomputer control design of research and design, the realization of the design is analyzed the meaning and feasibility. SCM AT889S51 is a kind of very small but functions very much, very wide application of a chip, power is also very little, using AT89S51 as core making music playing system control circuit design a lot simpler, can relapse burning, because for learning to reduce costs. This design external use of MCU reset circuit design, a single chip microcomputer shocks of circuit design, LED digital display tube being played music, serial Numbers, button control etc, but because AT89S51 resolution does not too much, music is a bit dull, moreover, due to the time relationship specific circuit and place imperfect place.

六、参考文献

6 and references

[18]杨欣.电路设计与仿真.北京:清华大学出版社,2006

[18] YangXin. Circuit design and simulation. Beijing: tsinghua university press, 2006

七、附录

Seven, appendix

中文 ? 英语<~ 复制

单片机课程设计

This course design

课程设计题目:数字音乐盒

Course design topic: digital music box

课程设计组:计算机科学与技术(网络方向)专业

Course design: computer science and technology (network) professional direction 0601班第1组

0601 class group 1

课程设计组成员:吉彩霞(2006100102)

Course design JiCaiXia (2006100102) members:

李磊(2006100116)

Li lei (2006100116)

肖海燕(2006100126)

XiaoHaiYan (2006100126)

王臻(2006100138)

Wang zhen (2006100138)

2009年11月

2009 November

数字音乐盒

Digital music box

摘要:本文是应用AT89S51单片机原理和控制理论来设计音乐盒的硬件电路,并利用C51单片机语言进行程序设计。通过控制单片机内部的定时器来产生不同频率的方波,驱动喇叭发出不同音调的音乐,再利用延迟来控制发音时间的长短。该程序通过把乐谱转化成相应的定时常数来驱动发音设备演奏出悦耳动听的音乐。这种控制电路结构简单,可靠性高,应用性强;软件程序适应范围广,对于不同的音乐只需要改变相应的定时常数即可。对单片机和音乐爱好者有一定的借鉴价值。

Abstract: this paper is the application of AT89S51 principle and control theory to music box hardware circuit design, and using C51 microcontroller programming language. Through controlling the microcontroller timer to generate the internal of different frequency square-wave, drive horn sends out the different music, tones of reusing delay to control the pronunciation time length. The program through my music into the corresponding timing constants to drive the pronunciation equipment play an euphonic beautiful music. This kind of control circuit of simple structure, high reliability and applicability is strong; Software programs adapt range, for different music only need to change the corresponding timing constants can. The SCM and music enthusiasts is of certain reference value.

关键词:AT89C51单片机音乐盒 C51语言

Keywords: AT89C51 music box C51 language

一、方案的设计与论证

First, the design with argument

1.方案设计

Scheme design. 1.

方案1:

Plan 1:

用四个按键控制音乐的播放。3个按键选择3首不同的音乐播放,另一个按键控制音乐的停止。按下播放键,用一点简单的控制之后,才开始播放音乐。比如,用定时器控制,亮灯倒计时10秒然后触发音乐播放。

With four key control music playback. Three key choice 3 different songs music playback, another button control music stops. Press the play button, with a few simple control later, just start playing music. For instance, with lights countdown timer control, 10 seconds and then trigger music playback.

方案2:

Plan 2:

用4*4小键盘来实现音乐的选择播放,1~A按键控制播放10首音乐,C~F按键分别实现欢迎页面、上一首、下一首、停止播放。

Use 4 * 4 small keyboards to achieve music selection playback, 1 ~ A button control play music, C ~ 10 tracks F buttons realized respectively welcome pages, on A, the following piece, stop playing.

方案3:

Plan 3:

为了充分利用实验板的功能,进一步扩充音乐盒的功能。设计开机时用七段显示数码管LED 显示英文欢迎提示字符HELLO,播放时显示歌曲序号。一个按键控制播放音乐,按下一次按键播放一首歌曲,另外三个按键分别实现上一首、下一首、暂停。考虑到实验的复杂度和时

间上的局限,不再使用亮灯倒计时10秒才出发播放的构思。使用方案三。

In order to make full use of the function of experimental board, further expand the function of music box. Design is powered with seven segment display digital tube LED display English welcome hint characters, broadcasting displayed when songs HELLO serial number. A button control play music, press the next key play a song, another three buttons realized respectively on a poem, pause,. Considering the experimental complexity and time limit, no longer use bright lights countdown to 10 seconds to start broadcast conception. Use plan 3.

2.方案论证

2. Plan demonst

1) 在方案1中,共用了4个按键,其中3个按键控制播放3首音乐,另一个键控制音乐播放的停止。但是我们却只能选择3首音乐,局限性太强了。

1) on the plan 1, share four buttons, three of which button control broadcast three first music, another key control music broadcast stop. But we are only choose 3 first music, limitations is too strong.

2) 在方案2中,由于个人所学知识有限、实践经验太少等原因,我们仅实现了歌曲的播放、开机画面、停止,未能实现歌曲的上一首、下一首选择播放。由于

2) in solution 2, due to personal knowledge learnt limited, practical experience too little and other reasons, we can only achieve songs play, boot screen, stop, failed to achieve songs, a choice on a play. because

二、单片机控制电路的设计

Second, a single chip microcomputer control circuit design

本设计中用到了89C51单片机,4*4键盘,蜂鸣器,16*2 LCD,七段显示数码管LED。

This design using the 89C51, 4 * 4 keyboard, buzzer, 16 * 2 LCD display, seven segment digital tube LED.

当键盘有键按下时,判断键值,启动计数器T0,产生一定频率的脉冲,驱动蜂鸣器,放出乐曲。同时启动定时器T1,显示乐曲播放的时间,并驱动LCD,显示歌曲号及播放时间。也可在LED显示歌曲号。

When the keyboard have keys when pressed, judge keys, start-up counter T0, produce a certain frequency pulse, drive the buzzer and released music. At the same time, show start timer T1 music broadcast time and drive LCD, display songs number and broadcast time. Also available in LED display songs number.

(1)硬件电路中用P1.0~P1.7控制按键,其中P1.0~P1.3扫描行,P1.4~P1.7扫描列。(1) hardware circuit with P1.0 ~ P1.7 control key, which P1.0 ~ P1.3 scan line, P1.4 ~ P1.7 scanning columns.

(2)用P0.0~P0.7,P2.0~P2.7控制LED,其中P0.0~P0.7控制七段码a,b,c,d,e,f,g,用P2.0~P2.7为数码管位选信号。

(2) using P0.0 ~ P0.7, P2.0 ~ P2.7 control, which LED P0.0 ~ P0.7 control seven bit code a, b, c, d, e, f, g, and with P2.0 ~ P2.7 for digital tube bits choose signal. (3)用,P2.0~P2.2作为LCD的RS,R/W,E的控制信号。用P0.0~P0.7作为LCD的D0~D7的控制信号。

(3) use, P2.0 ~ P2.2 as LCD of RS, R/W, E control signals. With the P0.0 ~ P0.7 as LCD D0 ~ D7 control signals.

(4)用P3.7口控制蜂鸣器。

(4) with P3.7 mouth control sounders.

(5)电路为12MHZ晶振频率工作,起振电路中C1,C2均为30pf。

(5) circuit for 12MHZ crystal frequency work, initial circuits are 30pf C1, C2.

三、软件实现

Third, software realization

音乐产生的方法:

Music produced methods:

一首音乐是许多不同的音阶组成的,而每个音阶对应着不同的频率,这样我们就可以利用不同的频率的组合,即可构成我们所想要的音乐了,当然对于单片机来产生不同的频率非常方便,我们可以利用单片机的定时/计数器T0来产生这样方波频率信号,因此,我们只要把一首歌曲的音阶对应频率关系弄正确即可。现在以单片机12MHZ晶振为例,例出高中低音符与单片机计数T0相关的计数值如下表4.1所示:

A music is composed of many different scales, and each octave corresponds to different frequency, so we can make use of different frequency combination, can constitute what we want the music, of course, for a singleship produce different frequency is very convenient, and we can of the microcontroller timer/counter to produce such T0 square wave frequency signals, therefore, we just need to get song the octave corresponding frequency relations correctly can get. Now 12MHZ on single crystals, for example, many notes and MCU example out T0 relevant count value counting the list below 4.1 shows:

表4.1 高中低音符与单片机计数T0相关的计数值

Many notes and MCU table 4.1 T0 relevant count value count

音符频率(HZ)简谱码(T值)音符频率(HZ)简谱码(T值)

Note the frequency (HZ) chords yards (T) values notes frequency (HZ) chords yards (T) values

低1 DO 262 63628 # 4 FA# 740 64860

Low 1 DO 63628 # 4 262 FA# 7.4 64860

#1 DO# 277 63731 中 5 SO 784 64898

The # 1 in 5 DO# 277 63731 SO 64898 784

低2 RE 294 63835 # 5 SO# 831 64934

Low 2 RE 294 63835 # 5 SO# 831 64934

#2 RE# 311 63928 中 6 LA 880 64968

# 2 RE# 311 63928 in six 64968 LA 880

低 3 M 330 64021 # 6 932 64994

Low 3 M 330 64021 # 6 932 64994

低 4 FA 349 64103 中 7 SI 988 65030

Low 4 FA 349 64103 7 of SI 65030 988

# 4 FA# 370 64185 高 1 DO 1046 65058

# 4 FA# 370 64185 high 1 DO 65058 1046

低 5 SO 392 64260 # 1 DO# 1109 65085

Low 5 SO 64260 # 1 DO# 1109 392 65085

# 5 SO# 415 64331 高 2 RE 1175 65110

# 5 SO# 415 64331 tall 2 RE 65110 1175

低 6 LA 440 64400 # 2 RE# 1245 65134

Low 6 LA 440 64400 # 2 65134 RE# 1245

# 6 466 64463 高 3 M 1318 65157

# 6 466 64463 high 3 M 65157 1318

低 7 SI 494 64524 高 4 FA 1397 65178

Low 7 SI 494 64524 high 4 FA 65178 1397

中 1 DO 523 64580 # 4 FA# 1480 65198

One of 64580 # 4 DO 523 FA# 1480 65198

# 1 DO# 554 64633 高 5 SO 1568 65217

The # 1 DO# 554 64633 high 5 SO 65217 1568

中 2 RE 587 64684 # 5 SO# 1661 65235

2 RE 64684 # 5 SO# 587 1661 65235

# 2 RE# 622 64732 高 6 LA 1760 65252

# 2 RE# 622 64732 height 6 1760 65252 LA

中 3 M 659 64777 # 6 1865 65268

In 3 M 659 64777 # 6 65268 1865

中 4 FA 698 64820 高 7 SI 1967 65283

4 FA 698 64820 high 7 SI 65283 1967

如表4.2所示:音乐的音拍,一个节拍为单位(C调)

As the chart 4.2 music sound shown: clap, a beat for units (C key

表4.2 音乐的音拍

Watch music sound pat. 4.2

曲调值 DELAY 曲调值 DELAY

Tune value tow vehicle tune value tow vehicle

调4/4 125ms 调4/4 62ms

Adjustable 4/4 125ms adjustable 4/4 62ms

调3/4 187ms 调3/4 94ms

Adjustable 3/4 187ms adjustable 3/4 94ms

调2/4 250ms 调2/4 125ms

Adjustable 2/4 250ms adjustable 2/4 125ms

对于不同的曲调我们也可以用单片机的另外一个定时/计数器来完成。发音部分代码在程序中实现,靠单片机的一个管脚输出,考虑到声音可能不够大所以我们加入了功放电路,利用LM386来对声音信号进行放大。音频输出信号由ADU OUT引出,信号可经功放电路LM386输出到扬声器或耳机。电路如图4-1所示。

For different tunes we can also use the MCU another timing/counter to complete. Pronunciation parts in the program code realization, a tube feet by SCM outputs, considering the voice may not big enough so we joined the amplifier circuit, using LM386 to amplify sound signal. Audio output signal by ADU OUT derivation, signal by amplifier circuit LM386 output to speakers or headphones. Circuit as shown in figure 4-1 shows.

图1-6放音电路

Figure 1-6 playback circuit

流程图如图1-7所示:

Flow chart is shown in figure 1-7 shows:

图1-7流程图

Figure 1-7 flowchart

四、测试结果

Four, testing results

1.使用说明:

Instructions: 1.

键盘如下:

The keyboard is as follows:

K1 K2 K3 K4

K1 K2 ultrachrome K3 K4

按键功能说明如下:

Keys function that is as follows:

K1:开始,显示HELLO欢迎画面

K1: beginning, display HELLO welcome screen

K2:结束,停止播放,并且LED左右来回移动

K2: the end, to stop broadcasting, and LED around move around

K3:下一首歌曲(共有6首歌曲)

Ultrachrome K3: next song (six songs)

K4:上一首歌曲

K4: on song

2.程序调试中出现的问题及解决的办法:

2. Program test of the problems and solution:

1) 有时会出现程序一点错误也没有,但就是不能正常运行的现象,最后我们发行是因为程序中有的指令书写得不规范导致的。

1) can appear sometimes program little mistake also have no, but is not the normal operation of the phenomenon, finally we issue because some instructions well written program is not standard lead.

2) 编程时要注意,在程序开始时,要写入各定时器中断的入口地址。

2) when programming to note, that the program starts when, want to write each timer interrupt entry address.

3) 编程过程中要注意加注释或分割线,否则,在程序过长时容易变得很乱,不便于查找或更改。

3) the programming process should pay attention to add comments or rules, otherwise, the program is too long easily when become very disorderly, not easy reference or updates.

4) 程序的结构要设计的合理,避免上下乱调用的现象,这样会使程序更加清晰化。

4) program structure to design the reasonable, avoid fluctuation disorderly invoked the phenomenon, this would make more biaxial streching program.

5) 编程前要加流程图,这样会使思路清晰,例如数字音乐盒的设计思路完全可以按着MP3的工作方式列写流程图。

5) programming flowchart before to add, such meetings make clear thinking, such as digital music box design ideas can completely according to MP3 way of working column write flowchart.

6) LCD计时正常显示的解决办法:

6) LCD timer display properly solution:

a. 两个定时器同时工作,存在中断时序问题,刚开始时我们把定时器1设定在方式3,计250us,由于定时中断过于频繁,使CPU负载过大,导致音乐不能正常播放,时间不能正常显示。解决办法:将定时器1设定在工作方式1,16位计数,计50ms,效果有很大改观。但还有问题。A. two timers working at the same time, there exists interrupt timing problems, just start when we put the timer 1 set in the way, 250us, because three project timing interrupt too frequent, make excessive, causing music CPU load cannot normally broadcast, time can't display properly. Solution: will the timer set in working way

1 Tony bits count, plan, the effect is very 50ms change. But there is a problem.

b. 当音乐为全4拍起始时,此时音乐节奏与定时器T1中断频率错开,LCD显示和音乐播放都会好一些。

B. when music for whole 4 shoot, starting at music rhythm and timer T1 interrupt frequency stagger, LCD display and music play will be better.

c. 另外,在歌曲中,当遇到一个音符发音为4拍,在编曲中为*CH,托因时间较长,当定时器T1此时来中断时,就会对歌曲播放产生影响,若改为发音一拍,中断对歌曲播放影响减弱,但音乐效果变差。

C. besides, in the song, when facing a pronunciation notes for 4 shoot, in vocal for * CH, torre for over a long period of time, when the timer T1 at this time to interrupt, will influence of songs played, if the following pronunciation clap, interruption to songs played influence is abate, but music effect becomes poor.

d. 改进方案:若采用可以定时时间更长的单片机,可以避免所有问题。

D. improvement scheme: if you use to regular time longer microcontroller, can avoid all problems.

五、总结

Five, summarizes

本文通过对基于单片机音乐演奏控制设计的研究和设计,分析了设计的实现的意义和可行性。单片机AT889S51是一种非常小巧但功能非常多,应用非常广的一种芯片,功率也非常的小,采用AT89S51作为系统核心制作音乐演奏控制设计电路简单了很多,由于可以反复烧写,为学习降低成本。本设计外部采用单片机的复位电路设计、单片机的震荡电路设计、LED数码管显示正在播放的音乐序号,按键控制等,但由于AT89S51分辨率不是太高,音乐有点单调,另外,由于时间关系具体电路还有的地方不尽完善之处。

This article through to play music based on single-chip microcomputer control design of research and design, the realization of the design is analyzed the meaning and feasibility. SCM AT889S51 is a kind of very small but functions very much, very wide application of a chip, power is also very little, using AT89S51 as core making music playing system control circuit design a lot simpler, can relapse burning, because for learning to reduce costs. This design external use of MCU reset circuit design, a single chip microcomputer shocks of circuit design, LED digital display tube being played music, serial Numbers, button control etc, but because AT89S51 resolution does not too much, music is a bit dull, moreover, due to the time relationship specific circuit and place imperfect place.

六、参考文献

6 and references

[18]杨欣.电路设计与仿真.北京:清华大学出版社,2006

[18] YangXin. Circuit design and simulation. Beijing: tsinghua university press, 2006

七、附录

Seven, appendix

相关主题
文本预览
相关文档 最新文档