Electronic keyboard design based on 51 microcontroller

Electronic keyboard design based on 51 microcontroller

(Simulation + Program + Schematic + Design Report)

Function introduction

Specific functions:

1. Use the eight keys 1, 2, 3, 4, 5, 6, 7, and 8 of the keyboard to produce 8 different tones.

2. There are 3 buttons that can play 3 songs respectively.

3. Song titles “Girl with Waving Wings”, “Same Song” and “Two Butterflies”

?

/*******51 MCU simple electronic keyboard music box design************/
/**********do re mi fa so la si treble do************/
/******************Built-in 3 songs************************/
/***"Girl with Waving Wings", "Same Song", "Two Butterflies"***/

/********************original design********************/

#include <REGX52.H> //Adjust system header files

#define uchar unsigned char //uchar replaces unsigned char
#define uint unsigned int //uint replaces unsigned char
\t
#define Key1 P2_0 //Define key 1 (play "Girl with Wings")
#define Key2 P2_1 //Define key 2 (play "the same song")
#define Key3 P2_2 //Define key 3 (play "Two Butterflies")

#define SMG P0 //Define the digital tube display end
#define Speak P2_4 //Define buzzer interface

uchar sth,stl; //Define global variable sth stl
uint i,j; //Define loop variable i

uchar code table[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,
0x88,0x83,0xC6,0xA1,0x86,0x8E};//Define digital tube display 0-9,A-F


uchar code Music_hzcb[]={//"Girl with Wings" system comes with song notes
0x17,0x02, 0x17,0x03, 0x18,0x03, 0x19,0x02, 0x15,0x03,
    0x16,0x03, 0x17,0x03, 0x17,0x03, 0x17,0x03, 0x18,0x03,
0x19,0x02, 0x16,0x03, 0x17,0x03, 0x18,0x02, 0x18,0x03,
    0x17,0x03, 0x15,0x02, 0x18,0x03, 0x17,0x03, 0x18,0x02,
    0x10,0x03, 0x15,0x03, 0x16,0x02, 0x15,0x03, 0x16,0x03,
    0x17,0x02, 0x17,0x03, 0x18,0x03, 0x19,0x02, 0x1A,0x03,
    0x1B,0x03, 0x1F,0x03, 0x1F,0x03, 0x17,0x03, 0x18,0x03,
    0x19,0x02, 0x16,0x03, 0x17,0x03, 0x18,0x03, 0x17,0x03,
    0x18,0x03, 0x1F,0x03, 0x1F,0x02, 0x16,0x03, 0x17,0x03,
    0x18,0x03, 0x17,0x03, 0x18,0x03, 0x20,0x03, 0x20,0x02,
    0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x20,0x03, 0x21,0x03,
    0x20,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x1F,0x03,
    0x1B,0x03, 0x19,0x03, 0x19,0x03, 0x15,0x03, 0x1A,0x66,
    0x1A,0x03, 0x19,0x03, 0x15,0x03, 0x15,0x03, 0x17,0x03,
    0x16,0x66, 0x17,0x04, 0x18,0x04, 0x18,0x03, 0x19,0x03,
    0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x20,0x03, 0x21,0x03,
    0x20,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x1F,0x03,
    0x1B,0x03, 0x19,0x03, 0x19,0x03, 0x15,0x03, 0x1A,0x66,
    0x1A,0x03, 0x19,0x03, 0x19,0x03, 0x1F,0x03, 0x1B,0x03,
    0x1F,0x00, 0x1A,0x03, 0x1A,0x03, 0x1A,0x03, 0x1B,0x03,
    0x1B,0x03, 0x1A,0x03, 0x19,0x03, 0x19,0x02, 0x17,0x03,
    0x15,0x17, 0x15,0x03, 0x16,0x03, 0x17,0x03, 0x18,0x03,
    0x17,0x04, 0x18,0x0E, 0x18,0x03, 0x17,0x04, 0x18,0x0E,
    0x18,0x66, 0x17,0x03, 0x18,0x03, 0x17,0x03, 0x18,0x03,
    0x20,0x03, 0x20,0x02, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66,
    0x20,0x03, 0x21,0x03, 0x20,0x03, 0x1F,0x03, 0x1B,0x03,
    0x1F,0x66, 0x1F,0x04, 0x1B,0x0E, 0x1B,0x03, 0x19,0x03,
    0x19,0x03, 0x15,0x03, 0x1A,0x66, 0x1A,0x03, 0x19,0x03,
    0x15,0x03, 0x15,0x03, 0x17,0x03, 0x16,0x66, 0x17,0x04,
    0x18,0x04, 0x18,0x03, 0x19,0x03, 0x1F,0x03, 0x1B,0x03,
    0x1F,0x66, 0x20,0x03, 0x21,0x03, 0x20,0x03, 0x1F,0x03,
    0x1B,0x03, 0x1F,0x66, 0x1F,0x03, 0x1B,0x03, 0x19,0x03,
    0x19,0x03, 0x15,0x03, 0x1A,0x66, 0x1A,0x03, 0x19,0x03,
    0x19,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x00, 0x18,0x02,
    0x18,0x03, 0x1A,0x03, 0x19,0x0D, 0x15,0x03, 0x15,0x02,
    0x18,0x66, 0x16,0x02, 0x17,0x02, 0x15,0x00, 0xff,0xff};
     
