You can find it online and see for yourself
#include
sbit SPK=P1^2;
unsigned char Timer0_H,Timer0_L,Time;
code unsigned char MUSIC[]={ 0,0,6,1, 5,6,1,1, 5,6,4,3, 2,2 ,2,5, 5,2,4,3, 1,2,4,4, 6,1,2,4 };
code unsigned char FREQH[]={
< p> 0xF2,0xF3,0xF5,0xF5,0xF6,0xF7,0xF8,0xF9,0xF9,0xFA,0xFA,0xFB,0xFB,0xFC,0xFC, //1,2,3,4,5 ,6,7,8,i
0xFC,0xFD,0xFD,0xFD,0xFD,0xFE,
0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFF,
p>} ;
// Lower eight digits of the scale frequency table
code unsigned char FREQL[]={
0x42,0xC1,0x17, 0xB6,0xD0,0xD1,0xB6,
0x21,0xE1,0x8C,0xD8,0x68,0xE9,0x5B,0x8F, //1,2,3,4,5,6,7,8,i
0xEE,0x44, 0x6B,0xB4,0xF4,0x2D, ??
0x47,0x77,0xA2,0xB6,0xDA,0xFA,0x16,
};< /p>
void DelayUs2x(unsigned char t)
{
while(--t);
}
void DelayMs(unsigned char t)
{
while(t--)
{
//Approximate delay 1mS< /p>
DelayUs2x(245);
DelayUs2x(245);
}
}
/*-- --------------------------------------------------
Beat delay function
Adjust 1/4 beat time:
Adjust 4/4 125ms
Adjust 2/4 250ms
Adjust 3/4 187ms
---------------------------------- -------------*/
void delay(unsigned char t)
{
unsigned char i; p>
for(i=0;i DelayMs(250); TR0=0; } p> void TIM0_ISR() interrupt 1 { TR0=0; SPK=!SPK; TH0 =Timer0_H; TL0=Timer0_L; TR0=1; } void Song() { TH0=Timer0_H;//Assign timer time to determine frequency TL0=Timer0_L; TR0=1; //Open timer< /p> delay(Time); //The beat required for delay } void main(void) { unsigned char k,i; TMOD|=0x01; EA=1; ET0=1; while(1) { i=0; while(i<100) {
Timer0_H=FREQH[k];
Timer0_L=FREQL[k];
p>Time=MUSIC[i+2];
i=i+3;
Song();
}
}
}