按键电路:第一次按下按键时,播放第一首歌曲;再一次按下按键时,播放第二首歌曲;第三次按下按键时,播放第三首歌曲;
源程序代码:
#include<reg51.h>
#define uchar unsigned char #define uint unsigned int sbit BEEP=P3^7; sbit KEY=P2^0; uint m=0;
//生日快乐歌的音符频率表,不同频率由不同的延时来决定 uchar
code
SONG_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}; //生日快乐歌节拍表,节拍决定每个音符的演奏长短 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};