基于51单片机的音乐程序.doc

上传人:xin****828 文档编号:6639855 上传时间:2020-03-01 格式:DOC 页数:10 大小:48KB
返回 下载 相关 举报
基于51单片机的音乐程序.doc_第1页
第1页 / 共10页
基于51单片机的音乐程序.doc_第2页
第2页 / 共10页
基于51单片机的音乐程序.doc_第3页
第3页 / 共10页
点击查看更多>>
资源描述
基于51单片机的按键切换播放音乐原理图:引脚说明:共5个按键,分别接51单片机的P0P4引脚,前4个按键控制播放设置好的四首音乐,第5个按键用来关闭音乐。按键采用中断方式,任意时刻按下任意按键则立即进入所按按键的功能;蜂鸣器接单片机的P3.6口。仿真说明:使用proteus仿真,晶振:12MHZ。程序代码如下:/*12Mhz晶振工作*/#include #define uint unsigned int#define uchar unsigned charsbit voice=P36;uchar code sound1=0xff,0x40,0x80,0x30,0x40,0x2b,0x40,0x26,0x80,0x24,0x10,0x26,0x40,0x30,0x40,0x2b,0x80,0x30,0x40,0x39,0x40,0x30,0xc0,0x40,0x80,0x30,0x40,0x2b,0x40,0x26,0x40,0x26,0x20,0x24,0x20,0x20,0x40,0x30,0x40,0x24,0x80,0x26,0x10,0x20,0x40,0x2b,0x20,0x26,0x20,0x26,0x20,0x2b,0x20,0x2b,0xc0,0x26,0x80,0x20,0x40,0x19,0x40,0x19,0x80,0x1c,0x10,0x1c,0x80,0x20,0x40,0x20,0x20,0x1c,0x20,0x19,0x40,0x1c,0x20,0x20,0x20,0x26,0xc0,0x24,0x80,0x24,0x10,0x20,0x40,0x1c,0x40,0x20,0x40,0x24,0x20,0x26,0x20,0x2b,0x80,0x33,0x40,0x33,0x20,0x39,0x20,0x40,0x40,0x39,0x40,0x30,0xc0,0x18,0x80,0x1c,0x80,0x24,0x80,0x20,0x10,0x1c,0x80,0x19,0x40,0x19,0x20,0x19,0x20,0x19,0x40,0x1c,0x20,0x20,0x20,0x26,0xc0,0x18,0x80,0x1c,0x80,0x24,0x80,0x20,0x10,0x1c,0x80,0x1c,0x40,0x1c,0x20,0x1c,0x20,0x1c,0x40,0x24,0x20,0x26,0x20,0xff,0x20,0x00;/同一首歌*/uchar code sound2=0xff,0x18,0x40,0x1c,0x20,0x18,0x20,0x13,0x40,0x13,0x20,0x15,0x20,0x13,0x20,0x15,0x20,0x13,0x20,0x15,0x20,0x18,0x20,0x19,0x20,0x1c,0x20,0x20,0x20,0x1c,0x40,0x19,0x20,0x18,0x20,0x15,0x40,0x10,0x80,0x13,0x10,0x10,0x40,0x15,0x10,0x13,0x10,0x18,0x10,0x1c,0x10,0x26,0x10,0x13,0x10,0x18,0x10,0x1c,0x10,0x26,0x10,0x13,0x10,0x18,0x10,0x1c,0x10,0x26,0x10,0x13,0x10,0x18,0x10,0x1c,0x10,0x26,0x10,0x15,0x10,0x19,0x10,0x20,0x10,0x2b,0x10,0x15,0x10,0x19,0x10,0x20,0x10,0x2b,0x10,0x15,0x10,0x19,0x10,0x20,0x10,0x2b,0x10,0x15,0x10,0x19,0x10,0x20,0x10,0x2b,0x10,0x18,0x10,0x1c,0x10,0x24,0x10,0x30,0x10,0x18,0x10,0x1c,0x10,0x24,0x10,0x30,0x10,0x19,0x10,0x20,0x10,0x2b,0x10,0x19,0x10,0x19,0x10,0x20,0x10,0x2b,0x10,0x19,0x10,0x18,0xc0,0xff,0x40,0x40,0x10,0x39,0x20,0x30,0x20,0x2b,0x20,0x30,0x20,0x2b,0x20,0x26,0x20,0x26,0x20,0x26,0x20,0x26,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x2b,0x20,0x26,0x20,0x26,0x20,0x26,0x20,0x26,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x2b,0x40,0x30,0x10,0x30,0x20,0x39,0x20,0x30,0x40,0x2b,0x10,0x2b,0x20,0x26,0x20,0x26,0x80,0x40,0x10,0x39,0x20,0x30,0x20,0x2b,0x20,0x30,0x20,0x2b,0x20,0x30,0x20,0x30,0x20,0x20,0x20,0x20,0x20,0x26,0x20,0x2b,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x30,0x20,0x26,0x20,0x26,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x2b,0x40,0x2b,0x10,0x2b,0x20,0x2b,0x20,0x2b,0x40,0x30,0x10,0x30,0x20,0x39,0x20,0x2b,0x80,0x40,0x10,0x39,0x20,0x30,0x20,0x2b,0x20,0x30,0x20,0x2b,0x20,0x26,0x20,0x26,0x20,0x20,0x20,0x20,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x2b,0x20,0x26,0x20,0x26,0x20,0x1c,0x20,0x1c,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x2b,0x40,0x30,0x10,0x30,0x20,0x39,0x20,0x30,0x40,0x2b,0x10,0x2b,0x20,0x26,0x20,0x20,0x80,0x40,0x10,0x39,0x20,0x30,0x20,0x2b,0x20,0x30,0x20,0x2b,0x20,0x30,0x20,0x30,0x20,0x1c,0x20,0x1c,0x20,0x20,0x20,0x26,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x30,0x20,0x26,0x20,0x26,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x2b,0x40,0x2b,0x10,0x2b,0x20,0x2b,0x20,0x2b,0x40,0x30,0x10,0x30,0x20,0x39,0x20,0x30,0x80,0x30,0x10,0x18,0x20,0x19,0x20,0x18,0x20,0x1c,0x20,0x18,0x40,0x1c,0x10,0x1c,0x20,0x20,0x20,0x1c,0x20,0x20,0x20,0x26,0x20,0x2b,0x20,0x26,0x20,0x20,0x20,0x1c,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x1c,0x20,0x20,0x20,0x1c,0x40,0x1c,0x10,0x1c,0x20,0x1c,0x20,0x1c,0x40,0x20,0x10,0x20,0x20,0x1c,0x20,0x20,0x20,0x26,0x20,0x26,0x40,0xff,0x20,0x30,0x20,0x2b,0x20,0x26,0x20,0x20,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x30,0x20,0x30,0x20,0x2b,0x20,0x26,0x20,0x1c,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x30,0x20,0x30,0x20,0x30,0x20,0x30,0x20,0x18,0x40,0x18,0x10,0x18,0x20,0x18,0x20,0x18,0x40,0x1c,0x10,0x1c,0x20,0x18,0x20,0x1c,0x80,0x20,0x10,0x20,0x20,0x30,0x20,0x18,0x20,0x19,0x20,0x18,0x20,0x19,0x20,0x1c,0x20,0x20,0x20,0x1c,0x20,0x20,0x20,0x26,0x20,0x2b,0x20,0x26,0x20,0x20,0x20,0x1c,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x1c,0x20,0x20,0x20,0x1c,0x40,0x1c,0x10,0x1c,0x20,0x1c,0x20,0x1c,0x40,0x20,0x10,0x20,0x20,0x1c,0x20,0x20,0x20,0x26,0x20,0x26,0x40,0xff,0x20,0x30,0x20,0x2b,0x20,0x26,0x20,0x20,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x30,0x20,0x30,0x20,0x2b,0x20,0x26,0x20,0x1c,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x18,0x80,0xff,0x40,0xff,0x40,0xff,0x20,0x18,0x20,0x1c,0x20,0x18,0x20,0x1c,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x1c,0x20,0x20,0x20,0x26,0x20,0x2b,0x20,0x26,0x20,0x2b,0x20,0x2b,0x20,0x30,0x20,0x39,0x20,0x30,0x20,0x30,0x20,0x2b,0x20,0x30,0xc0,0x30,0x80,0x30,0x20,0x18,0x20,0x1c,0x20,0x18,0x20,0x15,0x20,0x18,0x20,0x18,0x20,0x18,0x20,0x15,0x20,0x18,0x20,0x18,0x20,0x18,0x20,0x15,0x20,0x18,0x20,0x1c,0x20,0x18,0x20,0x13,0x20,0x15,0x20,0x15,0x20,0x18,0x20,0x1c,0x20,0x18,0x20,0x15,0x40,0x30,0xc0,0xff,0x40,0x00; /爱情转移*/uchar code sound3=0xff,0x40,0x10,0x39,0x10,0x30,0x10,0x2b,0x10,0x26,0x20,0x20,0x10,0x20,0x10,0x20,0x30,0x18,0x10,0x19,0x20,0x1c,0x20,0x20,0x20,0x20,0x40,0x1c,0x20,0x30,0x20,0x30,0x20,0x30,0x20,0x1c,0x20,0x20,0x20,0x24,0x10,0x26,0x10,0x26,0x10,0x2b,0x20,0x30,0x10,0x39,0x20,0x30,0x10,0x30,0x10,0x30,0x20,0x20,0x20,0x24,0x10,0x26,0x10,0x2b,0x10,0x30,0x10,0x33,0x10,0x40,0x10,0x39,0x20,0x39,0xc0,0xff,0x20,0x26,0x10,0x20,0x10,0x1c,0x10,0x20,0x10,0x1c,0x10,0x20,0x10,0x1c,0x10,0x18,0x30,0x19,0x10,0x1c,0x10,0x1c,0x10,0x20,0x10,0x1c,0x20,0x20,0x20,0x1c,0x20,0x1c,0x10,0x18,0x10,0x19,0x20,0x1c,0x10,0x20,0x10,0x1c,0x60,0x26,0x20,0x20,0x20,0x1c,0x10,0x20,0x10,0x1c,0x10,0x20,0x10,0x1c,0x10,0x18,0x30,0x15,0x10,0x18,0x10,0x15,0x10,0x18,0x10,0x18,0x10,0x15,0x30,0x13,0x20,0x13,0x10,0x15,0x10,0x18,0x10,0x15,0x20,0x13,0x10,0x13,0x60,0x15,0x20,0x13,0x20,0x15,0x10,0x18,0x10,0x15,0x10,0x18,0x10,0x15,0x20,0x18,0x10,0x15,0x10,0x15,0x60,0x15,0x20,0x13,0x20,0x15,0x10,0x18,0x10,0x18,0x10,0x18,0x10,0x18,0x20,0x19,0x10,0x1c,0x10,0x1c,0x60,0xff,0x20,0x13,0x20,0x15,0x10,0x18,0x10,0x15,0x10,0x18,0x10,0x15,0x20,0x18,0x10,0x15,0x10,0x15,0x20,0x18,0x20,0x18,0x10,0x10,0x30,0x10,0xc0,0x18,0x20,0x15,0x20,0x13,0x10,0x15,0x10,0x13,0x10,0x15,0x10,0x13,0x10,0x15,0x10,0x13,0x10,0x15,0x10,0x15,0x10,0x10,0x30,0x10,0x20,0x13,0x10,0x10,0x10,0x0e,0x10,0x0e,0x10,0x0e,0x10,0x0e,0x10,0x10,0x20,0x13,0x10,0x15,0x10,0x13,0x60,0x15,0x20,0x13,0x20,0x15,0x20,0x18,0x10,0x1c,0x10,0x1c,0x40,0x18,0x20,0x19,0x10,0x1c,0x10,0x1c,0x40,0xff,0x20,0x0e,0x20,0x10,0x20,0x13,0x20,0x15,0x40,0x18,0x20,0x15,0x20,0xff,0x20,0x26,0x20,0x20,0x20,0x26,0x20,0x15,0x20,0x13,0x40,0x15,0x20,0x18,0x20,0x1c,0xc0,0x30,0x40,0x2b,0x30,0x26,0x10,0x39,0x40,0xff,0x20,0x30,0x10,0x39,0x10,0x33,0x10,0x30,0x10,0x2b,0x20,0x2b,0x20,0x30,0x10,0x2b,0x10,0x26,0x10,0x2b,0x10,0x2b,0x20,0x1c,0x10,0x20,0x10,0x2b,0x10,0x26,0x10,0x26,0x80,0x18,0x10,0x19,0x10,0x1c,0x10,0x1c,0x10,0x19,0x20,0x26,0x20,0xff,0x20,0x26,0x20,0x20,0x20,0x26,0x20,0x15,0x20,0x13,0x40,0x15,0x20,0x18,0x20,0x1c,0xc0,0xff,0x20,0x26,0x20,0x20,0x20,0x26,0x20,0x15,0x20,0x13,0x40,0x15,0x20,0x18,0x20,0x1c,0x40,0x1c,0xc0,0x00;/最后一次的温柔*/uchar code sound4=0xff,0x40,0x30,0x30,0x80,0x30,0x30,0x30,0x80,0x26,0x40,0x2b,0x80,0x30,0x30,0x2b,0x80,0x26,0x30,0x30,0x80,0x30,0x30,0x26,0x80,0x20,0x30,0x1c,0xc0,0x1c,0x80,0x1c,0x30,0x20,0x80,0x26,0x30,0x26,0x80,0x30,0x30,0x2b,0x80,0x30,0x30,0x2b,0x80,0x26,0x30,0x30,0x80,0x39,0x30,0x39,0x80,0x40,0x30,0x30,0xc0,0x30,0x80,0x1c,0x30,0x20,0x80,0x26,0x30,0x26,0x80,0x30,0x30,0x2b,0x80,0x30,0x30,0x2b,0x80,0x1c,0x30,0x20,0x80,0x26,0x30,0x26,0x80,0x20,0x30,0x1c,0xc0,0x1c,0x80,0x18,0x30,0x20,0x80,0x26,0x30,0x26,0x80,0x30,0x30,0x2b,0x80,0x30,0x30,0x2b,0x80,0x26,0x30,0x30,0x80,0x39,0x30,0x39,0x80,0x40,0x30,0x30,0xc0,0x30,0xc0,0x00;/友谊地久天长*/*uchar code sound=0xff,0x20,0x60,0x26,0x20,0x20,0x40,0x20,0x20,0x1c,0x20,0x18,0x40,0x18,0x20,0x1c,0x20,0x20,0x80,0x20,0x60,0x1c,0x20,0x20,0x20,0x1c,0x10,0x20,0x10,0x26,0x20,0x2b,0x20,0x20,0x30,0x1c,0x10,0x20,0x20,0x26,0x20,0x2b,0x80,0xff,0x20,0x20,0x20,0xff,0x20,0x20,0x20,0x1c,0x40,0x20,0x40,0x18,0x30,0x1c,0x10,0x20,0x20,0x26,0x20,0x2b,0x80,0xff,0x20,0x20,0x20,0xff,0x20,0x20,0x20,0x26,0x40,0x2b,0x20,0x30,0x20,0x30,0xc0,0xff,0x40,0x00;/中华民谣*/uchar zdjs=0,jp,p,a;uint dpjs;void del(uchar yj) uchar yj2=2; while(yj!=0) while(yj2!=0) yj2-; yj2=2; yj-; void delay0() uchar u=20; while(u-);void play() uchar yj; dpjs=0; while(a) zdjs=0; dpjs+; if(p=1) yj=sound1dpjs; dpjs+; jp=sound1dpjs; if(p=2) yj=sound2dpjs; dpjs+; jp=sound2dpjs; if(p=3) yj=sound3dpjs; dpjs+; jp=sound3dpjs; if(p=4) yj=sound4dpjs; dpjs+; jp=sound4dpjs; while(zdjs!=jp) if(yj!=0xff) if(yj!=0) voice=!voice; del(yj); else dpjs=0; break; else voice=0; del(jp); void init() TMOD=0x01; IE=0x82; TH0=0xd8; TL0=0xef; TR0=1; EX0=1; IT0=1; EA=1;void main(void) init(); a=1; p=1; while(1) play(); void init_0(void) interrupt 0 uchar q;q=P1;if(q!=0xff) delay0(); q=P1; if(q!=0xff) zdjs=0; dpjs=0; jp=0;switch(q) case 0xfe: a=1;p=1;break; case 0xfd: a=1;p=2;break; case 0xfb: a=1;p=3;break; case 0xf7: a=1;p=4;break; case 0xef: a=0;break; void time0(void) interrupt 1 TH0=0xd8; TL0=0xef; zdjs+;声明:欢迎学习与制作;转载请注明出处!
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 其他分类 > 大学论文


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


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