Design of single-chip microcomputer performance system based on Proteus

Publisher:书卷气息Latest update time:2012-10-10 Source: 21ic 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 Schematic diagram of using a single-chip microcomputer to control the buzzer sound in the Proteus environment. [page]

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 sound of a certain tone. If different delay programs are used to change the output frequency, the tone can be changed, and the single-chip microcomputer can then emit the music of "1", "2", "3", "4", "5", "6", and "7".

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, 4, etc. For example, to emit 200Hz audio, its period is 1/200s, that is, 5ms. In this way, when the duration of the high level 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 (i.e. 10H); for a 3 beat note, the timing time is 1.92s, and the corresponding time constant is 192 (i.e. C0H). [page]

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 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.


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:Design of single-chip microcomputer performance system based on Proteus

Previous article:Design and implementation of multi-DSP boot scheme for link port based on CPCI bus
Next article:AD program of STC12C5410AD single chip microcomputer two digital tube display

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

DS1302 clock + 1602 LCD, proteus circuit diagram + program
  #include REGX51.H #include "LCD1602.h" #include "DS1302.h" void Delay1ms(unsigned int count) {         unsigned int i,j;         for(i=0;i count;i++)         for(j=0;j 120;j++); } main() {         SYSTEMTIME CurrentTime;         LCD_Initial();         Initial_DS1302();         GotoXY(0,0);         Print("Date:");
[Microcontroller]
DS1302 clock + 1602 LCD, proteus circuit diagram + program
001_89C52_Proteus_ADC0809 collects voltage
1) Using ADC0809 to collect DC voltage 1. The first digital tube displays the sampling input port 2. The last three digits are the sampling voltage (II) Using ADC0809 to sample AC power 1. First, step down the AC voltage, that is, use a transformer to step down the voltage and the
[Microcontroller]
001_89C52_Proteus_ADC0809 collects voltage
Proteus entry-level microcontroller (4) routine analysis
Hardware connection: P1.0-P1.7 connect led1 to led8 P0.0-P0.7 connects led9 to led16 P2.1 connection mode button P2.4 connection acceleration button P2.5 connects the deceleration button P3.0-P3.7 connect common anode digital tube Phenomenon: After powering on, LED1 to LED16 light up in a cycle (only
[Microcontroller]
Based on AT89C51 single chip microcomputer, the digital tube lights up 0 to 9 in a cycle (Keil+Proteus+C language)
Requirement Description: Use AT89C51 single chip microcomputer, green 7-segment common cathode digital tube, and use C language to implement Simulation diagram Code #include reg52.h #include intrins.h #define uchar unsigned char #define uint unsigned int uchar code DSY_CODE = {   0x3f,0x06,0x5b,0x4f, 0x66,0x6d,
[Microcontroller]
Based on AT89C51 single chip microcomputer, the digital tube lights up 0 to 9 in a cycle (Keil+Proteus+C language)
Digital pointer thermometer designed and debugged based on single chip microcomputer
  This paper mainly describes a debugging method of a digital pointer thermometer implemented using Proteus software. The MCS51 single- chip microcomputer is used as the digital signal processor of the pointer thermometer . Among them, the temperature acquisition sensor uses the Dallas company's Ds1820 single-bus dig
[Microcontroller]
Digital pointer thermometer designed and debugged based on single chip microcomputer
Using PROTEUS to simulate the serial communication of single chip microcomputer
Design requirements: Implement serial communication with 8051 microcontroller in Proteus. Let's review serial communication. In serial communication, there are two pins called TX and RX. The TX pin is used to send data, while the RX pin is used to receive data. Just put the schematic and code directl
[Microcontroller]
Using PROTEUS to simulate the serial communication of single chip microcomputer
[MCU] Practical application: Keil+Proteus digital tube counting 99
This article: Main content: Statically light up the digital tube to display the number 99, dynamically light up the digital tube to display 12345678 (8-bit digital tube). Function 1: Static lighting of the digital tube to display the number 99 (2-digit digital tube) Function 2: Dynamically light up the digital tube to
[Microcontroller]
[MCU] Practical application: Keil+Proteus digital tube counting 99
Use Proteus to learn the serial port of 51 single chip microcomputer
I won't remember the theoretical knowledge of the serial port, there is a lot of it on the Internet. The serial port of the 51 microcontroller has 4 modes, namely mode 0, mode 1, mode 2, and mode 3. Because my purpose is to use the serial port mainly to communicate with the computer, so I mainly use mode 1 (in fact, I
[Microcontroller]
Use Proteus to learn the serial port of 51 single chip microcomputer
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号