STC89C52單片機(jī)蜂鳴器唱歌實(shí)驗(yàn)
////////////////////////////////////////////////////////////////////////
#include
#define uchar unsigned char
#define uint
uchar cCount;
sbit FMQ =P2^4;
unsigned char code SONG[] ={
0x26,0x20,0x20,0x20,0x20,0x20,0x26,0x10,0x20,0x10,0x20,0x80,0x26,0x20,0x30,0x20,
0x30,0x20,0x39,0x10,0x30,0x10,0x30,0x80,0x26,0x20,0x20,0x20,0x20,0x20,0x1c,0x20,
0x20,0x80,0x2b,0x20,0x26,0x20,0x20,0x20,0x2b,0x10,0x26,0x10,0x2b,0x80,0x26,0x20,
0x30,0x20,0x30,0x20,0x39,0x10,0x26,0x10,0x26,0x60,0x40,0x10,0x39,0x10,0x26,0x20,
0x30,0x20,0x30,0x20,0x39,0x10,0x26,0x10,0x26,0x80,0x26,0x20,0x2b,0x10,0x2b,0x10,
0x2b,0x20,0x30,0x10,0x39,0x10,0x26,0x10,0x2b,0x10,0x2b,0x20,0x2b,0x40,0x40,0x20,
0x20,0x10,0x20,0x10,0x2b,0x10,0x26,0x30,0x30,0x80,0x18,0x20,0x18,0x20,0x26,0x20,
0x20,0x20,0x20,0x40,0x26,0x20,0x2b,0x20,0x30,0x20,0x30,0x20,0x1c,0x20,0x20,0x20,
0x20,0x80,0x1c,0x20,0x1c,0x20,0x1c,0x20,0x30,0x20,0x30,0x60,0x39,0x10,0x30,0x10,
0x20,0x20,0x2b,0x10,0x26,0x10,0x2b,0x10,0x26,0x10,0x26,0x10,0x2b,0x10,0x2b,0x80,
0x18,0x20,0x18,0x20,0x26,0x20,0x20,0x20,0x20,0x60,0x26,0x10,0x2b,0x20,0x30,0x20,
0x30,0x20,0x1c,0x20,0x20,0x20,0x20,0x80,0x26,0x20,0x30,0x10,0x30,0x10,0x30,0x20,
0x39,0x20,0x26,0x10,0x2b,0x10,0x2b,0x20,0x2b,0x40,0x40,0x10,0x40,0x10,0x20,0x10,
0x20,0x10,0x2b,0x10,0x26,0x30,0x30,0x80,0x00,
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,
};
////////////////////////////////////////////////////////////////////////
函數(shù)名稱(chēng):Time0_Init
函數(shù)功能:定時(shí)器的初始化配置,使其能中斷,中斷的時(shí)間間隔為10ms
參數(shù)介紹:無(wú)
返回值:
注意事項(xiàng):注意此時(shí)實(shí)驗(yàn)板上用到的晶振為11.0592M的,要選用其他的,得重新配置
////////////////////////////////////////////////////////////////////////
void Init_Time0()
{
}
////////////////////////////////////////////////////////////////////////
函數(shù)名稱(chēng):Time0_Routine
函數(shù)功能:定時(shí)器0中斷服務(wù)函數(shù),重新給定時(shí)器0賦值,同時(shí)把全局變量cCount加1
參數(shù)介紹:無(wú)
返回值:
注意事項(xiàng):無(wú)
////////////////////////////////////////////////////////////////////////
void Time0_Routine() interrupt 1 using 1
{
}
////////////////////////////////////////////////////////////////////////
函數(shù)名稱(chēng):DelayUs
函數(shù)功能:延時(shí)函數(shù),通過(guò)示波器測(cè)試,此函數(shù)每執(zhí)行一次大概能延時(shí)55us
參數(shù)介紹:iDelay_Us:執(zhí)行此延時(shí)函數(shù)的次數(shù)
返回值:
注意事項(xiàng):無(wú)
////////////////////////////////////////////////////////////////////////
void DelayUs(unsigned int iDelay_Us)
{
}
////////////////////////////////////////////////////////////////////////
函數(shù)名稱(chēng):FMQ_PlaySong
函數(shù)功能:控制實(shí)驗(yàn)板上與蜂鳴器相連的引腳輸出不同的頻率的方波,依次來(lái)控制蜂鳴
參數(shù)介紹:cNumber:歌曲的選擇,0代表“祝你平安”,‘1’代表“路邊的野花不要采”
返回值:
注意事項(xiàng):無(wú)
////////////////////////////////////////////////////////////////////////
void FMQ_PlaySong(unsigned char cNumber)
{
}
////////////////////////////////////////////////////////////////////////
函數(shù)名稱(chēng):main
函數(shù)功能:完成系統(tǒng)的初始化,讓實(shí)驗(yàn)板上的蜂鳴器不停循環(huán)的唱上面的兩首歌
參數(shù)介紹:無(wú)
返回值:
注意事項(xiàng):無(wú)
////////////////////////////////////////////////////////////////////////
void main()
{
}
評(píng)論