基于51单片机数字音乐盒的设计说明.doc

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

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

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

2、按键 蜂鸣器 LCD1602液晶目录前 言第一章 工作原理1.1设计目标第二章 软件设计与分析2.1 软件设计的组成2.2 各部分软件分析2.2.1 延时165MS,即十六分音符子函数2.2.2 延时1MS子函数2.2.3 定时器0中断子函数2.2.4 播放音乐子函数2.5 定时器1中断子函数2.6 按键扫描子函数2.2.7 主函数2.3 总源程序第三章 软件仿真3.仿真图3.1 元件清单总结参考文献26 / 26第一章 工作原理1.1设计目标1.1.1基本功能具体要:以单片机为核心,设计一个数字音乐盒: 利用I/O口产生一定频率的方波,驱动蜂鸣器,发出不同的音调,从而演奏乐曲(最少3首乐曲,

3、每首不少于30s)。采用LCD显示信息。 a. 开机时有英文欢迎提示字符,播放时显示歌曲序号(或名称)。 b. 可通过功能键选择乐曲、暂停、播放。第二章 软件设计与分析2.1 软件设计的组成该系统由延时165MS,即十六分音符子函数、延时1MS子函数、按键扫描子函数、播放音乐子函数、定时器1中断子函数、定时器0中断子函数、主函数和数据定义这几部分组成。2.2 各部分软件分析2.2.1 延时165MS,即十六分音符子函数/延时165MS,即十六分音符子函数void delay1(uint z)uint x,y;for(x=z;x0;x-) for(y=19000;y0;y-);2.2.2 延时1

