首页 > 其他分享 >基于51单片机的电子琴设计

基于51单片机的电子琴设计

时间:2024-03-15 16:00:12浏览次数:19  
标签:0x19 0x17 0x16 51 0x02 0x03 单片机 电子琴 0x1A

基于51单片机的电子琴设计

(仿真+程序+原理图+设计报告)

功能介绍

具体功能:

1.利用所给键盘的1,2,3,4,5,6,7,8八个键,能够发出8个不同的音调

2.有3个按键可以分别播放3首歌曲

3.歌曲名《挥着翅膀的女孩》《同一首歌》《两只蝴蝶》

​演示视频:

<iframe allowfullscreen="true" data-mediaembed="bilibili" frameborder="0" id="nmHwnQy0-1710422334334" src="https://player.bilibili.com/player.html?aid=528308365"></iframe>

基于51单片机的电子琴设计 音乐播放器

/*******51单片机简易电子琴 八音盒 设计***********/
/*********do re mi fa so la si 高音do************/
/******************内置3首歌*********************/
/***《挥着翅膀的女孩》《同一首歌》《两只蝴蝶》***/

/********************原创设计********************/

#include <REGX52.H>			//调系统头文件

#define uchar unsigned char	//uchar代替 unsigned char
#define uint unsigned int	//uint代替 unsigned char
	
#define Key1	P2_0	//定义按键1(播放 "挥着翅膀的女孩")
#define	Key2	P2_1	//定义按键2(播放 "同一首歌")
#define Key3	P2_2	//定义按键3(播放 "两只蝴蝶")

#define SMG		P0		//定义数码管显示端
#define	Speak	P2_4	//定义蜂鸣器接口

uchar sth,stl;    		//定义全局变量 sth stl
uint i,j;				//定义循环变量i

uchar code table[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,
					0x88,0x83,0xC6,0xA1,0x86,0x8E};//定义数码管显示 0-9,A-F


uchar code Music_hzcb[]={//《挥着翅膀的女孩》系统自带歌曲音符
	0x17,0x02, 0x17,0x03, 0x18,0x03, 0x19,0x02, 0x15,0x03,
    0x16,0x03, 0x17,0x03, 0x17,0x03, 0x17,0x03, 0x18,0x03,
	0x19,0x02, 0x16,0x03, 0x17,0x03, 0x18,0x02, 0x18,0x03,
    0x17,0x03, 0x15,0x02, 0x18,0x03, 0x17,0x03, 0x18,0x02,
    0x10,0x03, 0x15,0x03, 0x16,0x02, 0x15,0x03, 0x16,0x03,
    0x17,0x02, 0x17,0x03, 0x18,0x03, 0x19,0x02, 0x1A,0x03,
    0x1B,0x03, 0x1F,0x03, 0x1F,0x03, 0x17,0x03, 0x18,0x03,
    0x19,0x02, 0x16,0x03, 0x17,0x03, 0x18,0x03, 0x17,0x03,
    0x18,0x03, 0x1F,0x03, 0x1F,0x02, 0x16,0x03, 0x17,0x03,
    0x18,0x03, 0x17,0x03, 0x18,0x03, 0x20,0x03, 0x20,0x02,
    0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x20,0x03, 0x21,0x03,
    0x20,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x1F,0x03,
    0x1B,0x03, 0x19,0x03, 0x19,0x03, 0x15,0x03, 0x1A,0x66,
    0x1A,0x03, 0x19,0x03, 0x15,0x03, 0x15,0x03, 0x17,0x03,
    0x16,0x66, 0x17,0x04, 0x18,0x04, 0x18,0x03, 0x19,0x03,
    0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x20,0x03, 0x21,0x03,
    0x20,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x1F,0x03,
    0x1B,0x03, 0x19,0x03, 0x19,0x03, 0x15,0x03, 0x1A,0x66,
    0x1A,0x03, 0x19,0x03, 0x19,0x03, 0x1F,0x03, 0x1B,0x03,
    0x1F,0x00, 0x1A,0x03, 0x1A,0x03, 0x1A,0x03, 0x1B,0x03,
    0x1B,0x03, 0x1A,0x03, 0x19,0x03, 0x19,0x02, 0x17,0x03,
    0x15,0x17, 0x15,0x03, 0x16,0x03, 0x17,0x03, 0x18,0x03,
    0x17,0x04, 0x18,0x0E, 0x18,0x03, 0x17,0x04, 0x18,0x0E,
    0x18,0x66, 0x17,0x03, 0x18,0x03, 0x17,0x03, 0x18,0x03,
    0x20,0x03, 0x20,0x02, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66,
    0x20,0x03, 0x21,0x03, 0x20,0x03, 0x1F,0x03, 0x1B,0x03,
    0x1F,0x66, 0x1F,0x04, 0x1B,0x0E, 0x1B,0x03, 0x19,0x03,
    0x19,0x03, 0x15,0x03, 0x1A,0x66, 0x1A,0x03, 0x19,0x03,
    0x15,0x03, 0x15,0x03, 0x17,0x03, 0x16,0x66, 0x17,0x04,
    0x18,0x04, 0x18,0x03, 0x19,0x03, 0x1F,0x03, 0x1B,0x03,
    0x1F,0x66, 0x20,0x03, 0x21,0x03, 0x20,0x03, 0x1F,0x03,
    0x1B,0x03, 0x1F,0x66, 0x1F,0x03, 0x1B,0x03, 0x19,0x03,
    0x19,0x03, 0x15,0x03, 0x1A,0x66, 0x1A,0x03, 0x19,0x03,
    0x19,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x00, 0x18,0x02,
    0x18,0x03, 0x1A,0x03, 0x19,0x0D, 0x15,0x03, 0x15,0x02,
    0x18,0x66, 0x16,0x02, 0x17,0x02, 0x15,0x00, 0xff,0xff}; 
     
