基于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