/*****************单片机唱歌,刀郎的,song[]中可改歌谱***********************************/#includereg51.hsbitSPK=P3^7;voiddelayms(unsignedcharms);unsignedintdataj;unsignedcharcodesong[636]={0xFF,0xFF,4,0xFd,0x08,2,0xFd,0x08,2,0xFd,0x08,2,0xFd,0x08,2,0xFd,0x08,2,0xfd,0x08,2,//210xFD,0x5B,4,0xFD,0x08,2,0xFC,0xAB,2,0xFC,0x0B,2,0xFC,0x0B,2,0xff,0xff,2,0xFc,0x0B,2,//210xFC,0xAB,2,0xFC,0xAB,2,0xFC,0xAB,2,0xFC,0xAB,2,0xFC,0xAB,4,0xFC,0xAB,2,0xFC,0xAB,2,//210xFB,0x8F,2,0xFC,0x0B,2,0xFC,0x0B,4,0xff,0xff,8,//120xff,0xff,2,0xFD,0x08,2,0xFD,0x08,2,0xFD,0x08,2,0xFD,0x08,4,0xFD,0x08,2,0xFD,0x08,2,//210xFD,0x5B,4,0xFD,0x08,2,0xFC,0xAB,4,0xFD,0x08,6,//120xff,0xff,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x03,2,0xFA,0x14,2,//240xFC,0xAB,4,0xFC,0xAB,2,0xFC,0xAB,2,0xFC,0xAB,2,0xFC,0x0B,2,0xFC,0x0B,4,//180xFF,0xFF,4,0xFD,0x08,2,0xFD,0x08,2,0xFD,0x08,2,0xFD,0x08,2,0xFD,0x08,2,0xFD,0x08,2,//210xFD,0x5B,4,0xFD,0x08,2,0xFC,0xAB,4,0xFD,0x08,6,//12,1830xFF,0xFF,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x03,2,0xFA,0x14,2,//240xFC,0xAB,4,0xFC,0xAB,2,0xFC,0xAB,2,0xFC,0xAB,2,0xFC,0x0B,2,0xFC,0x0B,4,//180xFF,0xFF,4,0xFd,0x08,2,0xFd,0x08,2,0xFd,0x08,2,0xFd,0x08,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5b,1,0xf8,0x2a,2,0xf8,0x2a,4,//240xff,0xff,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x03,2,0xFA,0x14,2,//240xfb,0x8f,2,0xfc,0x08,2,0xfc,0x08,2,0xfc,0x08,10,//120xff,0xff,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x03,2,0xFA,0x14,2,//240xfb,0x03,2,0xfb,0x03,2,0xfb,0x03,2,0xfa,0x14,2,0xfa,0x14,1,0xf9,0x5b,1,0xf8,0x2a,2,0xf8,0x2a,4,//24,2070xff,0xff,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x03,2,0xFA,0x14,2,//240xfc,0xab,2,0xfd,0x08,2,0xfd,0x08,2,0xfd,0x08,2,0xff,0xff,4,0xff,0xff,4};//18,42,636voidmain(){TMOD=0x01;IE=0x82;while(1){j=0;while(j636){TR0=1;if((song[j]==0xff)&&(song[j+1]==0xff))TR0=0;//休止符用0xff,0xff表示,出现休止符时CT0禁止,不发声.delayms(song[j+2]);//每一音符唱多长.j=j+3;}}}voidtimer0()interrupt1using1//每一音符唱多高{TH0=song[j];TL0=song[j+1];SPK=!SPK;}voiddelayms(unsignedcharms)//基本延时子程序(16分之1拍的时间){unsignedinti;while(ms--){for(i=0;i20300;i++);}TR0=0;}