本系统通过光敏电阻将光信号转化为电信号,再经由STC89C51单片机进行引脚的数据采集,获得信号后通过LM386放大音频信号,通过控制电路,控制扬声器发出相应频率声音,并将音符信息显示在1602液晶上。
硬件部分主要包含激光发射电路,激光接收电路,音频输出电路,以及液晶显示电路等,软件部分主要包括激光信号采集,液晶显示器的操作,以及发声频率的控制。
51单片机制作的激光竖琴程序主要是:
#include <>#define uchar unsigned char#define uint unsigned int//数码管 共阳uchar code DSY_Table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xbf};//音符对应的延时uint code Tone_Delay_Table[]={64021,64103,64260,64400,64524,64580,64684,64777,64820,64898,64968,65030,65058,65110,65157,65178};sbit BEEP=P3^2;uchar KeyNo
//生日快乐歌的音符频率表,不同的频率用延时值来表示uchar code SONG_TONE[]={212,212,190,212,159,169,212,212,190,212,142,159,212,212,212,159,169,190,119,119,126,159,142,159,0};uchar code SONG_LONG[]={9,3,12,12,12,24,9,3,12,12,12,24,9,3,12,12,12,12,9,3,12,12,12,24,0};///////delay------void DelayMS(uint x){uchar i;while(x--)for(i=0;i<120;i++);}void PlayMusic(){uint i=0,j,k;while(SONG_LONG[i]!=0||SONG_TONE[i]!=0){for(j=0;j
DelayMS(80); //每个音符之间的时间间隔i++;}}void Keys_SCAN(){uchar k,t,key_state;P1=0xff;//while(1)//{t=P1;if(t!=0xff){DelayMS(10);if(t!=P1){switch(t){case 0x87: BEEP=159 ; break; //1mie docase 0x47: BEEP=142 ; break; //2mie recase 0x27: BEEP=126 ; break; //3mie micase 0x17: BEEP=119 ; break; //4mie facase 0x0f: BEEP=212 ; break; //5mie soldefault: BEEP=169 ;}// silu}//continue;// key_state=~t;// k=0;//while(key_state!=0)// {//k++;//key_state>>=1;// }// KeyNo=k;//}
//return; //return 语句的加法很重要}//return;//KeyNo=k;}void play_Tone() interrupt 1{TH0=Tone_Delay_Table[KeyNo]/256;TL0=Tone_Delay_Table[KeyNo]%256;BEEP=~BEEP;}//////MAIN/////////////////void main(){//BEEP=0;//while(1)//P0=0xF0;P0=0xbf;PlayMusic();DelayMS(1000);DelayMS(1000);TMOD=0x01;IE=0x82;while(1){P1=0xff;if(P1 != 0xff){Keys_SCAN();P0=DSY_Table[KeyNo];TR0=1;}else{TR0=0;}DelayMS(2);}}