uchar code Music_tyshg[]={//"Same Song" The system comes with song notes
0x0F,0x01, 0x15,0x02, 0x16,0x02, 0x17,0x66, 0x18,0x03,
    0x17,0x02, 0x15,0x02, 0x16,0x01, 0x15,0x02, 0x10,0x02,
    0x15,0x00, 0x0F,0x01, 0x15,0x02, 0x16,0x02, 0x17,0x02,
    0x17,0x03, 0x18,0x03, 0x19,0x02, 0x15,0x02, 0x18,0x66,
    0x17,0x03, 0x19,0x02, 0x16,0x03, 0x17,0x03, 0x16,0x00,
    0x17,0x01, 0x19,0x02, 0x1B,0x02, 0x1B,0x70, 0x1A,0x03,
    0x1A,0x01, 0x19,0x02, 0x19,0x03, 0x1A,0x03, 0x1B,0x02,
    0x1A,0x0D, 0x19,0x03, 0x17,0x00, 0x18,0x66, 0x18,0x03,
    0x19,0x02, 0x1A,0x02, 0x19,0x0C, 0x18,0x0D, 0x17,0x03,
    0x16,0x01, 0x11,0x02, 0x11,0x03, 0x10,0x03, 0x0F,0x0C,
    0x10,0x02, 0x15,0x00, 0x1F,0x01, 0x1A,0x01, 0x18,0x66,
    0x19,0x03, 0x1A,0x01, 0x1B,0x02, 0x1B,0x03, 0x1B,0x03,
    0x1B,0x0C, 0x1A,0x0D, 0x19,0x03, 0x17,0x00, 0x1F,0x01,
    0x1A,0x01, 0x18,0x66, 0x19,0x03, 0x1A,0x01, 0x10,0x02,
    0x10,0x03, 0x10,0x03, 0x1A,0x0C, 0x18,0x0D, 0x17,0x03,
    0x16,0x00, 0x0F,0x01, 0x15,0x02, 0x16,0x02, 0x17,0x70,
    0x18,0x03, 0x17,0x02, 0x15,0x03, 0x15,0x03, 0x16,0x66,
    0x16,0x03, 0x16,0x02, 0x16,0x03, 0x15,0x03, 0x10,0x02,
    0x10,0x01, 0x11,0x01, 0x11,0x66, 0x10,0x03, 0x0F,0x0C,
    0x1A,0x02, 0x19,0x02, 0x16,0x03, 0x16,0x03, 0x18,0x66,
    0x18,0x03, 0x18,0x02, 0x17,0x03, 0x16,0x03, 0x19,0x00,
    0xff,0xff };
                                
