基于51单片机的音乐程序

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

基于51单片机的按键切换播放音乐

原理图:

引脚说明:共5个按键,分别接51单片机的P0~P4引脚,前4个按键控制播放设置好的四首音乐,第5个按键用来关闭音乐。按键采用中断方式,任意时刻按下任意按键则立即进入所按按键的功能;蜂鸣器接单片机的P3.6口。

仿真说明:使用proteus仿真,晶振:12MHZ。

程序代码如下:

/*12Mhz晶振工作*/

#include

#define uint unsigned int

#define uchar unsigned char

sbit voice=P3^6;

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

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,

相关文档
最新文档