Happy Birthday Song Based on Single Chip Microcomputer

Publisher:快乐的天使Latest update time:2020-03-23 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#include 

#define uchar unsigned char 

#define uint unsigned int 

sbit BEEP=P3^7; 

//Happy Birthday song note frequency table, different frequencies are determined by different delays

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

//Happy Birthday song beat chart, the beat determines the playing length of each note

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

//Delay

void DelayMS(uint x) 

flying t; 

while(x--) for(t=0;t<120;t++); 

//Play function

void PlayMusic() 

{   uint i=0,j,k; 

while(SONG_LONG[i]!=0||SONG_TONE[i]!=0) 

{ //Play each note, SONG_LONG is the beat length 

for(j=0;j

BEEP=~BEEP; 

//SONG_TONE delay table determines the frequency of each note 

for(k=0;k

DelayMS(10); 

i++; 

void main() 

BEEP=0; 

while(1) 

PlayMusic(); //Play Happy Birthday 

DelayMS(500); //Pause for a while after playing 

}

Reference address:Happy Birthday Song Based on Single Chip Microcomputer

Previous article:Microcontroller - Buzzer (Happy Birthday)
Next article:51 single chip microcomputer realizes the birthday song

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号