单片机 音乐盒程序

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

单片机能播放三首音乐的音乐盒程序C语言

#include

#define uchar unsigned char

#define uint unsigned int

char a;

sbit BEEP=P2^0;

sbit BEEP1=P2^1;

sbit BEEP2=P2^2;

sbit P27=P2^7;

sbit P26=P2^6;

sbit P25=P2^5;

uchar note;

uchar *music_p;

uchar code scales[]=

{

0xFF,0xFF,0xFB,0x90,0xFC,0x0C,0xFC,0x44,0xFC,0xAC,

0xFD,0x09,0xFD,0x34,0xFD,0x82,0xFD,0xFD,0xC8,0xFE,0x06, 0xFE,0x22,0xFA,0X15,0XFB,0x04,0xFA,0x67,0xFE,0x85

};

uchar code XinXinXiangYing[]=

{

0x24,0x14,0x24,0xc4,0x54,0x54,0x48,0x04,0x54,0x44,

0x34,0x22,0x14,0xb2,0xc8,0x04,0x12,0xc2,0x16,0x12,

0x76,0x52,0x46,0x12,0x3f,0x04,0xb4,0xd4,0xc4,0x14,

0x28,0xc4,0x14,0x12,0x32,0x16,0xc2,0x54,0x78,0x34,

0x4c,0x42,0x52,0x86,0x74,0x76,0x52,0x74,0x28,0x44,

0x52,0x46,0x11,0x26,0x12,0xcf,0x04,0x24,0x14,0xc4,

0x56,0x52,0x48,0x04,0x54,0x44,0x34,0x22,0x14,0xb2,

0x74,0x52,0x34,0x3f,0xff

};

uchar code QiDao[]=

{

0xc4,0x14,0x32,0x44,0x44,0x52,0x52,0x44,0x32,0x32,

0x14,0x14,0x12,0x12,0x32,0x42,0x54,0x54,0x4f,0xc4,

0x12,0x32,0x44,0x42,0x72,0x58,0x42,0x32,0x34,0x14,

0x12,0x01,0x01,0x01,0x1f,0xff

};

uchar code LanHuaCao[]=

{

0x22,0x52,0x52,0x56,0x56,0x42,0x32,0x42,0x32,0x42,0x32,0x22, 0x18,0x82,0x82,0x82,0x82,0x82,0x82,0x86,0x72,0xb2,0x72,0x72, 0x62,0x58,0x52,0x82,0x82,0x72,0x56,0x42,0x32,0x42,

0x32,0x22,0x16,0xb2,0xb2,0x32,0x32,0x22,0x16,0x51,

0x42,0x31,0x21,0xc1,0x88,0xff

};

void delay(uint i)

{

uchar j;

for(;i>0;i--)

for(j=110;j>0;j--);

}

void playMusic()

{

uchar i,j,k;

music_p=XinXinXiangYing;

while(*(music_p+j)!=0xff)

{

k=*(music_p+j)&0x0F;

note=*(music_p+j)>>4;

TH0=scales[2*note];

TL0=scales[2*note+1];

TR0=1;

if((scales[2*note]==0xff)&(scales[2*note+1]==0xff))

{

TR0=0;

}

for(i=k;i>0;--i)

{

delay(187);

}

TR0=0;

j++;

}

BEEP=1;

} void playMusic1()

{

uchar i,j,k;

music_p=QiDao;

while(*(music_p+j)!=0xff)

{

k=*(music_p+j)&0x0F;

note=*(music_p+j)>>4;

TH0=scales[2*note];

TL0=scales[2*note+1];

TR0=1;

if((scales[2*note]==0xff)&(scales[2*note+1]==0xff)) {

TR0=0;

}

for(i=k;i>0;--i)

{

delay(187);

}

TR0=0;

j++;

}

BEEP1=1;

}

void playMusic2()

{

uchar i,j,k;

music_p=LanHuaCao;

while(*(music_p+j)!=0xff)

{

k=*(music_p+j)&0x0F;

相关文档
最新文档