资源描述:
《51单片机源程序》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、#include#defineucharunsignedchar#defineuintunsignedint///数码管共阳ucharcodeDSY_Table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xbf};///音符对应的延时uintcodeTone_Delay_Table[]={64021,64103,64260,64400,64524,6458
2、0,64684,64777,64820,64898,64968,65030,65058,65110,65157,65178};sbitBEEP=P3^0;ucharKeyNo;//生日快乐歌的音符频率表,不同的频率用延时值来表示ucharcodeSONG_TONE[]={212,212,190,212,159,169,212,212,190,212,142,159,212,212,106,126,159,169,190,119,119,126,159,142,159,0};ucharcodeSON
3、G_LONG[]={9,3,12,12,12,24,9,3,12,12,12,24,9,3,12,12,12,12,12,9,3,12,12,12,24,0};///////delay------voidDelayMS(uintx){uchari;while(x--)for(i=0;i<120;i++);}voidPlayMusic(){uinti=0,j,k;while(SONG_LONG[i]!=0
4、
5、SONG_TONE[i]!=0){for(j=0;j6、){BEEP=~BEEP;for(k=0;k>=1;}KeyNo=k;}return;//r
7、eturn语句的加法很重要}//return;//KeyNo=k;}voidplay_Tone()interrupt1{TH0=Tone_Delay_Table[KeyNo]/256;TL0=Tone_Delay_Table[KeyNo]%256;BEEP=~BEEP;}//////MAIN/////////////////voidmain(){P3.7=0xbf;PlayMusic();DelayMS(1000);DelayMS(1000);TMOD=0x01;IE=0x82;while(1){
8、P1=0xff;if(P1!=0xff){Keys_SCAN();P0=DSY_Table[KeyNo];TR0=1;}else{TR0=0;}DelayMS(2);}}