功能:按一下开关后,单片机控制蜂鸣器唱生日快乐歌曲
PROTEUS 和51单片机教程
/*
生日歌
*/
#include
typedef unsigned char uint8;
typedef unsigned int uint16;
sbit K1 = P1^0;
sbit BUZZER = P3^0;
code uint8 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
};
code uint8 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 delay(uint16 x)
{
uint16 i,j;
for(i = x; i > 0; i --)
for(j = 114; j > 0; j --);
}
void PlayMusic()
{
uint16 i =0,j,k;
while(SONG_LONG[i]!=0||SONG_TONE[i]!=0)
{
for(j=0;j
BUZZER = ~BUZZER;
for(k=0;k
delay(10);
i++;
}
}
void main()
{
P1 = 0xFF;
while(1)
{
if(K1==1)
{
PlayMusic();
delay(1000);
}
}
}
最后,如果有什么意见或者建议欢迎您留言给我,让我们共同学习一起进步,
如果需要 软件或者视频教程,例程,请在下方留言或者私信我,看到后会第一时间回复。
谢谢!