uchar code Music_lzhhd[] ={//"Two Butterflies" system comes with song notes
0x17,0x03, 0x16,0x03, 0x17,0x01, 0x16,0x03, 0x17,0x03,
    0x16,0x03, 0x15,0x01, 0x10,0x03, 0x15,0x03, 0x16,0x02,
    0x16,0x0D, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x10,0x03,
    0x10,0x0E, 0x15,0x04, 0x0F,0x01, 0x17,0x03, 0x16,0x03,
    0x17,0x01, 0x16,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x01,
0x10,0x03, 0x15,0x03, 0x16,0x02, 0x16,0x0D, 0x17,0x03,
0x16,0x03, 0x15,0x03, 0x10,0x03, 0x15,0x03, 0x16,0x01,
0x17,0x03, 0x16,0x03, 0x17,0x01, 0x16,0x03, 0x17,0x03,
0x16,0x03, 0x15,0x01, 0x10,0x03, 0x15,0x03, 0x16,0x02,
0x16,0x0D, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x10,0x03,
0x10,0x0E, 0x15,0x04, 0x0F,0x01, 0x17,0x03, 0x19,0x03,
0x19,0x01, 0x19,0x03, 0x1A,0x03, 0x19,0x03, 0x17,0x01,
0x16,0x03, 0x16,0x03, 0x16,0x02, 0x16,0x0D, 0x17,0x03,
0x16,0x03, 0x15,0x03, 0x10,0x03, 0x10,0x0D, 0x15,0x00,
0x19,0x03, 0x19,0x03, 0x1A,0x03, 0x1F,0x03, 0x1B,0x03,
0x1B,0x03, 0x1A,0x03, 0x17,0x0D, 0x16,0x03, 0x16,0x03,
0x16,0x0D, 0x17,0x01, 0x17,0x03, 0x17,0x03, 0x19,0x03,
0x1A,0x02, 0x1A,0x02, 0x10,0x03, 0x17,0x0D, 0x16,0x03,
0x16,0x01, 0x17,0x03, 0x19,0x03, 0x19,0x03, 0x17,0x03,
0x19,0x02, 0x1F,0x02, 0x1B,0x03, 0x1A,0x03, 0x1A,0x0E,
0x1B,0x04, 0x17,0x02, 0x1A,0x03, 0x1A,0x03, 0x1A,0x0E,
0x1B,0x04, 0x1A,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03,
0x17,0x0D, 0x16,0x03, 0x17,0x03, 0x19,0x01, 0x19,0x03,
0x19,0x03, 0x1A,0x03, 0x1F,0x03, 0x1B,0x03, 0x1B,0x03,
0x1A,0x03, 0x17,0x0D, 0x16,0x03, 0x16,0x03, 0x16,0x03,
0x17,0x01, 0x17,0x03, 0x17,0x03, 0x19,0x03, 0x1A,0x02,
0x1A,0x02, 0x10,0x03, 0x17,0x0D, 0x16,0x03, 0x16,0x01,
0x17,0x03, 0x19,0x03, 0x19,0x03, 0x17,0x03, 0x19,0x03,
0x1F,0x02, 0x1B,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04,
0x17,0x02, 0x1A,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04,
0x17,0x16, 0x1A,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04,
0x1A,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03, 0x0F,0x02,
0x10,0x03, 0x15,0x00, 0xff,0xff };
  
uchar code Music_Code[]={ //eight notes do re mi fa so la si high note do
0xf8,0x8b,0xf9,0x5b,0xfa,0x14,0xfa,0x66,
0xfb,0x03,0xfb,0x8f,0xfc,0x0b,0xfd,0xee};
uchar const yinfu1[3][14]={ //Three notes: low, medium and high
0xf8,0x8b,0xf9,0x5b,0xfa,0x14,0xfa,0x66,0xfb,0x03,0xfb,0x8f,0xfc,0x0b,
0xfc,0x43,0xfc,0xab,0xfd,0x08,0xfd,0x33,0xfd,0x81,0xfd,0xc7,0xfe,0x05,
0xfb,0x21,0xfe,0x55,0xfe,0x84,0xfe,0x99,0xfe,0xc0,0xfe,0xe3,0xff,0x02};
uchar const length[]={1,2,4,8,16,32,64}; //Frequent note lookup table (beat)


void delay_ms(uint time) //Millisecond delay function
{
uint z;
uchar x,y;
for(z=0;z<time;z + + )
for(x=5;x>0;x--)
for(y=97;y>0;y--);
}

void Time0_Init() //Timer T0 initialization function
{
TMOD=0x01; //Working mode 1
TH0=sth; //Assign the initial value to the high eight bits of the timer
TL0=stl; //Assign the initial value to the lower eight bits of the timer
ET0=1; //Enable T0 interrupt
EA=1; //Turn on global interrupt
TR0=0; //Close timer T0
}

