Realization of playing music with single chip microcomputer based on Proteus

Publisher:水云间梦Latest update time:2012-05-25 Source: 襄樊学院学报Keywords:Proteus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Many current systems that use single-chip microcomputers to perform music are implemented using development boards combined with simulators. This method is not very complicated and is easy to implement, but it is not very convenient to debug and the cost is also high. This paper proposes a method of playing music with a single-chip microcomputer based on Proteus. It is very simple and practical, and this method is implemented based on software, so the cost is very low, the debugging is convenient, and the effect is also very good. It is suitable for single-chip microcomputer learners who love music. The design of the single-chip microcomputer system is divided into two parts: hardware design and software design.

1 Hardware Design

The hardware part is relatively simple. If you are doing experiments on a development board, you can follow the circuit connection shown in Figure 1 below.

The P2.5 port of the AT89C51 microcontroller controls an 8550 transistor, which controls the power on and off of the electromagnetic buzzer.

If Proteus software is used for simulation, the circuit will be simpler, as shown in Figure 2.

Figure 2 shows the schematic diagram of using a microcontroller to control the sound of a buzzer in the Proteus environment.

Key components required: microcontroller and buzzer.

In order to facilitate software programming, we must first understand the basic principles of microcontroller singing.

What is sound? Sound is the vibration of air. We can hear different tones of sound with different vibration frequencies. The spectrum of sound ranges from tens to thousands of hertz.

Secondly, how to make the buzzer sound? There are many types of buzzers, but they can be roughly divided into two categories: active type (makes sound when DC is supplied, but the frequency is single); passive type (makes different sounds depending on the frequency of the input square wave). Here we choose a passive buzzer.

The basic principle of single-chip microcomputer singing: use the program to control a certain port of the single-chip microcomputer to output a square wave of a certain frequency to the buzzer, and the buzzer can emit a certain tone. If different delay programs are used to change the output frequency, the tone can be changed, and then the single-chip microcomputer can emit "1", "2", "3", "4", "5", "6", "7" music. [page]

2 Software Design

This is achieved by changing the high and low level states of the port line at different frequencies through software delay or timer delay. If it is just to make the buzzer sound, this is enough. But what we want is singing, so there is still some work to be done.

2.1 Tone

Output square waves of different frequencies to achieve different tones such as 1, 2, 3, and 4; for example, to emit 200HZ audio, its period is 1/200s, that is, 5ms. In this way, when the duration of the high or low level of P2.5 is 2.5ms, a 200HZ tone can be emitted. We can write a delay subroutine and use R3 to provide parameters. When R3=1, the delay is 20us. Then when R3 takes 2500/20=125 (7DH), a 200Hz tone can be emitted. By providing different R3 constants, different tone changes can be obtained.

The general sound generation program can be used to program music performance. Music is composed of tones with certain relationships of high and low, long and short, and strong and weak. In a piece of music, the pitch and length of each note are related to the frequency and beat (as shown in Figure 3).

Figure 3 The relationship between the pitch and duration of a note and its frequency

Figure 3 shows the piano keys of two scales (one scale has 8 notes) and the note name and frequency (Hz) of each key. The low scale is from low C (130.8Hz) to middle C (261.7Hz) and the high scale is from middle C to high C (523.3Hz). The black key is half a tone higher or lower than the white key next to it. The frequency and duration of each note that makes up the music are two important data required for the music program to sound. The frequency can be obtained from the figure, and the duration of the note can be determined according to the music speed and the number of beats of each note, which can be obtained from the music score.

2.2 Beat

Control the time of a note output, such as 1 beat, 1/4 beat. In 4/4 (4/4 time), a quarter note is a beat, 4 beats per measure, a whole note lasts 4 beats, a half note lasts 2 beats, a quarter note lasts 1 beat, and an eighth note lasts half a beat. A whole note takes 1s, so a half note lasts 0.5s (50×10ms), a quarter note lasts 0.25s (25×10ms), and an eighth note lasts 0.125s (12.5×10ms).

Knowing the relationship between pitch, frequency and time, we can define the frequency and duration of each note into two data tables according to the music score, and then write a program to retrieve the time value and frequency value in the table in turn.

The above is not enough. To play a piece of music accurately, you must accurately control the rhythm of the music, that is, the duration of a note. For example, if the rhythm of a piece of music is 94 beats per minute, then one beat is 60/94=0.64s.

We can use a timer to control the beat of music. Simply put, if a note of one beat is sung for 0.64s, we set a timer for 0.64s, and change to the next note when the time is up. However, since the maximum timing time of T0 of the microcontroller can only be 65ms under the 12MHz crystal oscillator, it is impossible to directly change the initial value of T0 to achieve different beats. How to time a longer time, we can use T0 to generate a 10ms time base, and then set an interrupt counter, and control the length of the beat time by judging the value of the interrupt counter.

