/*编写人:伍浩荣
8个按键宣布8个根本音,
能播映内置音乐,音乐跟从灯火闪耀
版权所有,翻版必究
作者博客:http://hi.baidu.com/haorongwu/home*/
sfr P4=0xe8;//界说P4组I0口
#include
#define uint unsigned int
#define uchar unsigned char
sbit speaker=P1^4;//喇叭接30脚
sbit key1=P4^4;//流水灯按键(暂时)
sbit key2=P4^6;//播映音乐按键(暂定)
uchar a,b,num1,s1num,n1,n2;
char num;//界说num为能够负数
uchar code yinfu[]={0xfb,0xe9, //Do
0xfc,0x5c, //Re
0xfc,0xc1, //Mi
0xfc,0xef, //Fa
0xfd,0x45, //So
0xfd,0x92, //La
0xfd,0xd0, //Si
0xfd,0xee, //Do#
0x00,0x00, //距离
};
uchar code shengri_tone[]={ 1,0,1,2,1,4,3,0, //生日快乐腔调
1,0,1,2,1,5,4,0,
1,0,1,8,6,4,3,2,0,
7,0,7,6,4,5,4,0 //0代表不发声,即中止;数字即为腔调
};
uchar code shengri_beat[]={ 24,1,24,48,48,48,72,5,//节拍
24,1,24,48,48,48,72,5,
24,1,24,48,48,48,48,72,5,
24,1,24,48,48,48,72,5 //节拍,即tone表各腔调的延时
};
uchar code ledtable[]={0x7f,0xbf,0xdf,0xef, //取反
0xf7,0xfb,0xfd,0xfe};//P0组口的发光二极管代码(焊接进程可能会相反,详细更改)
uchar code ledtable2[]={0x7f,0xbf,0xdf,0xef, //取反
0xf7,0xfb,0xfd,0xfe};//P2组口发光二极管代码,相反!
void check_key();//改为P3组为按键
void keyscan();
void turn();//顺时针活动
void back();
void qianhou();
void dangshuang();
void delay(uint z);//延时函数声明
void delay1(void);//声明第二个延时函数
void play1(void);//播映生日快乐
void main()
{
s1num=0;//流水灯品种标志
key1=1;
key2=1;
TMOD=0x01;
TH0=a;
TL0=b;
ET0=1;//翻开定时器,可是未答应中止
TR0=1;
while(1)
{
check_key();
keyscan();
}
}
void time0() interrupt 1
{
TH0=a;
TL0=b;
speaker=~speaker;
}
void check_key()
{
P3=0xff;//先赋给P2组口高电平
switch(P3)//按下一个键相应4个灯亮
{
case 0xfe:P0=0xee;P2=0x77;a=0xfb;b=0xe9;EA=1;break;//P0,P2组为发光二极管组
case 0xfd:P0=0xdd;P2=0xbb;a=0xfc;b=0x5c;EA=1;break;//留意:EA不能改为TR0
case 0xfb:P0=0xbb;P2=0xdd;a=0xfc;b=0xc1;EA=1;break;
case 0xf7:P0=0x77;P2=0xee;a=0xfc;b=0xef;EA=1;break;
case 0xef:P0=0xee;P2=0x77;a=0xfd;b=0x45;EA=1;break;
case 0xdf:P0=0xdd;P2=0xbb;a=0xfd;b=0x92;EA=1;break;
case 0xbf:P0=0xbb;P2=0xdd;a=0xfd;b=0xd0;EA=1;break;
case 0x7f:P0=0x77;P2=0xee;a=0xfd;b=0xee;EA=1;break;
default:EA=0;speaker=0;//P0=0xff;P2=0xff ;
}
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x–)
for(y=110;y>0;y–);
}
void keyscan()
{
if(key1==0)
{
delay(5);
if(key1==0)
{
s1num++;
while(!key1);
if(s1num==1)
{
turn();
}
}
if(s1num==2)
{
back();
}
if(s1num==3)
{
qianhou();
}
if(s1num==4)
{
dangshuang();
}
if(s1num==5)
s1num=1;
}
if(key2==0)
{
delay(5);
while(~key2);
play1();
}
}
声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/qiche/adas/318484.html