#include<STC15F2K60S2.h>
unsigned char n=0; //n???????
unsigned char code music_tab[] ={
0x18, 0x30, 0x1C , 0x10, //???: ????, ????, ????, ????,
0x20, 0x40, 0x1C , 0x10,
0x18, 0x10, 0x20 , 0x10,
0x1C, 0x10, 0x18 , 0x40,
0x1C, 0x20, 0x20 , 0x20,
0x1C, 0x20, 0x18 , 0x20,
0x20, 0x80, 0xFF , 0x20,
0x30, 0x1C, 0x10 , 0x18,
0x20, 0x15, 0x20 , 0x1C,
0x20, 0x20, 0x20 , 0x26,
0x40, 0x20, 0x20 , 0x2B,
0x20, 0x26, 0x20 , 0x20,
0x20, 0x30, 0x80 , 0xFF,
0x20, 0x20, 0x1C , 0x10,
0x18, 0x10, 0x20 , 0x20,
0x26, 0x20, 0x2B , 0x20,
0x30, 0x20, 0x2B , 0x40,
0x20, 0x20, 0x1C , 0x10,
0x18, 0x10, 0x20 , 0x20,
0x26, 0x20, 0x2B , 0x20,
0x30, 0x20, 0x2B , 0x40,
0x20, 0x30, 0x1C , 0x10,
0x18, 0x20, 0x15 , 0x20,
0x1C, 0x20, 0x20 , 0x20,
0x26, 0x40, 0x20 , 0x20,
0x2B, 0x20, 0x26 , 0x20,
0x20, 0x20, 0x30 , 0x80,
0x20, 0x30, 0x1C , 0x10,
0x20, 0x10, 0x1C , 0x10,
0x20, 0x20, 0x26 , 0x20,
0x2B, 0x20, 0x30 , 0x20,
0x2B, 0x40, 0x20 , 0x15,
0x1F, 0x05, 0x20 , 0x10,
0x1C, 0x10, 0x20 , 0x20,
0x26, 0x20, 0x2B , 0x20,
0x30, 0x20, 0x2B , 0x40,
0x20, 0x30, 0x1C , 0x10,
0x18, 0x20, 0x15 , 0x20,
0x1C, 0x20, 0x20 , 0x20,
0x26, 0x40, 0x20 , 0x20,
0x2B, 0x20, 0x26 , 0x20,
0x20, 0x20, 0x30 , 0x30,
0x20, 0x30, 0x1C , 0x10,
0x18, 0x40, 0x1C , 0x20,
0x20, 0x20, 0x26 , 0x40,
0x13, 0x60, 0x18 , 0x20,
0x15, 0x40, 0x13 , 0x40,
0x18, 0x80, 0x00
};
void int0() interrupt 1 //????0 ????
{ TH0=0xd8;
TL0=0xef;
n--;
}
void delay (unsigned char m) //??????
{
unsigned i=3*m;
while(--i);
}
void delayms(unsigned char a) //???????
{
while(--a); //??while(--a) ????while(a--); ?????????????????!
}
void allinit()
{
P2=0x80;
P0=0xff;
P2=0xa0;
P0=0x00;
P2=0x00;
}
void fengmingqikai()
{
P2=0xa0;
P0=0x40;
P2=0x00;
}
void main()
{
unsigned char p,m; //m???????
unsigned char i=0;
bit qq;
TMOD&=0x0f;
TMOD|=0x01;
TH0=0xd8;TL0=0xef;
IE=0x82;
play:
while(1)
{
a: p=music_tab[i];
if(p==0x00) { i=0, delayms(1000); goto play;} //???????,??1?,????????
else if(p==0xff) { i=i+1;delayms(100),TR0=0; goto a;} //??????,??100ms,???????
else {m=music_tab[i++], n=music_tab[i++];} //????? ? ????
TR0=1; //????1
while(n!=0) {
qq=~qq;
{
if(qq==0)
{
fengmingqikai();
}
else
{
allinit();
}
}
delay(m);
} //??????, ??P1?????(?????!)
TR0=0; //????1
}
}