#include "reg51.h"
#define uint unsigned int
#define uchar unsigned char
uchar * TABLE ;< /p>
code uint TABLE1 [15]={64260,64400,64524,64580,
64684,64777,64820,64898,
64968,65030,65058, 65110,
65157,65178,65217};
code uchar SONG [ ]={
//1. Belated love
< p> };code uchar SONG1 [ ]={
//2. Two butterflies
};
code uchar SONG3 [ ]={
//4. One master and three apprentices
};
uchar hjsz;
uchar ljsz;
uchar jpm;
uchar yfm;
uchar t0 =0;
uint i=0;
sbit Speaker =P1^0;
uint k;
void Delay1()
{
for ( k=0; k<20000;k++);
}
void Lignt( )
{ uchar t;
for(t=0; t<10;t++)
{
P2=0xff;
Delay1();
P2=0x00;
Delay1();
}
}
void Lignt1( )
{
P2=0xaa;
Delay1();
P2=0x55;
Delay1();
}
< p> void Delay(uchar t0)//Delay{
while(t0--) //Determine the beat
Lignt1(); p>
}
void Delay2(uchar w0)//Delay
{
while(w0--) //Determine the beat
p>Lignt();
}
void T0Int() interrupt 1//TIMER0
{
TL0 = ljsz;
TH0 = hjsz;
Speaker=!Speaker;
}
void ExtInt0() interrupt 0//INT0< /p>
{
if(t0>10)
t0=0;
i=0; // Global variable, pointing to the score 1st
switch(t+)
{
case 0 : TABLE=SONG;break; //Select the 1st song
case 1 : TABLE=SONG1;break;//Select song 2
case 2 : TABLE=SONG2;break;//Select song 3
case 3 : TABLE= SONG3;break;//Select song 4
case 4 : TABLE=SONG4;break;//Select song 5
case 5 : TABLE=SONG5;break;// Select the 6th song
case 6: TABLE=SONG6;break;//Select the 7th song
case 7: TABLE=SONG7;break;//Select the 8th song
p>case 8: TABLE=SONG8;break;//Select the 9th song
case 9: TABLE=SONG9;break;//Select the 10th song
}
}
void songsing()//pronunciation program
{
i=0;
while (TABLE[i])
{
jpm=TABLE[i]&0x0f; //beat value
yfm=(TABLE[i]>>0x04 )&0x0f;//Simple notation value
if(yfm) //The simple notation is 1, take the count value
{
yfm=yfm-1; p>
hjsz=(uchar)(TABLE1[yfm]>>0x08);//Get the high byte of the count value
TH0 = hjsz;
ljsz=(uchar )(TABLE1[yfm]); //Get the low byte of the count value
TL0 = ljsz;
TR0 = 1; //Start TIMER0
}
else TR0 = 0; //The simplified notation is 0, no pronunciation
Delay(jpm); //Beat delay
i++;
}
}
void main(void)
{
TMOD =0X01;//Set TIMER0 in MODE1< /p>
TCON =0X01; //External interrupt INT0, falling edge trigger
IE =0x83; //Enable interrupt (INT0, TIMER0)
IP =0x00; //Set interrupt priority
TABLE=SONG0;
while(1)
{
Lignt( );
songsing();//Calling the pronunciation program
TR0 = 0;//Stop TIMER0
Delay2(1);
TABLE=SONG0 ;//Change song 0
songsing();
}
}