uchar code Music_tyshg[]={//《同一首歌》 系统自带歌曲音符
	0x0F,0x01, 0x15,0x02, 0x16,0x02, 0x17,0x66, 0x18,0x03,
    0x17,0x02, 0x15,0x02, 0x16,0x01, 0x15,0x02, 0x10,0x02,
    0x15,0x00, 0x0F,0x01, 0x15,0x02, 0x16,0x02, 0x17,0x02,
    0x17,0x03, 0x18,0x03, 0x19,0x02, 0x15,0x02, 0x18,0x66,
    0x17,0x03, 0x19,0x02, 0x16,0x03, 0x17,0x03, 0x16,0x00,
    0x17,0x01, 0x19,0x02, 0x1B,0x02, 0x1B,0x70, 0x1A,0x03,
    0x1A,0x01, 0x19,0x02, 0x19,0x03, 0x1A,0x03, 0x1B,0x02,
    0x1A,0x0D, 0x19,0x03, 0x17,0x00, 0x18,0x66, 0x18,0x03,
    0x19,0x02, 0x1A,0x02, 0x19,0x0C, 0x18,0x0D, 0x17,0x03,
    0x16,0x01, 0x11,0x02, 0x11,0x03, 0x10,0x03, 0x0F,0x0C,
    0x10,0x02, 0x15,0x00, 0x1F,0x01, 0x1A,0x01, 0x18,0x66,
    0x19,0x03, 0x1A,0x01, 0x1B,0x02, 0x1B,0x03, 0x1B,0x03,
    0x1B,0x0C, 0x1A,0x0D, 0x19,0x03, 0x17,0x00, 0x1F,0x01,
    0x1A,0x01, 0x18,0x66, 0x19,0x03, 0x1A,0x01, 0x10,0x02,
    0x10,0x03, 0x10,0x03, 0x1A,0x0C, 0x18,0x0D, 0x17,0x03,
    0x16,0x00, 0x0F,0x01, 0x15,0x02, 0x16,0x02, 0x17,0x70,
    0x18,0x03, 0x17,0x02, 0x15,0x03, 0x15,0x03, 0x16,0x66,
    0x16,0x03, 0x16,0x02, 0x16,0x03, 0x15,0x03, 0x10,0x02,
    0x10,0x01, 0x11,0x01, 0x11,0x66, 0x10,0x03, 0x0F,0x0C,
    0x1A,0x02, 0x19,0x02, 0x16,0x03, 0x16,0x03, 0x18,0x66,
    0x18,0x03, 0x18,0x02, 0x17,0x03, 0x16,0x03, 0x19,0x00,
    0xff,0xff };
                                
