基于51单片机数字音乐盒的设计(共26页).doc

上传人:飞****2 文档编号:13369367 上传时间:2022-04-29 格式:DOC 页数:26 大小:222KB
返回 下载 相关 举报
基于51单片机数字音乐盒的设计(共26页).doc_第1页
第1页 / 共26页
基于51单片机数字音乐盒的设计(共26页).doc_第2页
第2页 / 共26页
点击查看更多>>
资源描述

《基于51单片机数字音乐盒的设计(共26页).doc》由会员分享,可在线阅读,更多相关《基于51单片机数字音乐盒的设计(共26页).doc(26页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、精选优质文档-倾情为你奉上单片机实物设计题 目: 单片机音乐盒设计 班 级: K-17 姓 名: 湛俊 朱斌 杨裕庆 学号:K K K 摘 要本设计是一个基于STC89C51RC系列单片机的音乐盒,依据单片机技术原理,通过硬件电路制作以及软件编译,设计制作出一个多功能多功能音乐盒。该音乐盒主要由按键电路、复位电路、时钟电路以及蜂鸣器组成。本音乐盒共有四首歌曲,用4个按键控制。播放歌曲时,蜂鸣器发出某个音调。本设计利用KEIL编程软件对音乐盒源程序进行编程并调试,配合PROTEUS仿真软件对硬件进行仿真调试,节约了设计时间。【关键词】STC89C51RC 按键 蜂鸣器 LCD1602液晶目录专心

2、-专注-专业第一章 工作原理1.1设计目标1.1.1基本功能具体要求是:以单片机为核心,设计一个数字音乐盒: 利用I/O口产生一定频率的方波,驱动蜂鸣器,发出不同的音调,从而演奏乐曲(最少3首乐曲,每首不少于30s)。采用LCD显示信息。 a. 开机时有英文欢迎提示字符,播放时显示歌曲序号(或名称)。 b. 可通过功能键选择乐曲、暂停、播放。第二章 软件设计与分析2.1 软件设计的组成该系统由延时165MS,即十六分音符子函数、延时1MS子函数、按键扫描子函数、播放音乐子函数、定时器1中断子函数、定时器0中断子函数、主函数和数据定义这几部分组成。2.2 各部分软件分析2.2.1 延时165MS

3、,即十六分音符子函数/延时165MS,即十六分音符子函数void delay1(uint z)uint x,y;for(x=z;x0;x-) for(y=19000;y0;y-);2.2.2 延时1MS子函数/延时1MS子函数void delay2(uint z)uint x,y;for(x=z;x0;x-) for(y=110;y0;y-);2.2.3 定时器0中断子函数/定时器0中断子函数void t0() interrupt 1 /用于产生各种音调TH0=a;TL0=b;BEEP=BEEP;2.2.4 播放音乐子函数/播放音乐子函数void song()uint temp;uchar a

4、a;/aa是简谱c=0;while(1)if(count2=0)break;if(count2=1)/选曲temp=table1c;if(count2=2)temp=table2c;if(count2=3)temp=table3c;if(count2=4)temp=table4c;if(temp=0xff)break;aa=temp/16; /取数的高4位if(aa!=0)a=cuzhiaa*2;b=cuzhiaa*2+1;elseTR1=0;BEEP=1;/关蜂鸣器delay1(temp%16); /取数的低4位TR1=0; /唱完一个音停10MSBEEP=1;delay2(10); TR1

5、=1; c+;TR1=0;BEEP=1;2.2.5 定时器1中断子函数/定时器1中断子函数void t1() interrupt 3 /用于产生各种音调key();2.2.6 按键扫描子函数void key()if(k3=0)delay2(10);if(k3=0)num1+;if(num1=1)TR1=0;aa=count2;count2=0;if(num1=2)num1=0;count2=aa;TR1=1;while(!k3);if(k4=0)delay2(10);if(k4=0)TR1=0;count2=0;c=0;write_com(0x01);/清屏 write_com(0x80+0)

6、; write_date(W);write_com(0x80+1); write_date(e); write_com(0x80+2); write_date(l);write_com(0x80+3); write_date(c);write_com(0x80+4); write_date(o);write_com(0x80+5); write_date(m);write_com(0x80+6); write_date(e);write_com(0x80+7); write_date( );write_com(0x80+8); write_date(t);write_com(0x80+9);

7、write_date(o);write_com(0x80+10); write_date( );write_com(0x80+11); write_date(u);write_com(0x80+12); 2.2.7 主函数/主函数void main()TMOD=0x10;/定时器0工作在方式1TH1=0;TL1=0;ET1=1;EA=1;/开总中断EX1=1;/开外部中断1IT1=1;/下降沿时触发中断EX0=1;/开外部中断0IT0=1;/下降沿时触发中断count2=0;/唱第一首歌LCD1602_init();while(1)/大循环song(); 2.3 总源程序#include/51

8、单片机头文件typedef unsigned char uchar;typedef unsigned int uint;sbit RS=P27;/LCD1602数据/命令选择端(H/L)sbit RW=P26;/LCD1602读/写选择端(H/L)sbit E=P25;/LCD1602使能信号端sbit BEEP=P20;/蜂鸣器接口sbit k1=P32;/下一首sbit k2=P33;/上一首sbit k3=P21;/播放/暂停sbit k4=P22;/复位char count2;/歌曲标志uchar a,b,c,aa,num;uchar num1,num2;/-简谱-/编程规则:字节高位

9、是简谱,低位是持续时间,/代表多少个十六分音符/1-7代表中央C调,8-E代表高八度,0代表停顿/最后的0是结束标志uchar code table1=/千年之恋0x12,0x22,0x34,0x84,0x74,0x54,0x38,0x42,0x32,0x22,0x42,0x34,0x84,0x72,0x82,0x94,0xA8,0x08,/前奏0x32,0x31,0x21,0x32,0x52,0x32,0x31,0x21,0x32,0x62,/竹林的灯火 到过的沙漠0x32,0x31,0x21,0x32,0x82,0x71,0x81,0x71,0x51,0x32,0x22,/七色的国度 不断

10、飘逸风中0x32,0x31,0x21,0x32,0x52,0x32,0x31,0x21,0x32,0x62,/有一种神秘 灰色的旋涡0x32,0x31,0x21,0x32,0x83,0x82,0x71,0x72,0x02,/将我卷入了迷雾中0x63,0xA1,0xA2,0x62,0x92,0x82,0x52,/看不清的双手0x31,0x51,0x63,0x51,0x63,0x51,0x63,0x51,0x62,0x82,0x7C,0x02,/一朵花传来谁经过的温柔0x61,0x71,0x82,0x71,0x62,0xA2,0x71,0x76,/穿越千年的伤痛0x61,0x71,0x82,0x7

11、1,0x62,0x52,0x31,0x36,/只为求一个结果0x61,0x71,0x82,0x71,0x62,0xA3,0x73,0x62,0x53,/你留下的轮廓 指引我0x42,0x63,0x83,0x83,0x91,0x91,/黑夜中不寂寞0x61,0x71,0x82,0x71,0x62,0x0A2,0x71,0x76,/穿越千年的哀愁0x61,0x71,0x82,0x71,0x62,0x52,0x31,0x36,/是你在尽头等我0x61,0x71,0x82,0x71,0x62,0xA3,0x73,0x62,0x53,/最美丽的感动 会值得0x42,0x82,0x88,0x02,0x74

12、,0x93,0x89,0xff/结束标?/睾? ;uchar code table2= /寂寞沙洲冷0x12,0x12,0x22,0x32,0x31,0x22,0x21,0x22,/自你走后心憔悴0x21,0x31,0x51,0x52,0x31,0x52,0x61,0x15,0x14,/白色油桐风中纷飞0x51,0x52,0x31,0x52,0x62,0x13,0x11,0x13,0x32,0x28,0x08,0x28,/落花似人有情 这个季节0x31,0x32,0x31,0x32,0x11,0x21,0x51,0x52,0x51,0x52,/河畔的风放肆拼命地吹0x51,0x51,0x31,

13、0x32,0x31,0x32,0x81,0x72,0x63,/不断拨弄离人的眼泪0x62,0x71,0x81,0x72,0x61,0x61,0x52,0x31,0x21,0x32,0x51,0x54,/那样浓烈的爱再也无法给0x22,0x12,0x11,0x12,0x11,0x12,0x12,0x14,0x26,0x32,0x26,/伤感一夜一夜0x32,0x61,0x51,0x51,0x31,0x31,0x21,0x31,0x51,0x61,0x51,0x31,0x51,/当记忆的线缠绕过往支离破碎0x02,0x32,0x81,0x81,0x81,0x81,0x62,0x52,0x34,/是

14、慌乱占据了心扉 0x31,0x81,0x81,0x81,0x61,0x91,0x82,/有花儿伴着蝴蝶0x51,0x51,0x51,0x51,0x31,0x61,0x53,/孤雁可以双飞0x21,0x11,0x21,0x11,0x22,0x11,0x21,0x26,/夜深人静独徘徊0x32,0x61,0x51,0x51,0x31,0x31,0x21,0x31,0x51,0x61,0x51,0x31,0x51,0x52,/当幸福恋人寄来红色分享喜悦0x31,0x31,0x81,0x81,0x81,0x61,0x91,0x81,0x61,0x31,0x56,/闭上双眼难过头也不敢回0x32,0x3

15、2,0x81,0x81,0x81,0x81,0x91,0x81,0x61,0x81,0x61,0x51,0x31,0x51,0x34,/仍然捡尽寒枝不肯安歇微带着后悔0x21,0x31,0x51,0x31,0x21,0x11,0x61,0x21,0x16,/寂寞沙洲我该思念谁0xff ;uchar code table3=0x26,0x20,0x20,0x20,0x20,0x20,0x26,0x10,0x20,0x10,0x20,0x80,0x26,0x20,0x30,0x20,0x30,0x20,0x39,0x10,0x30,0x10,0x30,0x80,0x26,0x20,0x20,0x2

16、0,0x20,0x20,0x1c,0x20,0x20,0x80,0x2b,0x20,0x26,0x20,0x20,0x20,0x2b,0x10,0x26,0x10,0x2b,0x80,0x26,0x20,0x30,0x20,0x30,0x20,0x39,0x10,0x26,0x10,0x26,0x60,0x40,0x10,0x39,0x10,0x26,0x20,0x30,0x20,0x30,0x20,0x39,0x10,0x26,0x10,0x26,0x80,0x26,0x20,0x2b,0x10,0x2b,0x10,0x2b,0x20,0x30,0x10,0x39,0x10,0x26,0x1

17、0,0x2b,0x10,0x2b,0x20,0x2b,0x40,0x40,0x20,0x20,0x10,0x20,0x10,0x2b,0x10,0x26,0x30,0x30,0x80,0x18,0x20,0x18,0x20,0x26,0x20,0x20,0x20,0x20,0x40,0x26,0x20,0x2b,0x20,0x30,0x20,0x30,0x20,0x1c,0x20,0x20,0x20,0x20,0x80,0x1c,0x20,0x1c,0x20,0x1c,0x20,0x30,0x20,0x30,0x60,0x39,0x10,0x30,0x10,0x20,0x20,0x2b,0x1

18、0,0x26,0x10,0x2b,0x10,0x26,0x10,0x26,0x10,0x2b,0x10,0x2b,0x80,0x18,0x20,0x18,0x20,0x26,0x20,0x20,0x20,0x20,0x60,0x26,0x10,0x2b,0x20,0x30,0x20,0x30,0x20,0x1c,0x20,0x20,0x20,0x20,0x80,0x26,0x20,0x30,0x10,0x30,0x10,0x30,0x20,0x39,0x20,0x26,0x10,0x2b,0x10,0x2b,0x20,0x2b,0x40,0x40,0x10,0x40,0x10,0x20,0x1

19、0,0x20,0x10,0x2b,0x10,0x26,0x30,0x30,0x80,0xff,;uchar code table4=0x30,0x1C,0x10,0x20,0x40,0x1C,0x10,0x18,0x10,0x20,0x10,0x1C,0x10,0x18,0x40,0x1C,0x20,0x20,0x20,0x1C,0x20,0x18,0x20,0x20,0x80,0xFF,0x20,0x30,0x1C,0x10,0x18,0x20,0x15,0x20,0x1C,0x20,0x20,0x20,0x26,0x40,0x20,0x20,0x2B,0x20,0x26,0x20,0x20

20、,0x20,0x30,0x80,0xFF,0x20,0x20,0x1C,0x10,0x18,0x10,0x20,0x20,0x26,0x20,0x2B,0x20,0x30,0x20,0x2B,0x40,0x20,0x20,0x1C,0x10,0x18,0x10,0x20,0x20,0x26,0x20,0x2B,0x20,0x30,0x20,0x2B,0x40,0x20,0x30,0x1C,0x10,0x18,0x20,0x15,0x20,0x1C,0x20,0x20,0x20,0x26,0x40,0x20,0x20,0x2B,0x20,0x26,0x20,0x20,0x20,0x30,0x80

21、,0x20,0x30,0x1C,0x10,0x20,0x10,0x1C,0x10,0x20,0x20,0x26,0x20,0x2B,0x20,0x30,0x20,0x2B,0x40,0x20,0x15,0x1F,0x05,0x20,0x10,0x1C,0x10,0x20,0x20,0x26,0x20,0x2B,0x20,0x30,0x20,0x2B,0x40,0x20,0x30,0x1C,0x10,0x18,0x20,0x15,0x20,0x1C,0x20,0x20,0x20,0x26,0x40,0x20,0x20,0x2B,0x20,0x26,0x20,0x20,0x20,0x30,0x30

22、,0x20,0x30,0x1C,0x10,0x18,0x40,0x1C,0x20,0x20,0x20,0x26,0x40,0x13,0x60,0x18,0x20,0x15,0x40,0x13,0x40,0x18,0x80,0xff,;/简谱音调对应的定时器初值/适合12的晶振uchar code cuzhi=0xff,0xff,/占位0xFC,0x8E,/中央C调1-70xFC,0xED,0xFD,0x43,0xFD,0x6A,0xFD,0xB3,0xFD,0xF3,0xFE,0x2D,0xFE,0x47,/高八度1-7 0xFE,0x76,0xFE,0xA1,0xFE,0xC7,0xFE,0

23、xD9,0xFE,0xF9,0xFF,0x16 ;uchar code yinyue=0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0x00,0x00;/将音调转化为对应的LED样式/延时165MS,即十六分音符子函数void delay1(uint z)uint x,y;for(x=z;x0;x-) for(y=19000;y0;y-);/延时1MS子函数void delay2(uint z)uint x,y;for(x=z;x0;x-) for(y=110;y0;y-);/LCD1602液晶写命令子函数void write_com(uchar c

24、om) RS=0; /选择写指令 RW=0;E=0; P0=com; E=1; delay2(5); /无延时不能正常工作 E=0; /LCD1602液晶写数据子函数void write_date(uchar date) RS=1; /选择写数据 RW=0;E=0; P0=date; E=1; delay2(5); /无延时不能正常工作 E=0; /LCD1602液晶初始化子函数void LCD1602_init() /初始化 delay2(15); /主函数void main()TMOD=0x11;/定时器0工作在方式1TH1=0;TL1=0;ET1=1;TH0=0;TL0=0;ET0=1;

25、TR0=1;EA=1;/开总中断EX1=1;/开外部中断1IT1=1;/下降沿时触发中断EX0=1;/开外部中断0IT0=1;/下降沿时触发中断count2=0;/唱第一首歌LCD1602_init();while(1)/大循环song(); /定时器0中断子函数void t0() interrupt 1 num2+;if(num2=5)num2=0;key();/定时器1中断子函数void t1() interrupt 3 /用于产生各种音调TH1=a;TL1=b;BEEP=BEEP;void wb0() interrupt 0TR1=0;if(k1=0)delay2(10);if(k1=0

26、)count2+;c=0;/从头开始唱if(count2=1)write_com(0x01);delay2(10);write_com(0x80+0); write_date( );write_com(0x80+1); write_date( ); write_com(0x80+2); write_date( );write_com(0x80+3); write_com(0xc0+8); write_date( );write_com(0xc0+9); write_date(f);write_com(0xc0+10); write_date(l);write_com(0xc0+11); wri

27、te_date(o);write_com(0xc0+12); write_date(w);write_com(0xc0+13); write_date(e);write_com(0xc0+14); write_date(r);write_com(0xc0+15); write_date(s);if(count24)count2=1;c=0;/从头开始唱TR1=1;while(!k1);void wb1() interrupt 2TR1=0;if(k2=0)delay2(10);if(k2=0)count2-;c=0;/从头开始唱if(count2=1)if(count2=0)count2=4;

28、c=0;/从头开始唱TR1=1;while(!k2); 3仿真图3.1原理图3.2 元件清单总结这次设计进一步端了我的学习态度,学会了实事求是,严谨的作风,对自己要严格要求,不能够一知半解,要力求明明白白。急于求成是不好的,我有所感受。如果省略了那些必要的步骤,急于求成,不仅会浪费时间,还会适得其反。我觉得动手之前,头脑里必须清楚该怎么做,这一点是很重要的。就目前来说,我的动手能力虽然差一点,但我想,通过我的不懈努力,在这方面,我总会得到提高。这一点,我坚信。因为别人能做到的,我也一定能做到。参考文献1李群芳,张士军,黄建.单片微型计算机与接口技术. 北京:电子工业出版社,20082李群芳.单

29、片机原理接口与应用.北京:清华大学出版社,20053张迎新.单片微型计算机原理、应用及接口技术.北京:国防工业出版社,19994高峰.单片微机应用系统设计及使用技术.北京:机械工业出版社,20075彭伟.单片机c语音程序设计实例基于protues仿真.北京:电子工业出版社,20077张冬林,李鑫,戴梅.基于DHT11的低成本蚕室温湿度自动控制系统设计J.现代农业科技,2010,(18):14-15 .8 徐春河.浅谈AT89S51J.制造业自动化,2010,(12):80-82.9吴汉清.常用的典型单片机资料J.无线电,2007,(11):72-80.10叶健斌.基于单片机嵌入式系统的GPS应

30、用J.电子质量,2008,(7):16-24.11 刘宝元,张玉虹,姜旭,段存丽.基于单片机的温湿度监控系统设计J.国外电子测量技术,2009,(12):77-80,83.12王静.通用库房温湿度测控系统D.中国海洋大学,2009.13陈汝全.实用微机与单片机控制技术M电子科技大学出版社1995.7 12.14 张广军,黄俊钦.温度传感器现场动态校准方法与实验研究J 北京航空航天大学学报 1997年23卷3期 311-315.15 李建民单片机在温度控制系统中的应用M江汉大学学报,1996.6 210-215.16. 薛玲,孙曼,张志会,夏莉丽,魏希文.基于单片机AT89S51的温湿度控制仪J.2010,37, (7):66-69

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 教案示例

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