For example, for a 1/4 beat note, the timing time is 0.16s, and the corresponding time constant (mid-segment counter) is 16 (ie 10H); for a 3 beat note, the timing time is 1.92s, and the corresponding time constant is 192 (ie C0H).

2.3 Circuit Implementation

Because a piece of music has more than one note, we cannot "manually" provide time constants for the scale of each note. To simplify the implementation, we compile a table that groups the time constant of each note and its corresponding beat constant, and arranges all the constants in the music in order. In the program, we use table lookup instructions to find out the frequency and corresponding beat time of each note in turn, generate notes and control the rhythm, and then we can achieve the performance effect.

In addition, the end character and the body end character can be represented by the codes 00H and FFH respectively. If the table lookup result is 00H, it means the end of the song; if the table lookup result is FFH, a corresponding pause effect is produced.

In order to create a sense of hand-plucked rhythm, between certain notes (for example two identical notes) a note with a slightly different frequency per time unit is inserted.

The program flowchart is shown in Figure 4. This program plays the folk song "Osmanthus Flowers Bloom Everywhere in August", in the key of C, with a rhythm of 94 beats/min.

Use Keil to compile the program, as shown in Figure 5. The specific method can be found in the literature [5]. After the compilation is correct, a .hex file is generated. Then double-click the AT89C51 in the schematic diagram under the Proteus environment to find this .hex file, and then click the Play button. At this time, the buzzer controlled by the microcontroller can start playing music. [page]

Figure 4 Program flow chart

Figure 5 Compiling the program in Keil environment

3 Conclusion

The method introduced above has been tested and works well. It has a certain enlightenment effect on beginners of single-chip microcomputers. Readers can also find a song by themselves, translate the music into a code table and input it into the single-chip microcomputer without changing the program. This experimental method is simple, even people who don't understand music can easily translate an unfamiliar song into code.

Keywords:Proteus Reference address:Realization of playing music with single chip microcomputer based on Proteus

Previous article:The implementation of intelligent time-sharing electricity meter with single chip microcomputer
Next article:Design of air mass flow display device based on single chip microcomputer

Recommended ReadingLatest update time:2024-11-16 21:54

PIC16F877 outputs sine wave signal PROTEUS simulation and program
//The PIC16F877 microcontroller outputs a sine wave signal simulation schematic diagram as follows //20MHz crystal oscillator, outputs 500Hz sine wave, 100 points per cycle. //1 cycle time is 2ms, the interval between two points is 2000/100=20us //Use TMR2 to delay, 256*Tcy*K=20, Tcy=0.2, take K=1 //PR2 calculatio
[Microcontroller]
PIC16F877 outputs sine wave signal PROTEUS simulation and program
Embedded virtual development platform based on ARM
With the increasing popularity of embedded devices (such as smart MP4, digital cameras, smart phones, TV set-top boxes and PDAs, etc.), embedded training and embedded development have become popular. Most of these embedded devices use 32-bit RISC embedded processors as core components, among which embedded processor
[Microcontroller]
Embedded virtual development platform based on ARM
51 MCU simulation SPI bus communication program and proteus simulation
Share a 51 microcontroller simulation SPI bus to communicate program and simulation schematic diagram as follows The microcontroller source program is as follows: #include reg51.h //Header file containing microcontroller registers #include intrins.h //Header file containing _nop_() function definition //x5045 pin de
[Microcontroller]
51 MCU simulation SPI bus communication program and proteus simulation
ATMEGA48 uses buttons to control the clock proteus simulation
  ATMEGA48 clock program source code: #include iom48v.h //Common anode digital tube key code const unsigned char disp_table_ca = { 0xC0,0xF9,0xA4,0xB0,0x99,     0x92,0x82,0xF8,0x80,0x90 }; char a_second=0; char b_second=0; int count=0,flag; void delay(unsigned int x) { int i,j; for(i=0;i x;i++) for(j=0;j 1141;j++)
[Microcontroller]
ATMEGA48 uses buttons to control the clock proteus simulation
Four-digit digital tube dynamic display PROTEUS simulation based on PIC16F877
Source code description ;**************************************************** ;** File name: four_led.asm ** ;** Function: Four-digit digital tube dynamically displays 1234 ** ;****************************************************      LIST P=16F877,R=DEC ; Set the assembly parameters to PIC16F877, the default num
[Microcontroller]
Application of ProteuS simulation software in ARM system design
introduction Nowadays, embedded devices exist in every corner of people's lives, such as DVDs, mobile phones, MP3s, and PDAs. Most of these embedded devices use 32-bit RISC embedded processors as core components. Among them, embedded processors based on ARM cores are the best, accounting for more than 75% o
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号