Design of music box based on 51 single chip microcomputer

Publisher:大伊山人Latest update time:2021-10-12 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Hardware Solution

This design uses the 51 single-chip microcomputer principle and control theory to design the hardware circuit of the music performance controller, and uses C language for program design. By controlling the timer inside the single-chip microcomputer to generate square waves of different frequencies, the buzzer is driven to emit music of different tones, and the delay is used to control the length of the pronunciation time. By converting the music score into the corresponding timing constant, you can play pleasant music from the pronunciation device.


It is mainly composed of 51 single chip microcomputer + minimum system + LM386 power amplifier circuit + speaker + LED indicator module + button module; as shown in the figure:

2. Design function

(1) Using an external power amplifier circuit and LM386 chip to drive the speaker, the hardware circuit of the music player is formed;

(2) Built-in 8 songs;

(3) Four button functions: a single button for reset, previous song, start/pause, and next song;


3. Design Schematic

(1) The schematic diagram is mainly designed using AD software, as shown in the figure:

(2) The Protues simulation diagram is as follows:

(3) The PCB diagram is as follows:

4. Software Design

(1) Program flow chart

(2) Main program source code


void main(void)

{

TMOD=0x11; //T0 T1 are both in working mode 1

ET0=1; //T0 opens interrupt

EA=1; //CPU interrupt  

while(1)

{

music_play(); //Play a note of the corresponding song according to the current state


if(!pause) //Pause key processing

{

delayms(5);

if(!pause)

{

if(music_num==0) //music_num=0 only exists when the device is just powered on and the pause button is not pressed, indicating the state when the device is just powered on. Press the button to start playing from the first song.

{

music_num=1; //Set the song number to 1

num=0;         //play from the beginning

play_enable=1; //Allow playback

}

else

{

play_enable=~play_enable;

    speaker=1;

}

while(!pause) //What to do if you hold down the pause button

{

if(play_enable==0){}         //If it is paused, the display time remains unchanged //(play_enable==0 when paused)

}


  }//Pause key processing ends

}//while ends


if((!play_up)&&(music_num!=0)) //Previous song button

{

delayms(5);

if((!play_up)&&(music_num!=0))

{ speaker=1;

music_num-=1; // song number minus one

if(music_num<=0)

music_num=8;

num=0; //Start playing from the beginning


if(music_num==(sound_amount+1))

music_num=1; 

delayms(500); // song switching delay 0.5S

}

}


if((!play_down)&&(music_num!=0))

{

delayms(5);

if((!play_down)&&(music_num!=0))

{ speaker=1;

music_num+=1; //Song number plus one

if(music_num>=9)

music_num=1;

num=0; //Start playing from the beginning


if(music_num==0)

music_num=sound_amount;

delayms(500); // song switching delay 0.5S

}

}


}

Reference address:Design of music box based on 51 single chip microcomputer

Previous article:Automobile Intelligent Lighting Control System Based on 51 Single Chip Microcomputer
Next article:Wireless anti-theft alarm based on 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号