uchar code Music_lzhhd[] ={//《两只蝴蝶》系统自带歌曲音符
	0x17,0x03, 0x16,0x03, 0x17,0x01, 0x16,0x03, 0x17,0x03,
    0x16,0x03, 0x15,0x01, 0x10,0x03, 0x15,0x03, 0x16,0x02,
    0x16,0x0D, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x10,0x03,
    0x10,0x0E, 0x15,0x04, 0x0F,0x01, 0x17,0x03, 0x16,0x03,
    0x17,0x01, 0x16,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x01,
	0x10,0x03, 0x15,0x03, 0x16,0x02, 0x16,0x0D, 0x17,0x03,
	0x16,0x03, 0x15,0x03, 0x10,0x03, 0x15,0x03, 0x16,0x01,
	0x17,0x03, 0x16,0x03, 0x17,0x01, 0x16,0x03, 0x17,0x03,
	0x16,0x03, 0x15,0x01, 0x10,0x03, 0x15,0x03, 0x16,0x02,
	0x16,0x0D, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x10,0x03,
	0x10,0x0E, 0x15,0x04, 0x0F,0x01, 0x17,0x03, 0x19,0x03,
	0x19,0x01, 0x19,0x03, 0x1A,0x03, 0x19,0x03, 0x17,0x01,	
	0x16,0x03, 0x16,0x03, 0x16,0x02, 0x16,0x0D, 0x17,0x03,
	0x16,0x03, 0x15,0x03, 0x10,0x03, 0x10,0x0D, 0x15,0x00,
	0x19,0x03, 0x19,0x03, 0x1A,0x03, 0x1F,0x03, 0x1B,0x03,
	0x1B,0x03, 0x1A,0x03, 0x17,0x0D, 0x16,0x03, 0x16,0x03,
	0x16,0x0D, 0x17,0x01, 0x17,0x03, 0x17,0x03, 0x19,0x03,
	0x1A,0x02, 0x1A,0x02, 0x10,0x03, 0x17,0x0D, 0x16,0x03,
	0x16,0x01, 0x17,0x03, 0x19,0x03, 0x19,0x03, 0x17,0x03,
	0x19,0x02, 0x1F,0x02, 0x1B,0x03, 0x1A,0x03, 0x1A,0x0E,
	0x1B,0x04, 0x17,0x02, 0x1A,0x03, 0x1A,0x03, 0x1A,0x0E,
	0x1B,0x04, 0x1A,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03,
	0x17,0x0D, 0x16,0x03, 0x17,0x03, 0x19,0x01, 0x19,0x03,
	0x19,0x03, 0x1A,0x03, 0x1F,0x03, 0x1B,0x03, 0x1B,0x03,
	0x1A,0x03, 0x17,0x0D, 0x16,0x03, 0x16,0x03, 0x16,0x03,
	0x17,0x01, 0x17,0x03, 0x17,0x03, 0x19,0x03, 0x1A,0x02,
	0x1A,0x02, 0x10,0x03, 0x17,0x0D, 0x16,0x03, 0x16,0x01,
	0x17,0x03, 0x19,0x03, 0x19,0x03, 0x17,0x03, 0x19,0x03,
	0x1F,0x02, 0x1B,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04,
	0x17,0x02, 0x1A,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04,
	0x17,0x16, 0x1A,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04,
	0x1A,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03, 0x0F,0x02,
	0x10,0x03, 0x15,0x00, 0xff,0xff };
  
