51单片机简易电子琴Word格式文档下载.docx
《51单片机简易电子琴Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《51单片机简易电子琴Word格式文档下载.docx(44页珍藏版)》请在冰豆网上搜索。
![51单片机简易电子琴Word格式文档下载.docx](https://file1.bdocx.com/fileroot1/2022-12/13/e9b09527-0173-416d-b0d7-8823db6bae79/e9b09527-0173-416d-b0d7-8823db6bae791.gif)
sbitP1_7=P1^7;
ucharcodetable[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchartemp,key,i,j,STH0,STL0;
uintcodetab[]={64260,64400,64463,64580,64684,64777,64820,64898,64968,
64994,65058,65110,65157,65178,65217,65252};
uintcodetabb[]={64463,64524,64633,64732,64777,64860,
64934,64994,65030,65085,65134,65157,65198,65235,
65268,65283};
//voiddisplay(ucharkey);
voiddelay(uintz);
voidmusic();
voidmain(void)
{
TMOD=0x01;
ET0=1;
EA=1;
while
(1)
{
if(P1_7==0)
b++;
if(b==2)
b=0;
if(b==0)
P3=0xff;
P3_4=0;
temp=P3;
temp=temp&
0x0f;
if(temp!
=0x0f)
{
delay(5);
switch(temp)
case0x0e:
key=0;
break;
case0x0d:
key=1;
case0x0b:
key=2;
case0x07:
key=3;
}
//display(key);
P2_3=~P2^3;
P2_4=~P2_4;
STH0=tab[key]/256;
STL0=tab[key]%256;
TR0=1;
while(temp!
=0x0f)
temp=P3;
temp=temp&
0x0f;
}
TR0=0;
P2_3=1;
P2_4=1;
P3_5=0;
for(i=50;
i>
0;
i--)
for(j=200;
j>
j--);
key=4;
key=5;
key=6;
key=7;
P3_6=0;
key=8;
key=9;
key=10;
key=11;
//display(key);
while(temp!
{
temp=P3;
temp=temp&
}
P2_3=1;
P2_4=1;
P3_7=0;
key=12;
key=13;
key=14;
key=15;
P2_3=~P2^3;
P2_4=~P2_4;
//display(key);
}
}
if(b==1)
music();
voidmusic()
{
STH0=tabb[12]/256;
STL0=tabb[12]%256;
TR0=1;
delay(500);
TR0=0;
STH0=tabb[13]/256;
STL0=tabb[13]%256;
//;
STH0=tabb[10]/256;
STL0=tabb[10]%256;
delay(2000);
delay(500);
STH0=tabb[9]/256;
STL0=tabb[9]%256;
delay(500);
delay(750);
delay(250);
delay(1000);
STH0=tabb[6]/256;
STL0=tabb[6]%256;
STH0=tabb[5]/256;
STL0=tabb[5]%256;
delay(4000);
//|;
delay(250);
delay(4000);
STH0=tabb[7]/256;
STL0=tabb[7]%256;
STH0=tabb[8]/256;
STL0=tabb[8]%256;
delay(500);
STH0=tabb[3]/256;
STL0=tabb[3]%256;
for(a=0;
a<
2;
++a)
delay(1500);
delay(750);
delay(2000);
STL0=tabb[12]%25