中科因仑“3+1”工程特种兵精英论坛
标题:
实验23-播放一段音乐
[打印本页]
作者:
张衍波
时间:
2015-5-5 16:26
标题:
实验23-播放一段音乐
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit BEEP = P1^4;
uchar code SONG_TONE[]=
{
212,212,190,212,159,169,212,212,190,212,142,159,212,212,106,126,129,169,190,119,119,126,159,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 ms)
{
uchar t;
while(ms--)
{
for(t=0;t<120;t++);
}
}
void PlayMusic()
{
uint i =0,j,k;
while(SONG_LONG
!=0||SONG_TONE
!=0)
{
for(j=0;j<SONG_LONG
*20;j++)
{
BEEP = ~BEEP;
for(k=0;k<SONG_TONE
/3;k++);
}
DelayMS(10);
i++;
}
}
void main()
{
while(1)
{
PlayMusic();
DelayMS(500);
}
}
[attach]2678[/attach]
欢迎光临 中科因仑“3+1”工程特种兵精英论坛 (http://bbs.enlern.com/)
Powered by Discuz! X3.4