51单片机实现蜂鸣器播放小星星

在中断的时候降了一个调,一开始没发现后面也懒得改了。

unsigned int code FreqTable[]=
	{
	63628,63731,63835,63928,64021,64103,64185,64260,64331,64400,64463,64528,//1
	64580,64633,64684,64732,64777,64820,64860,64898,64934,64968,65000,65030,
	65058,65085,65110,65134,65157,65178,65198,65217,65235,65252,65268,65283,
	0
	};
unsigned char select,MusicSelect;
unsigned char code Music[]=
{
12,
12,
19,
19,
21,
21,
19,
17,
17,
16,
16,
14,
14,
12,
16,
16,
15,
15,
14,
14,
13,
16,
16,
14,
14,
12,
16,
16,
15,
15,
14,
14,
13,
12,
12,
19,
19,
21,
21,
19,
17,
17,
16,
16,
14,
14,
12,
};
	Timer0_Init();
	while(1)
	{
			

			
			for(i=0;i<=20;i++)
			{
			select=Music[MusicSelect];
			MusicSelect++;
			Delay(500);
			TR0=0;
			Delay(5);
			TR0=1;
			}
			}
}
void Timer0_Routine() interrupt 1
{
	if(FreqTable[select])
	{
		TL0 = FreqTable[select]%256;
		TH0 = FreqTable[select]/256;
		Buzzer = !Buzzer;
		
	}
}	

你可能感兴趣的:(c语言,51单片机,嵌入式,嵌入式硬件,单片机)