4、MS子函数/延时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 aa;/aa是简谱c=0;while(1)if(count2=0)break;if(count2=1)/选曲temp=table1c;if(count2=2)temp=table2c;if(count

5、2=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=1; c+;TR1=0;BEEP=1;2.2.5 定时器1中断子函数/定时器1中断子函数void t1() interrupt 3 /用于产生各种音调key();2.2.6 按键扫描子函数void

6、 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_(0x01);/清屏 write_(0x80+0); write_date(W);write_(0x80+1); write_date(e); write_(0x80+2); write_date(l);write_(0x80+3); write_date(c

7、);write_(0x80+4); write_date(o);write_(0x80+5); write_date(m);write_(0x80+6); write_date(e);write_(0x80+7); write_date( );write_(0x80+8); write_date(t);write_(0x80+9); write_date(o);write_(0x80+10); write_date( );write_(0x80+11); write_date(u);write_(0x80+12); 2.2.7 主函数/主函数void main()TMOD=0x10;/定时器0

8、工作在方式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单片机头文件typedef unsigned char uchar;typedef unsigned int uint;sbit RS=P27;/LCD1602数据/命令选择端(H/L)sbit RW=P26;/LCD1602读/写选择端(H/L)sbit E=P25;/LCD16

9、02使能信号端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;/-简谱-/编程规则:字节高位是简谱,低位是持续时间,/代表多少个十六分音符/1-7代表中央C调,8-E代表高八度,0代表停顿/最后的0是结束标志uchar code table1=/千年之恋0x12,0x22,0x34,0x84,0x74,0x54,0x38,0x42,0x32,0x22,0x42,0x34,

10、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,/七色的国度 不断飘逸风中0x32,0x31,0x21,0x32,0x52,0x32,0x31,0x21,0x32,0x62,/有一种神秘 灰色的旋涡0x32,0x31,0x21,0x32,0x83,0x82,0x71,0x72,0x02,/将我卷入了迷雾中0x63,0xA1,0xA2,0x62,0

11、x92,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,0x71,0x62,0x52,0x31,0x36,/只为求一个结果0x61,0x71,0x82,0x71,0x62,0xA3,0x73,0x62,0x53,/你留下的轮廓 指引我0x42,0x63,0x83,0x83,0x91,0x91,/黑夜中不寂寞0x61,0x71,0x82,0x7

12、1,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,0x93,0x89,0xff/结束标?/睾? ;uchar code table2= /寂寞沙洲冷0x12,0x12,0x22,0x32,0x31,0x22,0x21,0x22,/自你走后心憔悴0x21,0x31,0x51,0x52,0x31,0x52,0x61,0x15,0x1

13、4,/白色油桐风中纷飞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,0x32,0x31,0x32,0x81,0x72,0x63,/不断拨弄离人的眼泪0x62,0x71,0x81,0x72,0x61,0x61,0x52,0x31,0x21,0x32,0x51,0x54,/那样浓烈的爱再也无法给0x22,0x12,0x11,0x12,0x11,0x12

14、,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,/是慌乱占据了心扉 0x31,0x81,0x81,0x81,0x61,0x91,0x82,/有花儿伴着蝴蝶0x51,0x51,0x51,0x51,0x31,0x61,0x53,/孤雁可以双飞0x21,0x11,0x21,0x11,0x22,0x11,0x21,0x26,/夜深人静独徘徊

15、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,0x32,0x81,0x81,0x81,0x81,0x91,0x81,0x61,0x81,0x61,0x51,0x31,0x51,0x34,/仍然捡尽寒枝不肯安歇微带着后悔0x21,0x31,0x51,0x31,0x21,0x11,0x61,0x21,0x16,/寂寞沙洲我该思念谁0xf

16、f ;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,0x20,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

17、,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,0x10,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

18、,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,0x10,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

19、,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,0x10,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,

20、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,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,

21、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,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,

22、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,0x20,0x30,0x1C,0x10,0x18,0x40,0x1C,0x20,0x20,0x20,0x26,0x40,0x13,0x60,0x18,0x20,0x15,0x40,0x13,0x40,0x18,0x80,0xff,;/简谱音调对应的定时器初值/适合12的晶振uch

23、ar 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,0xD9,0xFE,0xF9,0xFF,0x16 ;uchar code yinyue=0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0x00,0x00;/将音调转化为对应的LED样式/延时165MS,即十六分音符子函数void delay

24、1(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_(uchar ) RS=0; /选择写指令 RW=0;E=0; P0=; E=1; delay2(5); /无延时不能正常工作 E=0; /LCD1602液晶写数据子函数void write_date(uchar date) RS=1; /选择写数据 RW=0;E=0; P0=date; E=1; de

25、lay2(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;TR0=1;EA=1;/开总中断EX1=1;/开外部中断1IT1=1;/下降沿时触发中断EX0=1;/开外部中断0IT0=1;/下降沿时触发中断count2=0;/唱第一首歌LCD1602_init();while(1)/大循环song(); /定时器0中断子函数void t0() interrupt

26、 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)count2+;c=0;/从头开始唱if(count2=1)write_(0x01);delay2(10);write_(0x80+0); write_date( );write_(0x80+1); write_date( ); write_(0x80+2); write_date( );write

27、_(0x80+3); write_(0xc0+8); write_date( );write_(0xc0+9); write_date(f);write_(0xc0+10); write_date(l);write_(0xc0+11); write_date(o);write_(0xc0+12); write_date(w);write_(0xc0+13); write_date(e);write_(0xc0+14); write_date(r);write_(0xc0+15); write_date(s);if(count24)count2=1;c=0;/从头开始唱TR1=1;while(!

28、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;c=0;/从头开始唱TR1=1;while(!k2);3仿真图3.1原理图3.2 元件清单总结这次设计进一步端了我的学习态度,学会了实事,严谨的作风,对自己要严格要求,不能够一知半解,要力求明明白白。急于求成是不好的,我有所感受。如果省略了那些必要的步骤,急于求成,不仅会浪费时间,还会适得其反。我觉得动手之前,头脑里必须清楚该怎么做,这一点是很重要的。就目前来说,我的动手能力虽

29、然差一点,但我想,通过我的不懈努力,在这方面,我总会得到提高。这一点,我坚信。因为别人能做到的,我也一定能做到。参考文献1群芳,士军,黄建.单片微型计算机与接口技术. :电子工业,20082群芳.单片机原理接口与应用.:清华大学,20053迎新.单片微型计算机原理、应用及接口技术.:国防工业,19994高峰.单片微机应用系统设计及使用技术.:机械工业,20075伟.单片机c语音程序设计实例基于protues仿真.:电子工业,20077冬林,鑫,戴梅.基于DHT11的低成本蚕室温湿度自动控制系统设计J.现代农业科技,2010,(18):14-15 .8徐春河.浅谈AT89S51J.制造业自动化,

30、2010,(12):80-82.9吴汉清.常用的典型单片机资料J.无线电,2007,(11):72-80.10叶健斌.基于单片机嵌入式系统的GPS应用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 淘文阁