“屏幕式”聲光電子琴程序
8個(gè)按鍵發(fā)出8個(gè)基本音,
能播放內(nèi)置音樂(lè),音樂(lè)跟隨燈光閃爍
版權(quán)所有,翻版必究
作者博客: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;//流水燈按鍵(暫時(shí))
sbit key2=P4^6;//播放音樂(lè)按鍵(暫定)
uchar a,b,num1,s1num,n1,n2;
char num;//定義num為可以負(fù)數(shù)
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, //生日快樂(lè)音調(diào)
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代表不發(fā)聲,即停頓;數(shù)字即為音調(diào)
};
uchar code shengri_beat[]={ 24,1,24,48,48,48,72,5,//節(jié)拍
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 //節(jié)拍,即tone表各音調(diào)的延時(shí)
};
uchar code ledtable[]={0x7f,0xbf,0xdf,0xef, //取反
0xf7,0xfb,0xfd,0xfe};//P0組口的發(fā)光二極管代碼(焊接過(guò)程可能會(huì)相反,具體更改)
uchar code ledtable2[]={0x7f,0xbf,0xdf,0xef, //取反
0xf7,0xfb,0xfd,0xfe};//P2組口發(fā)光二極管代碼,相反!
void check_key();//改為P3組為按鍵
void keyscan();
void turn();//順時(shí)針流動(dòng)
void back();
void qianhou();
void dangshuang();
void delay(uint z);//延時(shí)函數(shù)聲明
void delay1(void);//聲明第二個(gè)延時(shí)函數(shù)
void play1(void);//播放生日快樂(lè)
void main()
{
s1num=0;//流水燈種類標(biāo)志
key1=1;
key2=1;
TMOD=0x01;
TH0=a;
TL0=b;
ET0=1;//打開定時(shí)器,但是未允許中斷
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)//按下一個(gè)鍵相應(yīng)4個(gè)燈亮
{
case 0xfe:P0=0xee;P2=0x77;a=0xfb;b=0xe9;EA=1;break;//P0,P2組為發(fā)光二極管組
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();
}
關(guān)鍵詞:
聲光電子琴流水
相關(guān)推薦
技術(shù)專區(qū)
- FPGA
- DSP
- MCU
- 示波器
- 步進(jìn)電機(jī)
- Zigbee
- LabVIEW
- Arduino
- RFID
- NFC
- STM32
- Protel
- GPS
- MSP430
- Multisim
- 濾波器
- CAN總線
- 開關(guān)電源
- 單片機(jī)
- PCB
- USB
- ARM
- CPLD
- 連接器
- MEMS
- CMOS
- MIPS
- EMC
- EDA
- ROM
- 陀螺儀
- VHDL
- 比較器
- Verilog
- 穩(wěn)壓電源
- RAM
- AVR
- 傳感器
- 可控硅
- IGBT
- 嵌入式開發(fā)
- 逆變器
- Quartus
- RS-232
- Cyclone
- 電位器
- 電機(jī)控制
- 藍(lán)牙
- PLC
- PWM
- 汽車電子
- 轉(zhuǎn)換器
- 電源管理
- 信號(hào)放大器
評(píng)論