Lt
D
/*生日快乐歌曲*/
#include <reg51.h>
#define uint unsigned int
#define uchar unsigned char
sbit beep = P1^5;
uchar code SONG_TONE[]={212,212,190,212,159,169,212, 212,190,212,142,159,
212,212,106,126,159,169,190,119,119,126,1 59,142,159,0};
uchar code SONG_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};
//延时
void DelayMS(uint x)
{
uchar t;
while(x--) for(t=0;t<120;t++);
}
void PlayMusic()
{
uint i=0,j,k;
while(SONG_LONG[i]!=0||SONG_TONE[i]!=0) { //播放各个音符,SONG_LONG 为拍子长度 for(j=0;j<SONG_LONG[i]*20;j++)
{
beep=~beep;
//SONG_TONE 延时表决定了每个音符的频率 for(k=0;k<SONG_TONE[i]/3;k++);
}
DelayMS(10);
i++;
}
}
void main()
{
beep=0;
while(1)
PlayMusic(); //播放生日快乐
DelayMS(500); //播放完后暂停一段时间
}
}
两只蝴蝶:
#include <reg51.h> // 这是单片机音乐代码生成器生成的代码
#define uchar unsigned char
sbit beepIO=P1^5; // 输出为 P1.5 可以修改成其它 IO 口
uchar m,n;
uchar code T[49][2]={{0,0},
{0xF8,0x8B},{0xF8,0xF2},{0xF9,0x5B},{0xF9 ,0xB7},{0xFA,0x14},{0xFA,0x66},{0xFA,0xB9 },{0xFB,0x03},{0xFB,0x4A},{0xFB,0x8F},{0x FB,0xCF},{0xFC,0x0B},
{0xFC,0x43},{0xFC,0x78},{0xFC,0xAB},{0xFC ,0xDB},{0xFD,0x08},{0xFD,0x33},{0xFD,0x5B },{0xFD,0x81},{0xFD,0xA5},{0xFD,0xC7},{0x FD,0xE7},{0xFE,0x05},快乐音乐
{0xFE,0x21},{0xFE,0x3C},{0xFE,0x55},{0xFE ,0x6D},{0xFE,0x84},{0xFE,0x99},{0xFE,0xAD },{0xFE,0xC0},{0xFE,0x02},{0xFE,0xE3},{0x FE,0xF3},{0xFF,0x02},
{0xFF,0x10},{0xFF,0x1D},{0xFF,0x2A},{0xFF ,0x36},{0xFF,0x42},{0xFF,0x4C},{0xFF,0x56 },{0xFF,0x60},{0xFF,0x69},{0xFF,0x71},{0x FF,0x79},{0xFF,0x81}
};
uchar code music[][2]={{0,4},
{23,4},{21,4},{23,16},{23,4},{21,4},{23,4 },{21,4},{19,16},{16,4},{19,4},{21,8},{21 ,4},{23,4},{21,4},{19,4},{16,4},{19,4},{1 4,24},
{23,4},{21,4},{23,16},{23,4},{21,4},{23,4 },{21,4},{19,24},{16,4},{19,4},{21,8},{21 ,4},{23,4},{21,4},{19,4},{16,4},{19,4},{2 1,24},
{23,4},{21,4},{23,16},{23,4},{21,4},{23,4 },{21,4},{19,16},{16,4},{19,4},{21,8},{21 ,4},{23,4},{21,4},{19,4},{16,4},{19,4},{1 4,24},
发布评论