好文档 - 专业文书写作范文服务资料分享网站

可振动感应切换的电子音乐

天下 分享 时间: 加入收藏 我要投稿 点赞

. .. . .

/**********************

基于STC15F2K60S2系列单片机C语言编程实现 使用如下头文件,不用另外再包含\***********************/ #include #define uint unsigned int #define uchar unsigned char

sbit Key1=P3^2; //Key1对应触发外部中断0 sbit beep=P3^4; sbit vibrate=P2^4;

//蜂鸣器 //振动传感器

//定义定时器的重装值

uchar timeh,timel,jindu=0,gequ=0,zanting=0; bit flag; //播放标志位 uchar code music1[] ={

//音乐代码,歌曲为《生日快乐》,格式为: 音符, 节拍, 音符, 节拍,

//音符的十位代表是低八度,中八度还是高八度,1代表高八度,2代表中八度,3代表高八度

//个位代表简谱的音符,例如0x15代表低八度的S0,0x21代表中八度的DO。 //节拍则是代表音长,例如:0x10代表一拍,0x20代表两拍,0x05代表1/2拍 0x15,0x05,0x15,0x05,

0x16,0x10,0x15,0x10, 0x31,0x10,0x17,0x20, 0x15,0x05,0x15,0x05, 0x16,0x10,0x15,0x10, 0x32,0x10,0x31,0x20, 0x15,0x05,0x15,0x05, 0x35,0x10,0x33,0x10, 0x31,0x10,0x17,0x10, 0x16,0x10,0x34,0x05, 0x34,0x05,0x33,0x10, 0x31,0x10,0x32,0x10,

. .. . .

. .. . .

};

0x31,0x10,0x00,0x00

uchar code music2[] ={ //歌曲为小毛驴

0x21,0x05,0x21,0x05, 0x21,0x05,0x23,0x05, 0x25,0x05,0x25,0x05, 0x25,0x05,0x25,0x05, 0x26,0x05,0x26,0x05, 0x26,0x05,0x31,0x05, 0x25,0x20,0x24,0x05, 0x24,0x05,0x24,0x05, 0x26,0x05,0x23,0x05, 0x23,0x05,0x23,0x05, 0x23,0x05,0x22,0x05, 0x22,0x05,0x22,0x05, 0x22,0x05,0x25,0x15, 0x25,0x05,0x21,0x05, 0x21,0x05,0x21,0x05, 0x23,0x05,0x25,0x05, 0x25,0x05,0x25,0x05, 0x25,0x05,0x26,0x05, 0x26,0x05,0x26,0x05, 0x31,0x05,0x25,0x20, 0x24,0x05,0x24,0x05, 0x24,0x05,0x26,0x05, 0x21,0x05,0x21,0x05, 0x21,0x05,0x23,0x05, 0x25,0x05,0x25,0x05, 0x25,0x05,0x25,0x05, 0x26,0x05,0x26,0x05,

. .. . .

. .. . .

0x26,0x05,0x31,0x05, 0x25,0x20,0x24,0x05, 0x24,0x05,0x24,0x05, 0x23,0x03,0x23,0x03, 0x23,0x03,0x23,0x03, 0x23,0x05,0x23,0x05, 0x22,0x05,0x22,0x05, 0x22,0x05,0x23,0x05, 0x21,0x20,0x00,0x00 };

uchar code music3[] ={ 0x16,0x05,0x17,0x05, 0x21,0x15,0x17,0x05, 0x21,0x10,0x23,0x10, 0x17,0x30,0x23,0x10, 0x16,0x15,0x15,0x05, 0x16,0x10,0x21,0x10, 0x15,0x30,0x13,0x10, 0x14,0x15,0x13,0x05, 0x14,0x05,0x21,0x05, 0x21,0x10,0x13,0x30, 0x21,0x10,0x17,0x10, 0x14,0x05,0x14,0x10, 0x17,0x10,0x17,0x20, 0xff,

0x16,0x05,0x17,0x05, 0x21,0x15,0x17,0x05, 0x21,0x10,0x23,0x10, 0x17,0x30,0x13,0x05, 0x13,0x05,0x16,0x15,

. //歌曲为天空之城

.. . .

. .. . .

0x15,0x05,0x16,0x10, 0x21,0x10,0x15,0x30, 0x13,0x10,0x14,0x10, 0x21,0x05,0x17,0x05, 0x17,0x10,0x21,0x10, 0x22,0x10,0x23,0x05, 0x21,0x20,0xff, 0x21,0x05,0x17,0x05, 0x16,0x10,0x17,0x10, 0x15,0x10,0x16,0x20, 0xff,

0x21,0x05,0x22,0x05, 0x23,0x15,0x22,0x10, 0x23,0x10,0x24,0x10, 0x25,0x05,0x22,0x30, 0x15,0x10,0x22,0x03, 0x21,0x03,0x17,0x03, 0x21,0x03,0x21,0x10, 0x21,0x05,0x22,0x10, 0x23,0x05,0x23,0x40, 0x16,0x05,0x17,0x05, 0x21,0x10,0x17,0x05, 0x21,0x05,0x22,0x10, 0x21,0x15,0x15,0x05, 0x15,0x20,0x24,0x10, 0x23,0x10,0x22,0x10, 0x21,0x10,0x23,0x30, 0x16,0x05,0x17,0x05, 0x21,0x15,0x17,0x05, 0x21,0x10,0x23,0x10,

. .. . .

. .. . .

0x17,0x30,0x13,0x10, 0x16,0x15,0x15,0x05, 0x16,0x10,0x21,0x10, 0x15,0x30,0x13,0x10, 0x14,0x10,0x21,0x05, 0x17,0x05,0x17,0x10, 0x21,0x10,0x22,0x10, 0x23,0x05,0x21,0x05, 0x21,0x20,0x21,0x05, 0x17,0x05,0x16,0x10, 0x17,0x10,0x15,0x10, 0x16,0x40,0x00,0x00 };

uchar code quzi[] ={ //此数组数据为各个音符在定时器中的重装值,第一列是高位,第二列是低位

0xf8,0x8c, //低八度,低1 0xf9,0x5b, 0xfa,0x15, //低3 0xfa,0x67,

0xfb,0x04, //低5 0xfb,0x90,

0xfc,0x0c, //低7 0xfc,0x44, //中央C调 0xfc,0xac, //中2 0xfd,0x09,

0xfd,0x34, //中4 0xfd,0x82,

0xfd,0xc8, //中6 0xfe,0x06,

0xfe,0x22, //高八度,高1

. .. . .

可振动感应切换的电子音乐

...../**********************基于STC15F2K60S2系列单片机C语言编程实现使用如下头文件,不用另外再包含\***********************/#
推荐度:
点击下载文档文档为doc格式
9ptve0g9pa6j6mw9sjhs44p5c1cp9m00dyx
领取福利

微信扫码领取福利

微信扫码分享