20分换一个单片机音乐程序

要求:C51语言编的。自动播放音乐的。... 要求:C51语言编的。自动播放音乐的。 展开
 我来答
chinasndw
2009-08-01 · TA获得超过162个赞
知道答主
回答量:210
采纳率:0%
帮助的人:109万
展开全部
#include <AT89X52.H>
unsigned char Count;
sbit bee_Speak =P2^0 ; //蜂鸣器器控制脚

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,

};

void Time0_Init()
{
TMOD = 0x01;
IE = 0x82;
TH0 = 0xDC;
TL0 = 0x00; //11.0592MZ晶振,10ms
}

void Time0_Int() interrupt 1
{
TH0 = 0xDC;
TL0 = 0x00;
Count++; //长度加1
}

/*-------------------------------------------------
功能:1MS延时子程序
-------------------------------------------------*/
void Delay_xMs(unsigned int x)
{
unsigned int i,j;
for( i =0;i < x;i++ )
{
for( j =0;j<2;j++ );
}
}

/*-------------------------------------------------
功能:歌曲播放子程序i为播放哪一段曲目
-------------------------------------------------*/
void Play_Song(unsigned char i)
{
unsigned char Temp1,Temp2;
unsigned int Addr;
Count = 0; //中断计数器清0
Addr = i * 217;
while(1)
{
Temp1 = SONG[Addr++];
if ( Temp1 == 0xFF ) //休止符
{
TR0 = 0;
Delay_xMs(100);
}
else if ( Temp1 == 0x00 ) //歌曲结束符
{
return;
}
else
{
Temp2 = SONG[Addr++];
TR0 = 1;
while(1)
{
bee_Speak = ~bee_Speak;
Delay_xMs(Temp1);
if ( Temp2 == Count )
{
Count = 0;
break;
}
}
}
}
}
/*-------------------------------------------------
功能:主程序
-------------------------------------------------*/
void main()
{
Time0_Init(); //定时器0中断初始化
while(1)
{
Play_Song(1); //播放//0改作1可播放第二首歌曲
}
}
你去试试!
船长2124
2009-08-01 · 超过15用户采纳过TA的回答
知道答主
回答量:110
采纳率:0%
帮助的人:36万
展开全部
;两只老虎音乐(用P1.0 口驱动一扬声器)

org 0000h
ljmp main

org 000bh
ljmp tim0

org 0030h
main: mov th0,#0a0h
mov tl0,#0ffh
setb et0
mov tmod,#01h
setb ea
setb tr0

loop:
mov 40h,#0fch
mov 41h,#44h ;1
lcall dely

mov 40h,#0fch ; 2
mov 41h,#0ach
lcall dely

mov 40h,#0fdh
mov 41h,#09h ;3
lcall dely

mov 40h,#0fch
mov 41h,#44h ;1
lcall dely

clr ea
lcall delyy
setb ea

mov 40h,#0fch
mov 41h,#44h ;1
lcall dely

mov 40h,#0fch ;2
mov 41h,#0ach
lcall dely

mov 40h,#0fdh
mov 41h,#09h ;3
lcall dely

mov 40h,#0fch
mov 41h,#44h ;1
lcall dely
lcall dely

clr ea
lcall delyy
setb ea

mov 40h,#0fdh
mov 41h,#09h ;3
lcall dely

mov 40h,#0fdh
mov 41h,#34h ;4
lcall dely

mov 40h,#0fdh
mov 41h,#82h ;5-
lcall dely
lcall dely

clr ea
lcall delyy
setb ea

mov 40h,#0fdh
mov 41h,#82h ;/5
lcall delyy

mov 40h,#0fdh ; /6
mov 41h,#0c7h
lcall delyy

mov 40h,#0fdh
mov 41h,#82h ;/5
lcall delyy

mov 40h,#0fdh
mov 41h,#034h ;/4
lcall delyy

mov 40h,#0fdh
mov 41h,#09h ;3
lcall dely

mov 40h,#0fch
mov 41h,#44h ;1
lcall dely

clr ea
lcall delyy
setb ea

mov 40h,#0fdh
mov 41h,#82h ;/5
lcall delyy

mov 40h,#0fdh ; /6
mov 41h,#0c7h
lcall delyy

mov 40h,#0fdh
mov 41h,#82h ;/5
lcall delyy

mov 40h,#0fdh
mov 41h,#034h ;/4
lcall delyy

mov 40h,#0fdh
mov 41h,#09h ;3
lcall dely

mov 40h,#0fch
mov 41h,#44h ;1
lcall dely

clr ea
lcall delyy
setb ea

mov 40h,#0fch
mov 41h,#44h ;1
lcall dely

mov 40h,#0f6h
mov 41h,#08h ;.5
lcall dely

mov 40h,#0fch
mov 41h,#44h ;1-
lcall dely
lcall dely

clr ea
lcall dely
setb ea
ljmp loop

delyy: mov r5,#02
d0: mov r7,#080h
d1: mov r6,#0dfh
d2: djnz r6,d2
djnz r7,d1
djnz r5,d0
ret

dely: mov r5,#02
d00: mov r7,#0ffh
d11: mov r6,#0dfh
d22: djnz r6,d22
djnz r7,d11
djnz r5,d00
ret

tim0: mov th0,40h
mov tl0,41h
cpl p1.0
reti

end
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式