uchar code Music_Code[]={ 		//八个音符	do re mi fa so la si 高音do 
	0xf8,0x8b,0xf9,0x5b,0xfa,0x14,0xfa,0x66,
	0xfb,0x03,0xfb,0x8f,0xfc,0x0b,0xfd,0xee};									  
uchar const yinfu1[3][14]={		//低中高三种音符
	0xf8,0x8b,0xf9,0x5b,0xfa,0x14,0xfa,0x66,0xfb,0x03,0xfb,0x8f,0xfc,0x0b,
	0xfc,0x43,0xfc,0xab,0xfd,0x08,0xfd,0x33,0xfd,0x81,0xfd,0xc7,0xfe,0x05,
	0xfb,0x21,0xfe,0x55,0xfe,0x84,0xfe,0x99,0xfe,0xc0,0xfe,0xe3,0xff,0x02};
uchar const length[]={1,2,4,8,16,32,64};	//几分音符查表(节拍)


void delay_ms(uint time)	//毫秒延时函数
{
	uint z;
	uchar x,y;
	for(z=0;z<time;z++)
	for(x=5;x>0;x--)
	for(y=97;y>0;y--); 
}

void Time0_Init()			//定时器T0初始化函数		
{
	TMOD=0x01;	//工作方式1
	TH0=sth;    //定时器高八位赋初值     
	TL0=stl;	//定时器低八位赋初值
	ET0=1;		//使能T0中断
	EA=1;		//打开全局中断
	TR0=0;		//关闭定时器T0
} 

