#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit key1=P3^2;//按key1可以暂停播放
sbit key2=P3^3;//按key2可切换歌曲
sbit fm=P3^7;//蜂鸣器连续的IO口
uchar code shuzi0=0x3f;
uchar code shuzi1=0x06;//数字1
uchar code shuzi2=0x5b;//数字2
uchar code shuzi3=0x4f;
uchar code shuzi4=0x66;
uchar code shuzi5=0x6d;
uchar code shuzi6=0x7d;
uchar code shuzi7=0x07;
uchar code shuzi8=0x7f;
uchar count1;//播放暂停标志
uchar count2;//歌曲标志
uchar timeh,timel,i;
//---------------------------简谱---------------------------------------
/*unsigned char code Music_Same[]={ 0x0F,0x01, 0x15,0x02, 0x16,0x02, 0x17,0x66, 0x18,0x03,
0x17,0x02, 0x15,0x02, 0x16,0x01, 0x15,0x02, 0x10,0x02,
0x15,0x00, 0x0F,0x01, 0x15,0x02, 0x16,0x02, 0x17,0x02,
0x17,0x03, 0x18,0x03, 0x19,0x02, 0x15,0x02, 0x18,0x66,
0x17,0x03, 0x19,0x02, 0x16,0x03, 0x17,0x03, 0x16,0x00,
0x17,0x01, 0x19,0x02, 0x1B,0x02, 0x1B,0x70, 0x1A,0x03,
0x1A,0x01, 0x19,0x02, 0x19,0x03, 0x1A,0x03, 0x1B,0x02,
0x1A,0x0D, 0x19,0x03, 0x17,0x00, 0x18,0x66, 0x18,0x03,
0x19,0x02, 0x1A,0x02, 0x19,0x0C, 0x18,0x0D, 0x17,0x03,
0x16,0x01, 0x11,0x02, 0x11,0x03, 0x10,0x03, 0x0F,0x0C,
0x10,0x02, 0x15,0x00, 0x1F,0x01, 0x1A,0x01, 0x18,0x66,
0x19,0x03, 0x1A,0x01, 0x1B,0x02, 0x1B,0x03, 0x1B,0x03,
0x1B,0x0C, 0x1A,0x0D, 0x19,0x03, 0x17,0x00, 0x1F,0x01,
0x1A,0x01, 0x18,0x66, 0x19,0x03, 0x1A,0x01, 0x10,0x02,
0x10,0x03, 0x10,0x03, 0x1A,0x0C, 0x18,0x0D, 0x17,0x03,
0x16,0x00, 0x0F,0x01, 0x15,0x02, 0x16,0x02, 0x17,0x70,
0x18,0x03, 0x17,0x02, 0x15,0x03, 0x15,0x03, 0x16,0x66,
0x16,0x03, 0x16,0x02, 0x16,0x03, 0x15,0x03, 0x10,0x02,
0x10,0x01, 0x11,0x01, 0x11,0x66, 0x10,0x03, 0x0F,0x0C,
0x1A,0x02, 0x19,0x02, 0x16,0x03, 0x16,0x03, 0x18,0x66,
0x18,0x03, 0x18,0x02, 0x17,0x03, 0x16,0x03, 0x19,0x00,
0x00,0x00 };
//两只蝴蝶
unsigned char code Music_Two[] ={ 0x17,0x03, 0x16,0x03, 0x17,0x01, 0x16,0x03, 0x17,0x03,
0x16,0x03, 0x15,0x01, 0x10,0x03, 0x15,0x03, 0x16,0x02,
0x16,0x0D, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x10,0x03,
0x10,0x0E, 0x15,0x04, 0x0F,0x01, 0x17,0x03, 0x16,0x03,
0x17,0x01, 0x16,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x01,
0x10,0x03, 0x15,0x03, 0x16,0x02, 0x16,0x0D, 0x17,0x03,
0x16,0x03, 0x15,0x03, 0x10,0x03, 0x15,0x03, 0x16,0x01,
0x17,0x03, 0x16,0x03, 0x17,0x01, 0x16,0x03, 0x17,0x03,
0x16,0x03, 0x15,0x01, 0x10,0x03, 0x15,0x03, 0x16,0x02,
0x16,0x0D, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x10,0x03,
0x10,0x0E, 0x15,0x04, 0x0F,0x01, 0x17,0x03, 0x19,0x03,
0x19,0x01, 0x19,0x03, 0x1A,0x03, 0x19,0x03, 0x17,0x01,
0x16,0x03, 0x16,0x03, 0x16,0x02, 0x16,0x0D, 0x17,0x03,
0x16,0x03, 0x15,0x03, 0x10,0x03, 0x10,0x0D, 0x15,0x00,
0x19,0x03, 0x19,0x03, 0x1A,0x03, 0x1F,0x03, 0x1B,0x03,
0x1B,0x03, 0x1A,0x03, 0x17,0x0D, 0x16,0x03, 0x16,0x03,
0x16,0x0D, 0x17,0x01, 0x17,0x03, 0x17,0x03, 0x19,0x03,
0x1A,0x02, 0x1A,0x02, 0x10,0x03, 0x17,0x0D, 0x16,0x03,
0x16,0x01, 0x17,0x03, 0x19,0x03, 0x19,0x03, 0x17,0x03,
0x19,0x02, 0x1F,0x02, 0x1B,0x03, 0x1A,0x03, 0x1A,0x0E,
0x1B,0x04, 0x17,0x02, 0x1A,0x03, 0x1A,0x03, 0x1A,0x0E,
0x1B,0x04, 0x1A,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03,
0x17,0x0D, 0x16,0x03, 0x17,0x03, 0x19,0x01, 0x19,0x03,
0x19,0x03, 0x1A,0x03, 0x1F,0x03, 0x1B,0x03, 0x1B,0x03,
0x1A,0x03, 0x17,0x0D, 0x16,0x03, 0x16,0x03, 0x16,0x03,
0x17,0x01, 0x17,0x03, 0x17,0x03, 0x19,0x03, 0x1A,0x02,
0x1A,0x02, 0x10,0x03, 0x17,0x0D, 0x16,0x03, 0x16,0x01,
0x17,0x03, 0x19,0x03, 0x19,0x03, 0x17,0x03, 0x19,0x03,
0x1F,0x02, 0x1B,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04,
0x17,0x02, 0x1A,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04,
0x17,0x16, 0x1A,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04,
0x1A,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03, 0x0F,0x02,
0x10,0x03, 0x15,0x00, 0x00,0x00 };
//北京欢迎你
unsigned char code Music_Code[]={ 0x17,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03, 0x17,0x03,
0x16,0x03, 0x17,0x02, 0x17,0x67, 0x16,0x03, 0x10,0x03,
0x15,0x03, 0x17,0x03, 0x16,0x66, 0x16,0x03, 0x15,0x03,
0x10,0x03, 0x15,0x03, 0x16,0x03, 0x17,0x03, 0x19,0x03,
0x16,0x03, 0x17,0x03, 0x1A,0x03, 0x19,0x03, 0x0F,0x03,
0x16,0x03, 0x15,0x66, 0x16,0x03, 0x15,0x03, 0x10,0x03,
0x15,0x03, 0x16,0x03, 0x17,0x03, 0x19,0x03, 0x16,0x03,
0x17,0x03, 0x1A,0x03, 0x19,0x03, 0x19,0x03, 0x17,0x01,
0x16,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x19,0x67,
0x1A,0x04, 0x17,0x02, 0x10,0x03, 0x17,0x03, 0x16,0x03,
0x16,0x03, 0x15,0x66, 0x17,0x03, 0x19,0x03, 0x1F,0x03,
0x19,0x03, 0x1A,0x66, 0x19,0x03, 0x1A,0x03, 0x19,0x03,
0x17,0x03, 0x17,0x03, 0x19,0x03, 0x19,0x66, 0x17,0x03,
0x19,0x03, 0x1A,0x03, 0x1F,0x03, 0x20,0x03, 0x1F,0x03,
0x19,0x03, 0x17,0x03, 0x16,0x03, 0x19,0x02, 0x17,0x03,
0x17,0x01, 0x17,0x03, 0x19,0x03, 0x1F,0x03, 0x19,0x03,
0x1A,0x66, 0x1F,0x03, 0x20,0x67, 0x1F,0x04, 0x19,0x03,
0x17,0x03, 0x19,0x03, 0x1F,0x03, 0x1A,0x66, 0x17,0x03,
0x16,0x03, 0x17,0x03, 0x1A,0x03, 0x21,0x03, 0x20,0x66,
0x20,0x03, 0x1F,0x01, 0x1F,0x66, 0x17,0x03, 0x19,0x03,
0x15,0x03, 0x19,0x03, 0x1A,0x66, 0x1F,0x03, 0x20,0x66,
0x1F,0x04, 0x19,0x03, 0x17,0x03, 0x19,0x03, 0x1F,0x03,
0x1A,0x66, 0x17,0x03, 0x16,0x03, 0x17,0x03, 0x1A,0x03,
0x21,0x03, 0x20,0x0B, 0x20,0x0B, 0x20,0x0B, 0x20,0x0B,
0x20,0x02, 0x1F,0x03, 0x1F,0x0B, 0x1F,0x0B, 0x1F,0x0B,
0x1F,0x0B, 0x1F,0x0B, 0x00,0x00 };
//奥运主题曲:我和你
unsigned char code Music_Code1[]={ 0x17,0x02, 0x19,0x02, 0x15,0x01, 0x16,0x02, 0x17,0x02,
0x0F,0x01, 0x15,0x02, 0x16,0x02, 0x17,0x02, 0x19,0x02,
0x16,0x00, 0x17,0x02, 0x19,0x02, 0x15,0x01, 0x16,0x02,
0x17,0x02, 0x10,0x01, 0x16,0x02, 0x0F,0x02, 0x16,0x02,
0x17,0x02, 0x15,0x00, 0x1A,0x01, 0x19,0x01, 0x1A,0x01,
0x15,0x01, 0x17,0x02, 0x10,0x02, 0x17,0x66, 0x19,0x03,
0x16,0x00, 0x17,0x02, 0x19,0x02, 0x15,0x01, 0x16,0x02,
0x17,0x02, 0x10,0x01, 0x16,0x02, 0x0F,0x02, 0x16,0x02,
0x17,0x02, 0x15,0x00, 0x00,0x00 };*/
uchar code muqin[]={ //母亲
0x52,0x51,0x61,0x82,0x71,0x62,0x31,0x21,0x14,0x32,0x92,0x91,0x71,0x61,0x31,0x58,
//你入学的新书包有人给你拿
0x52,0x51,0x61,0x82,0x71,0x62,0x51,0x61,0x34,0x62,0x61,0x51,0x51,0x31,0x28,
//你雨中的花折伞有人给你打
0x32,0x31,0x21,0x52,0x51,0x31,0x22,0x31,0x21,0x12,0x21,0x32,0x51,0x71,0x61,0x52,0x68,
//你爱吃的(那)三鲜馅有人(他)给你包
0x82,0x81,0x61,0x82,0x81,0x62,0x51,0x31,0x24,0x62,0x51,0x31,0x31,0x21,0x14,
//你委屈的泪花有人给你擦
0x81,0x91,0xa1,0xa2,0xa1,0x92,0xa1,0x91,0x84,
//啊,这个人就是娘
0x61,0x81,0x91,0x92,0xa1,0x91,0x71,0x61,0x71,0x61,0x58,
//啊,这个人就是妈
0x61,0x82,0x61,0x82,0x81,0x61,0x52,0x61,0x51,0x64,
//这个人给了我生命
0x62,0x81,0xa1,0x91,0x82,0x94,
//给我一个家
0x81,0x91,0xa1,0xa2,0xa1,0x92,0xa1,0x91,0x84,
//啊,不管你走多远
0x61,0x81,0x92,0x71,0x61,0x71,0x61,0x58,
//无论你在干啥
0x61,0x81,0x81,0x61,0x82,0x81,0x61,0x52,0x61,0x51,0x34,
//到什么时候也离不开
0x62,0xa2,0x91,0x81,0x62,0x88,
//咱的妈
0x62,0xa2,0x91,0x81,0x62,0x84,
//咱的妈
0x81,0x91,0x62,0xf2,0x91,0x81,0x62,0x88,
0XFF,
} ;
uchar code jmszl[]={ //寂寞沙洲冷
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,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,
//是慌乱占据了心扉
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,0x32,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 mamahao[]={ //世上只有妈妈好
//世上只有妈妈好
0x68,0x52,0x34,0x54,0x84,0x62,0x52,0x68,
//世上只有妈妈好
0x34,0x52,0x62,0x54,0x34,0x12,0xc2,0x52,0x32,0x28,
//有妈的孩子像个宝
0x24,0x32,0x54,0x52,0x62,0x34,0x24,0x18,
//投进了妈妈的怀抱
0x54,0x32,0x22,0x12,0xc2,0x12,0xb8,0x04,0xff,
//幸福享不了
};
uchar code exql[]={ //儿行千里
// 儿行千里
0x62,0x61,0x61,0x61,0x72,0x51,0x68,
//衣裳在添几件,
0x62,0x61,0x61,0x61,0x71,0x51,0x38,
//饭菜多吃几口,
0x32,0x31,0x62,0x31,0x21,0x31,0x14,0x22,0x21,0x21,0x12,0x61,0x38,
//出门在外没有妈熬的小米粥,
0x62,0x62,0x61,0x72,0x51,0x68,
//一会儿看看脸,
0x62,0x62,0x61,0x72,0x51,0x38,
//一会儿摸摸手,
0x34,0x62,0x61,0x31,0x22,0x21,0x31,0x14,
//一会儿又把嘱咐的话,
0x22,0x21,0x31,0x12,0x61,0x68,
//装进儿的兜;
0x62,0x84,0x62,0x92,0x84,0x72,0x61,0x71,0x51,0x32,0x31,0x52,0x64,
//如今要到了,离开家的时候,
0x62,0x84,0x62,0x91,0xa1,0x84,0x72,0x61,0x71,0x62,0x52,0x51,0x61,0x34,
//才理解儿行千里母担忧,
0x32,0x62,0x62,0x31,0x21,0x32,0x34,0x02,0x32,0x62,0x62,0x31,0x21,0x12,0x14,0x02,
//千里的路啊,我还一步没走,
0x71,0x72,0x61,0x22,0x31,0x31,0x52,0x31,0x52,0x62,
//就看见泪水在妈妈眼里,
0x82,0x81,0x71,0x61,0x62,0x28,0x62,0x61,0x71,0x52,0x31,0x68,0x68,0xff,
//妈妈眼里流,妈妈眼里流;
};
uchar code ganen[]={//感恩的心
0x12,0x14,0x22,0x32,0x54,
//我来自偶然,
0x32,0x84,0x72,0x62,0x54,
//像一颗尘土,
0x02,0x62,0x62,0x52,0x54,0x12,0x22,0x32,0x28,
//有谁看出我的脆弱,
0x12,0x14,0x22,0x32,0x54,
//我来自何方,
0x32,0x84,0x92,0x82,0x54,
//我情归何处,
0x32,0x24,0x21,0x61,0x54,0x22,0x32,0x12,0x18,
//谁在下一刻呼唤我,
0x22,0x24,0x12,0x24,0x11,0x21,0x34,0x32,0x21,0x31,0x34,
//天地虽宽 这条路却难走
0x12,0x22,0x22,0x22,0x11,0x21,0x22,0x64,0x52,0x52,0x32,0x38,
//我看遍这人间坎坷辛苦
0x31,0x52,0x51,0x52,0x31,0x51,0x58,
//我还有多少爱
0x31,0x82,0x81,0x82,0x31,0x61,0x68,
//我还有多少泪
0x62,0x62,0x62,0x51,0x61,0x64,0x61,0x82,0x61,0x9c,
//要苍天知道 我不认输
0x52,0xa4,0x92,0xa4,0x32,0x84,0x72,0x64,
//感恩的心 感谢有你
0x62,0x94,0x82,0x94,
//伴我一生
0x61,0x81,0x92,0x91,0x91,0x92,0x81,0xa1,0xa2,0x92,0x94,
//让我有勇气做我自己
0x52,0xa4,0x92,0xa4,0x32,0x84,0x72,0x64,
//感恩的心 感谢命运
0x52,0x62,0x81,0x81,0x82,0x92,0xa2,0x94,0x82,0x72,0x82,0x88,
//花开花落我一样会珍惜
};
uchar code tiger[]={//两只老虎
0x14,0x24,0x34,0x14,0x14,0x24,0x34,0x14,
//两只老虎两只老虎
0x34,0x44,0x58,0x34,0x44,0x58,
//跑得快跑得快
0x52,0x61,0x52,0x41,0x34,0x14,0x52,0x61,0x52,0x41,0x34,0x14,
//一只没有眼睛一只没有尾巴
0x14,0xb4,0x18,0x14,0xb4,0x18,0xff,
//真奇怪真奇怪
};
uchar code qizige[]={ //七子之歌
0x54,0x32,0x52,0x32,0x54,
//你可知MACAU
0x62,0x52,0x32,0x62,0x54,
//不是我真姓
0x14,0x12,0x22,0x34,0x52,0x32,
//我离开你太久了
0x02,0x32,0x58,
//母亲
0x52,0x52,0x62,0x52,0x32,0x54,0x52,0x62,0x52,0x82,0x62,0x58,
//但是他们掳去的是我的肉体
0x14,0x52,0x32,0x22,0x12,0x24,0x32,0x54,0x2,0x22,0x34,0x1f,0x18,
//你依然保管我内心的灵魂
0x04,0x54,0xa4,0x92,0x81,0x62,0x52,0x54,0x62,0x64,0x52,0x62,0x81,0xa2,0x82,0x9c,
//那三百年来梦寐不忘的生母啊
0x02,0x52,0xa4,0x92,0x81,0x62,0x52,0x54,
//请叫儿的乳名:
0x62,0x64,0x52,0x64,0xa2,0x92,0x9f,
//叫我一声--澳门
0xa4,0x92,0x81,0x62,0x52,0x54,
//母亲!母亲!
0x84,0x62,0x52,0x32,0x22,0x14,
//我要回来
0x04,0x22,0x32,0x58,0x58,0x04,0x52,0x62,0x8f,0xff,
//母亲!母亲!
};
uchar code qnzl[]={ //千年之恋
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,
//七色的国度 不断飘逸风中
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,0x71,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,0x93,0x89,0xff//结束标志
//用一生守候
};
//----------------------------简谱音调对应的定时器初值---------------------------
//适合11.0592M的晶振
uchar code cuzhi[]={
0xff,0xff,//占位
0xFC,0x8E,//中央C调1-7
0xFC,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 yinyue[]={0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0x0,0x0};//将节拍转换成灯亮的节奏
void delay1(uint z); //延时1MS
void delay(uint z); //延时165MS,即十六分音符
void song();
void beep();//蜂鸣器叫一声
main()
{
P1=shuzi0;
EA=1;//开总中断
EX0=1;//开外部中断0
IT0=1;//外部中断0下降沿触发方式
EX1=1;//开外部中断1
IT1=1;//外部中断1下降沿触发方式
TMOD=0x01;//定时器0工作在方式1
TH0=0;
TL0=0;
ET0=1;
while(1)
{
if(count2!=0)
{
switch(count2)
{
case 1:
{
song();
break;
}
break;
}
}
else
{
}
}
}
/*void key1() interrupt3
{
EA=1;
EX0=1;
IT0=0;
}
*/
void int1() interrupt 2 //用于按键key2引起的中断
{
EA=0;//关总中断
delay1(1);//去抖
if(key2==0)
{
TR0=1;
i=0;//从头开始唱
count2++;
if(count2==9)
count2=1;
}
EA=1;//开总中断
}
void timer0() interrupt 1 //用于产生各种音调
{
TH0=timeh;
TL0=timel;
fm=~fm;
}
void song()
{
uint temp;
uchar jp;//jp是简谱
int i=0;
while(1)
{
if(count2==1) //选曲
{ P1=shuzi1;
if(key1==0)
while(1)
{
fm=0;
if(key1==1)
break;
}
temp=muqin[i];}
if(count2==2)
{P1=shuzi2;
if(key1==0)
while(1)
{
fm=0;
if(key1==1)
break;
}temp=jmszl[i];}
if(count2==3)
{P1=shuzi3;
if(key1==0)
while(1)
{
fm=0;
if(key1==1)
break;
}temp=mamahao[i];}
if(count2==4)
{P1=shuzi4;
if(key1==0)
while(1)
{
fm=0;
if(key1==1)
break;
}temp=exql[i];}
if(count2==5)
{ P1=shuzi5; if(key1==0)
while(1)
{
fm=0;
if(key1==1)
break;
}temp=ganen[i];}
if(count2==6)
{ P1=shuzi6;
if(key1==0)
while(1)
{
fm=0;
if(key1==1)
break;
}temp=tiger[i];}
if(count2==7)
{P1=shuzi7;
if(key1==0)
while(1)
{
fm=0;
if(key1==1)
break;
}temp=qizige[i];}
if(count2==8)
{P1=shuzi8;
if(key1==0)
while(1)
{
fm=0;
if(key1==1)
break;
} temp=qnzl[i];}
if(temp==0xff)
break;
jp=temp/16; //取数的高4位
P0=yinyue[jp];
if(jp!=0)
{
timeh=cuzhi[jp*2];
timel=cuzhi[jp*2+1];
}
else
{
TR0=0;
fm=1;//关蜂鸣器
}
delay(temp%16); //取数的低4位
TR0=0; //唱完一个音停10MS
fm=1;
delay1(10);
TR0=1;
i++;
}
TR0=0;
fm=1;
}
void delay(uint z) //延时165MS,即十六分音符
{ uint x,y;
for(x=z;x>0;x--)
for(y=19000;y>0;y--);
}
void delay1(uint z) //延时1MS
{ uint x,y;
for(x=z;x>0;x--)
for(y=112;y>0;y--);
}
void beep() //蜂鸣器叫一声
{ uchar i;
for(i=0;i<50;i++)
{ fm=~fm;
delay1(1);
}
fm=1;
}
|