Haha, you can find any song online. Just go to Baidu and look up the simplified score of "Blue and White Porcelain"
#include
sbit speaker = P1^0;
unsigned char timer0h, timer0l, time;
//------------------ --------------------
//The microcontroller crystal oscillator uses 11.0592MHz
// Frequency - half-cycle data table high The eight-bit software *** saves 28 frequency data of four octaves
code unsigned char FREQH[] = {
0xF2, 0xF3, 0xF5, 0xF5, 0xF6, 0xF7, 0xF8, //Bass 1234567
0xF9, 0xF9, 0xFA, 0xFA, 0xFB, 0xFB, 0xFC, 0xFC,//1,2,3,4,5,6,7,i p>
0xFC, 0xFD, 0xFD, 0xFD, 0xFD, 0xFE, //Treble 234567
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFF}; //Super treble 1234567 p>
// Frequency-half-cycle data table lower eight bits
code unsigned char FREQL[] = {
0x42, 0xC1, 0x17, 0xB6, 0xD0, 0xD1, 0xB6, //Bass 1234567
0x21, 0xE1, 0x8C, 0xD8, 0x68, 0xE9, 0x5B, 0x8F, //1,2,3,4,5,6,7,i
0xEE, 0x44, 0x6B, 0xB4, 0xF4, 0x2D, ??//Treble 234567
0x47, 0x77, 0xA2, 0xB6, 0xDA, 0xFA, 0x16}; //Super treble 1234567
//-------------------------------------
/*code unsigned char sszymmh[] = {
3,2,3,5,2,1,6,2,2,5,2,1,6,2,
< p>1,1,3,4,6,2,3,1,3,1,3,2,2,2,2,1,3,2,1,5,2 ,4,5,2,3,3,2,1,6,2,2,3,2,1,2,
2,1,1,2,4,5,2, 3,3,2,1,2,2,3,6,1,1,1,
2,4,1,2,4,1,3,3,6,2,1 ,5,2,2,6,2,1,6,
2,1,5,2,1,5,2,4,5,2,3,6,2,1, 1,2,1,2,
2,1,5,2,1,3,2,4,2,2,3,3,2,1,5,2,2,1 ,
3,2,6,2,1,5,2,1,3,2,1,2,2,1,1,2,4,6,
2,3,1,3,1,5,2,1,3,2,1,2,2,2,6,1,1,1,
2,1,1, 2,4,6,2,3,1,3,1,5,2,1,3,2,1,2,
2,2,1,2,4,6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5,2,1,5,2,1,5,2,1,3,2,1,1,2,1,5,1,2,1,2,2,
3 ,1,1,1,1,1,5,2,1,5,2,1,5,2,1,3,2,1,1,2,1,5,1,2,1,2 ,2,5,1,2,1,2,2,5,1,2,1,2,2,1,2,2,
0, 0, 0};//National Anthem
/*code unsigned char sszymmh[] = {6,2,3,5,2,1,3,2,2,5,2,2,6,2,1,6,2 ,2,5,2,1,3,2,4,6,1,3,1,2,1,2,2,2,5,2,1,3,2,1,2,2,4 ,
6,2,3,2,3,1,2,3,2,1,3,1,7,2,1,6,2,3,5,2,1, 3,2,4,2,2,1,5,2,1,5,2,1,3,2,1,2,2,1,3,2,1,1,2,1,7, 1,1,6,1,4,
1,2,3,6,1,
1,6,2,1,1,2,2,2,2,2,5,
2,1,3,2,1,2,2,4,5,2,3 ,3,2,1,3,2,
2,5,2,2,6,2,4,2,3,3,2,3,1,1,3,2,
2,3,2,6,2,1,1,3,1,5,2,1,6,2,1,3,
2,4, 2,2,1,5,2,1,5,2,1,3,2,1,2,2,
1,3,2,1,1,2,1,7 ,1,1,6,1,4,
0, 0, 0};//Poppy*/
//End mark
/ /There is only one good data table in the world. If you want to play different music, you only need to modify this data table
//code unsigned char sszymmh[] = {
//6, 2, 3, 5, 2, 1, 3, 2, 2, 5, 2, 2, 1, 3, 2, 6, 2, 1, 5, 2, 1,
//A note has three number. The front is the note, the middle is the octave, and the back is the duration (in half a beat).
//6, 2, 3 represents: 6, alto, 3 and a half beats;
//5, 2, 1 represents: 5, alto, 1 and a half beats; Beat;
//3, 2, 2 represents: 3, alto, 2 and a half beats;
//5, 2, 2 represents: 5, alto, 2 One and a half beats;
//1, 3, 2 represents: 1, treble, 2 and a half beats;
//
//6, 2 , 4, 3, 2, 2, 5, 2, 1, 6, 2, 1, 5, 2, 2, 3, 2, 2, 1, 2, 1,
//6, 1, 1, 5, 2, 1, 3, 2, 1, 2, 2, 4, 2, 2, 3, 3, 2, 1, 5, 2, 2,
//5 , 2, 1, 6, 2, 1, 3, 2, 2, 2, 2, 2, 1, 2, 4, 5, 2, 3, 3, 2, 1,
// 2, 2, 1, 1, 2, 1, 6, 1, 1, 1, 2, 1, 5, 1, 6, 0, 0, 0,,,,,,,,,,,,,,, ,,,,,,,6,2,3, 6,2,1, 1,3,2, 7,2,1, 6,2,1, 5,2,2, 3,2,1, 5, 2,1, 6,2,4, 3,2,3,};
//---------------------- ---------------
void t0int() interrupt 1 //T0 interrupts the program and controls the tone of pronunciation
{
TR0 = 0; //Close T0 first
speaker = !speaker; //Output square wave, pronunciation
TH0 = timer0h; //Next interruption time, At this time, control the pitch level
TL0 = timer0l;
TR0 = 1; //Start T0
}
//- -------------------------------------
void delay(unsigned char t ) //Delay program, controls the length of pronunciation
{
unsigned char t1;
unsigned long t2;
for (t1 = 0; t1 < t; t1++) //Double loop, ***delay t half beats
for(t2 = 0; t2 < 8000; t2++); //delay period , can enter T0 interrupt to pronounce
TR0 = 0; //Close T0, stop pronouncing
}
//-------- ----------------------------------
void song() //Play a note
{
TH0 = timer0h; //Control tone
TL0 = timer0l;
TR0 = 1; //Start T0, output from T0 Wave to pronounce
delay(time); //Control the length of time
}
//------------- -----
--------------------
void main(void)
{
unsigned char k , i;
TMOD = 1; //Set T0 timing working mode 1
ET0 = 1; //Enable T0 interrupt
EA = 1; / /Turn on CPU interrupt
while(1) {
i = 0;
time = 1;
while(time) {
k = sszymmh[i] + 7 * sszymmh[i + 1] - 1;
//The i-th is the note, and the i+1 is the eighth note Degree
timer0h = FREQH[k]; //Read the frequency value from the data table
timer0l = FREQL[k]; //Actually, it is the timing length< /p>
time = sszymmh[i + 2]; //Read the time length value
i += 3;
song(); //Send a note
}
}
}
/*================= =====================
At the request of netizens, let’s write about the conversion relationship between music scores and data in detail below.
The first two sections of "Farewell" by Master Li Shutong will be used to illustrate the conversion method.
The lyrics of this part are: "Outside the long pavilion, beside the ancient road,";
The music score of this part is: | 5 35 1 - | 6 16 5 - |.
(Note: 1 in the score is the treble, with a dot above it; there are also some notes that should be underlined, but they cannot be marked here. Interested netizens should check the official music score.)
Then, based on this, the data table for the first two sections of "Farewell" can be written:
//---------------- -----------------------*/
//code unsigned char sszymmh[] = {
// 5, 2, 2, 3, 2, 1, 5, 2, 1, 1, 3, 4,
//Sound, alto, 2 and a half beats; Micro, alto, 1 beat Half a beat; Sui, alto, 1 and a half beats; Duo, treble, 4 and a half beats
//6, 2, 2, 1, 3, 1, 6, 2, 1, 5, 2, 4,
//La, alto, 2 and a half beats; Duo, treble, 1 and a half beats; La, alto, 1 and a half beats; Sui, alto, 4 and a half beats Shoot
//0, 0, 0};
//End mark
/*------------- -----------------------
Remember: a group of three numbers represents a note.
The first number is one of 1234567, which represents the note Dole Mi Fa...;
The second number is one of 0123, which represents bass, alto, treble, Super treble;
The third number is the number of half beats, representing the length of time.
When all three numbers are 0, it represents the end of the music data table.
Use this data table to replace the data table of "Only Mother is Good in the World" in the program, and this program can play the first two sections of "Farewell".
*/