void main() 	//主函数入口
{
	Time0_Init();	//定时器T0初始化
	Speak=1;		//蜂鸣器端口置1 (让蜂鸣器处于与电源5V断电状态)
	while(1)	//无限循环	
	{
		switch(P1)		//switch语句判断检测 P1按键状态
		{  
			case 0xfe:	//P1=0xfe    "do"按键按下 			
						delay_ms(10);	//延时去抖	
						if(P1==0xfe)	//再判断"do"按键是否按下
						{				
							SMG=table[1];	//数码管显示"1"	
							i=0;			//i置0
		                    TR0=0;  		//关闭定时器T0
							sth=Music_Code[2*i];	//定时器高八位赋值 "do"
						    stl=Music_Code[2*i+1];	//定时器低八位赋值 "do"
							TR0=1;			//启动定时器T0
							for(j=0;j<=1000;j++)	//软件延时,在一定时间里检测
							{							 				
								delay_ms(10);		//延时一下
								if(P1==0xfe) continue;	//"do"按键按下,跳出(继续发音)
								else break;			//松开了,则返回
							}
							SMG=0xff;	//关闭数码管显示
							Speak=1;	//蜂鸣器端口置1 (让蜂鸣器处于与电源5V断电状态)
							TR0=0;		//关闭定时器T0
							for(;;)	
							{
								while(P1==0xfe);	//等待按键松开									 				
								delay_ms(10);		//延时去抖
								if(P1==0xfe) continue;	
								else break;			//确定松开,退出
							}
							TR0=0;		//关闭定时器T0
						}
						break;			//返回
			case 0xfd:	//P1=0xfd	"re"按键按下 		
						delay_ms(10);	//延时去抖
						if(P1==0xfd)	//再判断"re"按键是否按下
			        	{
							SMG=table[2];	//数码管显示"2"
							i=1;			//i置1
							TR0=0;  		//关闭定时器T0
							sth=Music_Code[2*i];	//定时器高八位赋值 "re"
							stl=Music_Code[2*i+1];	//定时器低八位赋值 "re"
							TR0=1;			//启动定时器T0		
							for(j=0;j<=1000;j++)	//软件延时,在一定时间里检测
							{									 				
								delay_ms(10);	//延时一下	
								if(P1==0xfd) continue;	//"re"按键按下,跳出(继续发音)	
								else break;		//松开了,则返回
							}
							SMG=0xff;	//关闭数码管显示
							Speak=1;	//蜂鸣器端口置1 (让蜂鸣器处于与电源5V断电状态)
							TR0=0;		//关闭定时器T0
							for(;;)
							{
								while(P1==0xfd);	//等待按键松开
								delay_ms(10);		//延时去抖
								if(P1==0xfd) continue;	
								else break;			//确定松开,退出
							}
						}
						TR0=0;			//关闭定时器T0
						break;			//返回
			case 0xef:	//P1=0xef	"mi"按键按下 
						delay_ms(10);	//延时去抖			
						if(P1==0xef)	//再判断"mi"按键是否按下
						{
							SMG=table[3];	//数码管显示"3"
							i=2;			//i置2	
							TR0=0;  		//关闭定时器T0	
							sth=Music_Code[2*i];	//定时器高八位赋值 "mi"	
							stl=Music_Code[2*i+1];	//定时器低八位赋值 "mi"
							TR0=1;			//启动定时器T0	
							for(j=0;j<=1000;j++)	//软件延时,在一定时间里检测
							{							 				
								delay_ms(10);	//延时一下
								if(P1==0xef) continue;	//"mi"按键按下,跳出(继续发音)
								else break;		//松开了,则返回
							}
							SMG=0xff;	//关闭数码管显示
							Speak=1;	//蜂鸣器端口置1 (让蜂鸣器处于与电源5V断电状态)
							TR0=0;		//关闭定时器T0
							for(;;)
							{
								while(P1==0xef);	//等待按键松开	
								delay_ms(10);		//延时去抖
								if(P1==0xef) continue;
								else break;			//确定松开,退出
							}
						}
						TR0=0;			//关闭定时器T0
						break;			//返回		
			default: 	break;			//没有P1没有按键按下,返回
	    }
		switch(P3)		//switch语句判断检测 P3按键状态
		{
			case 0xfe:	//P3=0xfe	"fa"按键按下 
						delay_ms(10);	//延时去抖	
						if(P3==0xfe)	//再判断"fa"按键是否按下
						{
							SMG=table[4];	//数码管显示"4"
							i=3;			//i置3
							TR0=0;  		//关闭定时器T0	
							sth=Music_Code[2*i];	//定时器高八位赋值 "fa"	
							stl=Music_Code[2*i+1];	//定时器低八位赋值 "fa"
							TR0=1;			//启动定时器T0	
							for(j=0;j<=1000;j++)	//软件延时,在一定时间里检测	
							{							 				
								delay_ms(10);	//延时一下
								if(P3==0xfe) continue;	//"fa"按键按下,跳出(继续发音)
								else break;		//松开了,则返回
							}
							SMG=0xff;	//关闭数码管显示
							Speak=1;	//蜂鸣器端口置1 (让蜂鸣器处于与电源5V断电状态)
							TR0=0;		//关闭定时器T0
							for(;;)
							{
								while(P3==0xfe);	//等待按键松开
								delay_ms(10);		//延时去抖
								if(P3==0xfe) continue;
								else break;			//确定松开,退出
							}
						}
						TR0=0;		//关闭定时器T0	
						break;		//返回
			case 0xf7: 	//P3=0xf7	"so"按键按下 
						delay_ms(10);	//延时去抖			
						if(P3==0xf7)	//再判断"so"按键是否按下
						{
							SMG=table[5];	//数码管显示"5"	
							i=4;			//i置4			
							TR0=0;  		//关闭定时器T0		
							sth=Music_Code[2*i];	//定时器高八位赋值 "so"
							stl=Music_Code[2*i+1];	//定时器低八位赋值 "so"
							TR0=1;			//启动定时器T0		
							for(j=0;j<=1000;j++)	//软件延时,在一定时间里检测	
							{									 				
								delay_ms(10);		//延时一下
								if(P3==0xf7) continue;	//"so"按键按下,跳出(继续发音)
								else break;			//松开了,则返回
							}
							SMG=0xff;	//关闭数码管显示
							Speak=1;	//蜂鸣器端口置1 (让蜂鸣器处于与电源5V断电状态)
							TR0=0;		//关闭定时器T0
							for(;;)
							{
							   	while(P3==0xf7);	//等待按键松开		
								delay_ms(10);		//延时去抖
								if(P3==0xf7) continue;
								else break;			//确定松开,退出
							}
					  	}
						TR0=0;		//关闭定时器T0
						break;		//返回
			case 0xef: 	//P3=0xef	"la"按键按下
						delay_ms(10);	//延时去抖
						if(P3==0xef)	//再判断"la"按键是否按下
						{
							SMG=table[6];	//数码管显示"6"
							i=5;			//i置5
							TR0=0;  		//关闭定时器T0
							sth=Music_Code[2*i];	//定时器高八位赋值 "la"
							stl=Music_Code[2*i+1];	//定时器低八位赋值 "la"
							TR0=1;			//启动定时器T0		
							for(j=0;j<=1000;j++)	//软件延时,在一定时间里检测	
							{							 				
								delay_ms(10);		//延时一下
								if(P3==0xef) continue;	//"la"按键按下,跳出(继续发音)
								else break;			//松开了,则返回
							}
							SMG=0xff;	//关闭数码管显示
							Speak=1;	//蜂鸣器端口置1 (让蜂鸣器处于与电源5V断电状态)
							TR0=0;		//关闭定时器T0
							for(;;)
							{
								while(P3==0xef);	//等待按键松开	
								delay_ms(10);		//延时去抖
								if(P3==0xef) continue;
								else break;			//确定松开,退出
							}	
						}
						TR0=0;		//关闭定时器T0	
						break;		//返回
			case 0xdf: 	//P3=0xdf	"si"按键按下
						delay_ms(10);	//延时去抖
						if(P3==0xdf)	//再判断"si"按键是否按下
						{
							SMG=table[7];	//数码管显示"7"	
							i=6;			//i置6
							TR0=0;  		//关闭定时器T0
							sth=Music_Code[2*i];	//定时器高八位赋值 "si"
							stl=Music_Code[2*i+1];	//定时器低八位赋值 "si"
							TR0=1;			//启动定时器T0	
							for(j=0;j<=1000;j++)	//软件延时,在一定时间里检测	
							{							 				
								delay_ms(10);		//延时一下
								if(P3==0xdf) continue;	//"si"按键按下,跳出(继续发音)
								else break;			//松开了,则返回
							}
							SMG=0xff;	//关闭数码管显示
							Speak=1;	//蜂鸣器端口置1 (让蜂鸣器处于与电源5V断电状态)
							TR0=0;		//关闭定时器T0
							for(;;)
							{
								while(P3==0xdf);	//等待按键松开
								delay_ms(10);		//延时去抖
								if(P3==0xdf) continue;
								else break;			//确定松开,退出
							}
						}
						TR0=0;		//关闭定时器T0
						break;		//返回
			case 0xbf:	//P3=0xbf	"高音do"按键按下
						delay_ms(10);	//延时去抖	
						if(P3==0xbf)	//再判断"高音do"按键是否按下
						{
							SMG=table[1]&0x7f;  //数码管显示"1"带小数点(1.)
							i=7;		//i置7		
							TR0=0;  	//关闭定时器T0
							sth=Music_Code[2*i];	//定时器高八位赋值 "高音do"
							stl=Music_Code[2*i+1];	//定时器低八位赋值 "高音do"
							TR0=1;		//启动定时器T0			
							for(j=0;j<=1000;j++)	//软件延时,在一定时间里检测		
							{							 				
								delay_ms(10);		//延时一下
								if(P3==0xbf) continue;	//"高音do"按键按下,跳出(继续发音)
								else break;			//松开了,则返回
							}
							SMG=0xff;	//关闭数码管显示
							Speak=1;	//蜂鸣器端口置1 (让蜂鸣器处于与电源5V断电状态)
							TR0=0;		//关闭定时器T0
							for(;;)
							{
							   	while(P3==0xbf);	//等待按键松开
								delay_ms(10);		//延时去抖
								if(P3==0xbf) continue;
								else break;			//确定松开,退出
							}
						}
						TR0=0;		//关闭定时器T0
						break;		//返回
			default: 	break;		//没有P3没有按键按下,返回
		}
		
		if(Key1==0)			//按键1按下(播放 "挥着翅膀的女孩")
		{
			delay_ms(10);	//延时去抖
			if(Key1==0)		//再判断按键1是否按下
			{
				SMG=table[10];	//数码管显示"A"
				for(i=0;Music_hzcb[i]!=0xff;i++)	//for循环语句			
				{				//Music_hzcb[]=0ff时,跳出for循环语句,停止播放音乐
					sth=yinfu1[(Music_hzcb[i]%100)/10-1][((Music_hzcb[i]%10)-1)*2];	 //定时器高八位赋值
					stl=yinfu1[(Music_hzcb[i]%100)/10-1][((Music_hzcb[i]%10)-1)*2+1];//定时器低八位赋值
					i++;		//i加1
					TR0=1;		//启动定时器T0
					delay_ms(4*500/length[Music_hzcb[i]%10]);	//确定几分音符(节拍)		
					TR0=0;		//节拍结束,关闭定时器T0				 
				}
				SMG=0xff;	//关闭数码管显示
				Speak=1;	//蜂鸣器端口置1 (让蜂鸣器处于与电源5V断电状态)
				for(;;)
				{
					while(Key1==0);		//等待按键松开	
					delay_ms(10);		//延时去抖
					if(Key1==0) continue;
					else break;			//确定松开,退出	
				}
			}
		}
		if(Key2==0)			//按键2按下(播放 "同一首歌")	
		{
			delay_ms(10);	//延时去抖
			if(Key2==0)		//再判断按键2是否按下
			{
				SMG=table[11];	//数码管显示"B"
				for(i=0;Music_tyshg[i]!=0xff;i++)	//for循环语句
				{				//Music_tyshg[]=0ff时,跳出for循环语句,停止播放音乐
					sth=yinfu1[(Music_tyshg[i]%100)/10-1][((Music_tyshg[i]%10)-1)*2];  //定时器高八位赋值
					stl=yinfu1[(Music_tyshg[i]%100)/10-1][((Music_tyshg[i]%10)-1)*2+1];//定时器低八位赋值
					i++;		//i加1
					TR0=1;		//启动定时器T0
					delay_ms(4*500/length[Music_tyshg[i]%10]);	//确定几分音符(节拍)
					TR0=0;		//节拍结束,关闭定时器T0						 
				}
				SMG=0xff;	//关闭数码管显示
				Speak=1;	//蜂鸣器端口置1 (让蜂鸣器处于与电源5V断电状态)
				for(;;)	
				{
					while(Key2==0);		//等待按键松开	
					delay_ms(10);		//延时去抖
					if(Key2==0) continue;
					else break;			//确定松开,退出
				}
			}
		}

硬件设计

使用元器件:

单片机:STC89C52;

(注意:单片机是通用的,无论51还是52、无论stc还是at都一样,引脚功能都一样。程序也是一样的。)

电解电容10uF;电阻10K;

瓷片电容30P;晶振12M;

电阻470(贴片);按键;

电阻4.7K;三极管8550;

无源蜂鸣器;1位共阳数码管;

DIP40;连接导线;

7*9CM万能板;USB公对公线;

2P排针;导线:若干;

流程图:

设计资料

01 仿真图

本设计使用proteus7.8和proteus8.7两个版本设计,向下兼容,无需担心!具体如图!

02 原理图

本系统原理图采用Altium Designer19设计,具体如图!

03 程序

本设计使用软件keil4和keil5两个版本编程设计,无需担心!具体如图!

04 设计报告

七千多字设计报告,具体如下!

05 设计资料

        资料获取请关注同名公众号,全部资料包括仿真源文件 、程序(含注释)、AD原理图、开题报告、参考论文、流程图、任务书等。具体内容如下,全网最全! !

资料获取请观看前面演示视频!

点赞分享,一起学习成长。

标签:0x19,0x17,0x16,51,0x02,0x03,单片机,电子琴,0x1A
From: https://blog.csdn.net/2401_82402501/article/details/136722380

相关文章

  • 代码随想录算法训练营第七天|LeetCode 344.反转字符串、541.反转字符串II、卡码网54.替
    344.反转字符串题目描述:​编写一个函数,其作用是将输入的字符串反转过来。输入字符串以字符数组s的形式给出。不要给另外的数组分配额外的空间,你必须**原地修改输入数组**、使用O(1)的额外空间解决这一问题。示例一:输入:s=["h","e","l","l","o"]输出:["o","l","l......
  • 代码随想录训练营第44天 | 动态规划:完全背包理论基础、​​​​​​LeetCode 518.零钱
    目录动态规划:完全背包理论基础文章讲解:代码随想录(programmercarl.com)视频讲解:带你学透完全背包问题!_哔哩哔哩_bilibili思路​​​​​​LeetCode518.零钱兑换II文章讲解:代码随想录(programmercarl.com)视频讲解:518.零钱兑换II_哔哩哔哩_bilibili思路​​​​​​Le......
  • 基于51单片机的智能浇花系统的设计与实现
    项目介绍本设计是基于51系列单片机而设计的智能浇花系统,本系统结合单片机编程技术、传感器技术以及GSM通信技术实现系统基本功能,使系统根据不一样的土壤湿度,能够相应的改变浇水要求。本系统主要由湿度显示模块、湿度设置模块、湿度采集模块、远程控制模块、浇水控制模块五......
  • 学习C51单片机——独立按键控制数码管显示数字(学习笔记Keil5)
    学习C51单片机——独立按键控制数码管显示数字(学习笔记Keil5)文章目录学习C51单片机——独立按键控制数码管显示数字(学习笔记Keil5)1、按键控制数码管第一位显示数字22、按键控制数码管第一位按顺序显示数字0~91、按键控制数码管第一位显示数字2按键按下数码管第一位......
  • 513. 找树左下角的值C
    /***Definitionforabinarytreenode.*structTreeNode{*intval;*structTreeNode*left;*structTreeNode*right;*};*/intfindBottomLeftValue(structTreeNode*root){if(!root->left&&!root->right)return......
  • pcm5102芯片解析之基本概念
    一前记1在音频领域深耕,那就要不断的前行。最近有几个项目需要用到pcm5102这颗料,藉此机会,针对这个料进行深入的研究一下。做一一些简要的分析。二概念音频芯片的指标,其实,很多年都没啥变化了,唯一的问题就是这个应用形态有些变化。下面是该芯片的性能指标。 ......
  • AT89S52单片机复位电路理解
    AT89S52单片机经典复位电路如下:此时复位功能可以分为两类:上电复位和按键复位上电复位:利用电容器充放电原理。以常见的极板电容为例,极板电容的两个极板一般是由金属材料制成,上面充满了金属原子。复位电路上电后,左边极板上的自由电子就会在电场力的作用下流向电源正极,此时左边极......
  • AppLink对51Tracking的集成方式
    什么是51Tracking51Tracking是一个提供国际物流跟踪服务的平台,用户可以通过该平台跟踪包裹在全球范围内的物流信息。该平台提供多家物流公司的跟踪服务,帮助用户更方便地了解包裹的运输情况和到达时间。提供实时运单查询、运单管理功能,支持英语、法语、德语、阿拉伯语等多种语言。......
  • 代码随想录算法训练营第四十四天 | 377. 组合总和 Ⅳ ,518. 零钱兑换 II ,完全背包
    377.组合总和Ⅳ 已解答中等 相关标签相关企业 给你一个由 不同 整数组成的数组 nums ,和一个目标整数 target 。请你从 nums 中找出并返回总和为 target 的元素组合的个数。题目数据保证答案符合32位整数范围。 示例1:输入:num......
  • Vue学习笔记51--解绑组件自定义事件
    解绑组件自定义事件//this.$off('defineMyEvent')//解绑一个自定义事件//解绑多个自定义事件//this.$off(['defineMyEvent','demoEvent'])//等价于this.$off()//解绑所有自定义的事件this.$off()注意:如果vm被销毁,则其所有......