void main() //main function entry
{
Time0_Init(); //Timer T0 initialization
Speak=1; //Set the buzzer port to 1 (putting the buzzer in a power-off state of 5V)
while(1) //infinite loop
{
switch(P1) //switch statement determines and detects the P1 button status
{
case 0xfe: //P1=0xfe "do" button pressed
delay_ms(10); //Delay debounce
if(P1==0xfe) //Determine whether the "do" button is pressed
{
SMG=table[1]; //The digital tube displays "1"
i=0; //Set i to 0
TR0=0; //Close timer T0
sth=Music_Code[2*i]; //Assign the high eight bits of the timer to "do"
stl=Music_Code[2*i + 1]; //The lower eight bits of the timer are assigned "do"
TR0=1; //Start timer T0
for(j=0;j<=1000;j + + ) //Software delay, detect within a certain period of time
{
delay_ms(10); //Delay
if(P1==0xfe) continue; //Press the "do" button and jump out (continue pronunciation)
else break; //If released, return
}
SMG=0xff; //Turn off the digital tube display
Speak=1; //Set the buzzer port to 1 (putting the buzzer in a power-off state of 5V)
TR0=0; //Close timer T0
for(;;)
{
while(P1==0xfe); //Wait for the button to be released
delay_ms(10); //Delay debounce
if(P1==0xfe) continue;
else break; //Confirm to release and exit
}
TR0=0; //Close timer T0
}
break; //return
case 0xfd: //P1=0xfd "re" button pressed
delay_ms(10); //Delay debounce
if(P1==0xfd) //Determine whether the "re" button is pressed
{
SMG=table[2]; //The digital tube displays "2"
i=1; //Set i to 1
TR0=0; //Close timer T0
sth=Music_Code[2*i]; //Assign the high eight bits of the timer to "re"
stl=Music_Code[2*i + 1]; //The lower eight bits of the timer are assigned "re"
TR0=1; //Start timer T0
for(j=0;j<=1000;j + + ) //Software delay, detect within a certain period of time
{
delay_ms(10); //Delay
if(P1==0xfd) continue; //Press the "re" button to jump out (continue pronunciation)
else break; //If released, return
}
SMG=0xff; //Turn off the digital tube display
Speak=1; //Set the buzzer port to 1 (putting the buzzer in a power-off state of 5V)
TR0=0; //Close timer T0
for(;;)
{
while(P1==0xfd); //Wait for the button to be released
delay_ms(10); //Delay debounce
if(P1==0xfd) continue;
else break; //Confirm to release and exit
}
}
TR0=0; //Close timer T0
break; //return
case 0xef: //P1=0xef "mi" button pressed
delay_ms(10); //Delay debounce
if(P1==0xef) //Determine whether the "mi" button is pressed
{
SMG=table[3]; //The digital tube displays "3"
i=2; //Set i to 2
TR0=0; //Close timer T0
sth=Music_Code[2*i]; //Assign the high eight bits of the timer to "mi"
stl=Music_Code[2*i + 1]; //The lower eight bits of the timer are assigned "mi"
TR0=1; //Start timer T0
for(j=0;j<=1000;j + + ) //Software delay, detect within a certain period of time
{
delay_ms(10); //Delay
if(P1==0xef) continue; //Press the "mi" button and jump out (continue pronunciation)
else break; //If released, return
}
SMG=0xff; //Turn off the digital tube display
Speak=1; //Set the buzzer port to 1 (putting the buzzer in a power-off state of 5V)
TR0=0; //Close timer T0
for(;;)
{
while(P1==0xef); //Wait for the button to be released
delay_ms(10); //Delay debounce
if(P1==0xef) continue;
else break; //Confirm to release and exit
}
}
TR0=0; //Close timer T0
break; //return
default: break; //No P1, no button pressed, return
}
switch(P3) //switch statement determines and detects the P3 button status
{
case 0xfe: //P3=0xfe "fa" button pressed
delay_ms(10); //Delay debounce
if(P3==0xfe) //Determine whether the "fa" button is pressed
{
SMG=table[4]; //The digital tube displays "4"
i=3; //Set i to 3
TR0=0; //Close timer T0
sth=Music_Code[2*i]; //Assign the high eight bits of the timer to "fa"
stl=Music_Code[2*i + 1]; //The lower eight bits of the timer are assigned "fa"
TR0=1; //Start timer T0
for(j=0;j<=1000;j + + ) //Software delay, detect within a certain period of time
{
delay_ms(10); //Delay
if(P3==0xfe) continue; //Press the "fa" button to jump out (continue pronunciation)
else break; //If released, return
}
SMG=0xff; //Turn off the digital tube display
Speak=1; //Set the buzzer port to 1 (putting the buzzer in a power-off state of 5V)
TR0=0; //Close timer T0
for(;;)
{
while(P3==0xfe); //Wait for the button to be released
delay_ms(10); //Delay debounce
if(P3==0xfe) continue;
else break; //Confirm to release and exit
}
}
TR0=0; //Close timer T0
break; //return
case 0xf7: //P3=0xf7 "so" button pressed
delay_ms(10); //Delay debounce
if(P3==0xf7) //Determine whether the "so" button is pressed
{
SMG=table[5]; //The digital tube displays "5"
i=4; //Set i to 4
TR0=0; //Close timer T0
sth=Music_Code[2*i]; //Assign the high eight bits of the timer to "so"
stl=Music_Code[2*i + 1]; //Assign the lower eight bits of the timer to "so"
TR0=1; //Start timer T0
for(j=0;j<=1000;j + + ) //Software delay, detect within a certain period of time
{
delay_ms(10); //Delay
if(P3==0xf7) continue; //Press the "so" button to jump out (continue pronunciation)
else break; //If released, return
}
SMG=0xff; //Turn off the digital tube display
Speak=1; //Set the buzzer port to 1 (putting the buzzer in a power-off state of 5V)
TR0=0; //Close timer T0
for(;;)
{
while(P3==0xf7); //Wait for the button to be released
delay_ms(10); //Delay debounce
if(P3==0xf7) continue;
else break; //Confirm to release and exit
}
}
TR0=0; //Close timer T0
break; //return
case 0xef: //P3=0xef "la" button pressed
delay_ms(10); //Delay debounce
if(P3==0xef) //Determine whether the "la" button is pressed
{
SMG=table[6]; //The digital tube displays "6"
i=5; //Set i to 5
TR0=0; //Close timer T0
sth=Music_Code[2*i]; //Assign the high eight bits of the timer to "la"
stl=Music_Code[2*i + 1]; //Assign the lower eight bits of the timer to "la"
TR0=1; //Start timer T0
for(j=0;j<=1000;j + + ) //Software delay, detect within a certain period of time
{
delay_ms(10); //Delay
if(P3==0xef) continue; //Press the "la" button and jump out (continue pronunciation)
else break; //If released, return
}
SMG=0xff; //Turn off the digital tube display
Speak=1; //Set the buzzer port to 1 (putting the buzzer in a power-off state of 5V)
TR0=0; //Close timer T0
for(;;)
{
while(P3==0xef); //Wait for the button to be released
delay_ms(10); //Delay debounce
if(P3==0xef) continue;
else break; //Confirm to release and exit
}
}
TR0=0; //Close timer T0
break; //return
case 0xdf: //P3=0xdf "si" button pressed
delay_ms(10); //Delay debounce
if(P3==0xdf) //Determine whether the "si" button is pressed
{
SMG=table[7]; //The digital tube displays "7"
i=6; //Set i to 6
TR0=0; //Close timer T0
sth=Music_Code[2*i]; //Assign the high eight bits of the timer to "si"
stl=Music_Code[2*i + 1]; //The lower eight bits of the timer are assigned "si"
TR0=1; //Start timer T0
for(j=0;j<=1000;j + + ) //Software delay, detect within a certain period of time
{
delay_ms(10); //Delay
if(P3==0xdf) continue; //Press the "si" button and jump out (continue pronunciation)
else break; //If released, return
}
SMG=0xff; //Turn off the digital tube display
Speak=1; //Set the buzzer port to 1 (putting the buzzer in a power-off state of 5V)
TR0=0; //Close timer T0
for(;;)
{
while(P3==0xdf); //Wait for the button to be released
delay_ms(10); //Delay debounce
if(P3==0xdf) continue;
else break; //Confirm to release and exit
}
}
TR0=0; //Close timer T0
break; //return
case 0xbf: //P3=0xbf "Treble do" button is pressed
delay_ms(10); //Delay debounce
if(P3==0xbf) //Determine whether the "treble do" button is pressed
{
SMG=table[1] & amp;0x7f; //The digital tube displays "1" with a decimal point (1.)
i=7; //Set i to 7
TR0=0; //Close timer T0
sth=Music_Code[2*i]; //Assign the high eight bits of the timer to "treble do"
stl=Music_Code[2*i + 1]; //The lower eight bits of the timer are assigned "treble do"
TR0=1; //Start timer T0
for(j=0;j<=1000;j + + ) //Software delay, detect within a certain period of time
{
delay_ms(10); //Delay
if(P3==0xbf) continue; //Press the "treble do" button and jump out (continue pronunciation)
else break; //If released, return
}
SMG=0xff; //Turn off the digital tube display
Speak=1; //Set the buzzer port to 1 (putting the buzzer in a power-off state of 5V)
TR0=0; //Close timer T0
for(;;)
{
while(P3==0xbf); //Wait for the button to be released
delay_ms(10); //Delay debounce
if(P3==0xbf) continue;
else break; //Confirm to release and exit
}
}
TR0=0; //Close timer T0
break; //return
default: break; //No P3, no button pressed, return
}
\t\t
if(Key1==0) //Button 1 is pressed (play "Girl with Wings")
{
delay_ms(10); //Delay debounce
if(Key1==0) //Determine whether button 1 is pressed
{
SMG=table[10]; //The digital tube displays "A"
for(i=0;Music_hzcb[i]!=0xff;i + + ) //for loop statement
{ //When Music_hzcb[]=0ff, jump out of the for loop statement and stop playing music
sth=yinfu1[(Music_hzcb[i] 0)/10-1][((Music_hzcb[i] )-1)*2]; //Assign the high eight bits of the timer
stl=yinfu1[(Music_hzcb[i] 0)/10-1][((Music_hzcb[i] )-1)*2 + 1];//Assignment of the lower eight bits of the timer
i + + ; //i plus 1
TR0=1; //Start timer T0
delay_ms(4*500/length[Music_hzcb[i] ]); //Determine the fractional note (beat)
TR0=0; //End of beat, close timer T0
}
SMG=0xff; //Turn off the digital tube display
Speak=1; //Set the buzzer port to 1 (putting the buzzer in a power-off state of 5V)
for(;;)
{
while(Key1==0); //Wait for the key to be released
delay_ms(10); //Delay debounce
if(Key1==0) continue;
else break; //Confirm to release and exit
}
}
}
if(Key2==0) //Button 2 is pressed (play "the same song")
{
delay_ms(10); //Delay debounce
if(Key2==0) //Determine whether button 2 is pressed
{
SMG=table[11]; //The digital tube displays "B"
for(i=0;Music_tyshg[i]!=0xff;i + + ) //for loop statement
{ //When Music_tyshg[]=0ff, jump out of the for loop statement and stop playing music
sth=yinfu1[(Music_tyshg[i] 0)/10-1][((Music_tyshg[i] )-1)*2]; //Assign the high eight bits of the timer
stl=yinfu1[(Music_tyshg[i] 0)/10-1][((Music_tyshg[i] )-1)*2 + 1];//Assignment of the lower eight bits of the timer
i + + ; //i plus 1
TR0=1; //Start timer T0
delay_ms(4*500/length[Music_tyshg[i] ]); //Determine the quarter note (beat)
TR0=0; //End of beat, close timer T0
}
SMG=0xff; //Turn off the digital tube display
Speak=1; //Set the buzzer port to 1 (putting the buzzer in a power-off state of 5V)
for(;;)
{
while(Key2==0); //Wait for the key to be released
delay_ms(10); //Delay debounce
if(Key2==0) continue;
else break; //Confirm to release and exit
}
}
}

Hardware design

Use components:

Microcontroller: STC89C52;

(Note: The microcontroller is universal, whether it is 51 or 52, whether it is stc or at, the pin functions are the same. The program is also the same.)

Electrolytic capacitor 10uF; resistor 10K;

Ceramic capacitor 30P; crystal oscillator 12M;

Resistor 470 (SMD); button;

Resistor 4.7K; transistor 8550;

Passive buzzer; 1-bit common anode digital tube;

DIP40; connecting wire;

7*9CM universal board; USB male to male cable;

2P pin header; wires: several;

Flowchart:

Design information

01 Simulation diagram

This design uses two versions of proteus7.8 and proteus8.7, and is backward compatible, no need to worry! Specifically as shown in the picture!

02 Schematic Diagram

The schematic diagram of this system is designed using Altium Designer19, as shown in the figure!

03 Program

This design is programmed using two versions of the software keil4 and keil5, so there is no need to worry! Specifically as shown in the picture!

?

04 Design Report

A design report of more than 7,000 words, the details are as follows!

?

05 Design information

All materials include simulation source files, programs (including comments), AD schematics, proposal reports, reference papers, flow charts, task books, etc. The specific content is as follows, the most complete on the entire network! !

The following is the open source 51 microcontroller design information

?Everyone learns and makes progress together:

Link: https://pan.baidu.com/s/1GnKl4Pda-8e2O7XQhpYSQw?pwd=gc8f
Extraction code: gc8f

Like and share, learn and progress together! Grow together.