功能部分实现,框架已经写好:
1、按键选择音乐自动播放或自己演奏
2、EEPROM实现存储音乐(未加入,代码写好需要调试)
3、.......
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include <reg52.h>
- #include "led.h"
- #include "beep.h"
- #include "lcd1602.h"
- #include "key.h"
- #include "tim.h"
- #include "delay.h"
- #include "music.h"
- #include "musicArr.h"
- #include "SoundPlay.h"
- typedef unsigned int u16;
- typedef unsigned char u8;
- void show(u8 arr[],u8 length,u8 pos,u8 mode);
- unsigned char calcArrLen(unsigned char arr[]);
- void displayInit(void);
- u8 code ShowData[]="Electronic Organ";
- u8 code ShowData1[]="150802027";
- u8 code ShowData2[]="Welcome to use ";
- u8 code ShowData3[]="press note";
- u8 code ShowData4[]="Same song";
- u8 code ShowData5[]="Song name";
- u8 code ShowData6[]="aiwonijiubaobaowo";
- u16 FreqTemp=0;
- void main()
- {
- unsigned char i=0,key=0,timer=0,flag1=0;
- LcdInit(); //液晶屏初始化
- timInit(); //定时器初始化
- // AT24C02_Init(); //EEPROM初始化
- ledOFF(); //关闭LED灯
- InitialSound(); //音乐播放器初始化
- displayInit();
- while(1)
- {
- key=key_Scan();
- if(key==0x16&&flag==0) //播放/停止键 并且处于停止播放状态,开始播放
- {
- flag=1;
- }
- else if(key>0&&key<22&&flag==0) //21键音符
- {
- num=key-1;
- FreqTemp=Freqtab[key-1];
- TR0=1;
- }
- else
- {
- if(TR0==1) //之前音符键按下,延时一秒停止
- {
- delay_ms(1000);
- TR0=0;
- }
- }
- if(flag==1)
- {
- if(status==1) //循环播放两首歌曲
- {
- LcdWriteCom(0x01); //清屏
- show(ShowData5,9,4,0);
- show(ShowData4,15,0,1);
- Play(Music_Same,0,3,360);
- delay_ms(2000);
- }
- else
- {
- LcdWriteCom(0x01); //清屏
- show(ShowData5,9,4,0);
- show(ShowData6,16,0,1);
- Play(Music_Girl,0,3,360);
- delay_ms(2000);
- }
- }
- }
- }
- void displayInit(void)
- {
- unsigned char i= 0;
- for(i=0;i<16;i++)
- {
- LcdWriteData(ShowData[i]);
- }
- lcd_pos(0x40+3);
- for(i=0;i<9;i++)
- {
- LcdWriteData(ShowData1[i]);
- num=ShowData1[i]+6-'0';
- TR0=1;
- delay_ms(1000);
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载(仿真+代码):
单片机开发实训.zip
(321.68 KB, 下载次数: 163)
|