单片机音乐播放器设计 下载本文

内容发布更新时间 : 2024/5/20 18:27:49星期一 下面是文章的全部内容请认真阅读。

单片机音乐播放器设计

摘要

本文将介绍一种以89C51型单片机为基础元件设计的自动音乐播放器。在当今这个科技高速发展的时代,生活节奏的加快,人们长期处于工作、学习压力过大的状态,对于调节心理压力而言音乐对于每一个人都十分重要,由此音乐播放器在国内已经开始普及。校园里的上下课的铃声,宿舍内早晨的起床号声音,都由以前枯燥刺耳的铃音转变成了好听的音乐,公路、广场中的计时装置也逐渐开始采用音乐来充当铃声。此装置不仅为人们日常生活的计时提供了方便,同时也为目前快节奏的生活带来了乐趣。

本文是应用MCS-51单片机原理和控制理论设计音乐演奏控制器的硬件电路,并利用C语言进行程序设计。通过控制单片机内部的定时器来产生不同频率的方波,驱动蜂鸣器发出不同音调的音乐,再利用延迟来控制发音时间的长短。把乐谱转化成相应的定时常数就可以从发音设备中演奏出悦耳动听的音乐。

这种控制电路结构简单,可读性高,应用性强;软件程序适应范围广,对于不同的音乐只需要改变相应的定时常数即可。

关键词:单片机;音乐播放器;C语言

I

The design of the music plyer

Abstract

This article introduces a kind of 89C51-based microcontroller-based device designed for automatic music player. In today's era of rapid development of this technology, the accelerated pace of life, the long-in work, learning burden the state's case for regulating psychological stress is important for everyone, this music player at home has begun universal. Campus on the class of the ring, get up early morning dormitory No. voices, strident tones by the previous dry transformed into good music, road, square in the timing devices are also beginning to use music as ring tones. This device not only for the timing of daily life and provides a convenient, but also for the current fast-paced life fun.

This is the application of MCS-51 SCM principles and control theory, music performance controller hardware and programming using c programming language. By controlling the MCU's internal timer to generate square waves of different frequencies to drive speakers make different musical tones, and then use delay to control the length of pronunciation. The music into the corresponding time constants can be played from the sound equipment out of melodious music.

This control circuit is simple, readable, application and strong; software program to adapt to a wide range of different music just for the appropriate time constant change can be.

Keyword: Single-chip processor; Music player; C programming language

II

目 录

1 绪论 ...................................................................... 1

1.1 概述 .......................................................................... 1

1.2 单片机的产生和发展 ............................................................ 1 1.3 单片机的特点及应用 ............................................................ 2

1.3.1 单片机主要特点 .......................................................... 2 1.3.2 单片机的应用 ............................................................ 3 1.4 系统设计总体方案 .............................................................. 3 2 MCS-51单片机的结构与原理 ................................................. 5 2.1 MCS-51单片机的基本结构 ........................................................ 5

2.1.1 8051单片机的基本组成及主要性能 .......................................... 5 2.1.2 8051单片机的外部引脚说明 ................................................ 6 2.2 MCS-51单片机的微处理器 ........................................................ 9

2.2.1 运算器 .................................................................. 9 2.2.2 控制器 ................................................................. 10 2.3 MCS-51单片机的存储器 ......................................................... 11

2.3.1 内部数据存储器 ......................................................... 11 2.3.2 内部程序存储器 ......................................................... 12 2.3.3专用寄存器(SFR)简介 ................................................... 12 2.4 MCS-51单片机的定时计数 ....................................................... 14

2.4.1 定时器/计数器的结构 .................................................... 14 2.4.2 定时器/计数器的工作方式 ................................................ 15 2.4.3定时/计数器的初始化 ..................................................... 16 2.5 MCS-51单片机的中断系统 ....................................................... 16

2.5.1 中断源 ................................................................. 16 2.5.2 中断控制 ............................................................... 19 2.5.3 中断响应 ............................................................... 20 2.5.4 中断请求的撤除 ......................................................... 20 2.6 MCS-51单片机的并行/串行接口 .................................................. 21 3 硬件电路设计 ............................................................. 23 3.1 总体设计框图 ................................................................. 23

3.2 时钟电路 ..................................................................... 23 3.3 复位电路 ..................................................................... 23 3.4 选曲电路 ..................................................................... 24 3.5 音频发生及放大电路 ........................................................... 24 4 软件程序设计 ............................................................. 24 4.1单片机发声概述 ................................................................ 24

4.2 程序流程图 ................................................................... 26 4.3 音乐的产生 ................................................................... 27 5 KEIL仿真软件及Protel 99 SE的应用 ....................................... 29 5.1 KEIL51的应用 ................................................................. 29 5.2 protel99se的应用 ............................................................. 29 5.3 PCB板的设计制作 .............................................................. 30 6 调试与故障分析 ........................................................... 32 6.1 软件程序调试 ................................................................. 32

6.2 硬件电路调试 ................................................................. 32 7 总结与展望 ............................................................... 33

III