求单片机LED灯闪烁生日快乐代码。谢谢

2022-04-21 娱乐 160阅读
生日快乐歌曲C代码

#include
#defineuintunsignedint
#defineucharunsignedchar
sbitbeep=P1^5;
ucharcodeSONG_TONE[]={212,212,190,212,159,169,212,212,190,212,142,159,
212,212,106,126,159,169,190,119,119,126,159,142,159,0};

ucharcodeSONG_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};

//延时
voidDelayMS(uintx)
{
uchart;
while(x--)for(t=0;t<120;t++);
}

voidPlayMusic()
{
uinti=0,j,k;
while(SONG_LONG[i]!=0||SONG_TONE[i]!=0)
{//播放各个音符,SONG_LONG为拍子长度
for(j=0;j{
beep=~beep;
//SONG_TONE延时表决定了每个音符的频率
for(k=0;k}
DelayMS(10);
i++;
}
}

voidmain()
{

beep=0;
while(1)
{
PlayMusic();//播放生日快乐
DelayMS(500);//播放完后暂停一段时间
}
}
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com