- #include <reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit key1=P3^2;//按key1可切换下一曲
- sbit key2=P3^3;//按key2可切换上一曲
- sbit speaker=P3^7;//扬声器输出口
- char count;//歌曲标志
- uchar timeh,timel,i,k=0,counter=0;//用到的各个变量
- uchar code graph[] = //8*8点阵动态图数据
- {
- 0x00,0x82,0x82,0x86,0xA6,0xB7,0xFF,0xFF,
- 0x00,0x00,0x00,0x10,0x12,0x9B,0xBF,0xFF,
- 0x00,0x00,0x00,0x80,0xCA,0xEE,0xFF,0xFF,
- 0x42,0x42,0x52,0x52,0x73,0x7B,0xFB,0xFF,
- 0x42,0x42,0x66,0x76,0xFE,0xFF,0xFF,0xFF,
- 0x04,0x04,0x44,0x4E,0x4E,0x7F,0xFF,0xFF,
- 0x08,0x88,0x8A,0x8E,0xAE,0xFF,0xFF,0xFF,
- 0x10,0x10,0x12,0x1A,0x1A,0x9B,0xFF,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 ldzgr[]=
- {
- 0x52,0x82,0x82,0x52,0x62,0x62,0x54,0x32,0x52,0x12,0x32,0x28,
- //太阳光,金亮亮,雄鸡唱三唱;
- 0x52,0x84,0x52,0x62,0x62,0x54,0x52,0x81,0xA1,0x92,0x52,0x88,
- //花儿 醒来了,鸟儿忙梳妆
- 0x83,0x91,0x82,0x52,0x62,0x62,0x54,0x33,0x81,0x62,0x52,0x12,0x32,0x24,
- //小喜鹊 造新房,小蜜蜂 采蜜糖
- 0x12,0x11,0x21,0x32,0x51,0x51,0x62,0x52,0x84,0x82,0x51,0x61,0x84,0xA4,0x92,
- 0x52,0x86,0x02,
- //幸福的生活从哪里来?要靠劳动来创造
- 0x52,0x81,0x81,0x82,0x52,0x62,0x61,0x81,0x54,0x32,0x51,0x61,0x53,0x31,0x12,
- 0x32,0x24,
- //青青的叶儿 红红的花,小蝴蝶 贪玩耍
- 0x52,0x82,0x82,0x52,0x62,0x62,0x54,0x51,0x61,0x81,0xA1,0x92,0x52,0x88,
- //不爱劳动 不学习,我们大家不学它
- 0x83,0x91,0x82,0x52,0x62,0x62,0x54,0x33,0x81,0x62,0x52,0x12,0x32,0x24,
- //要学喜鹊 造新房,要学蜜蜂 采蜜糖
- 0x12,0x11,0x21,0x32,0x52,0x82,0x52,0x68,0x52,0x61,0x61,0x84,0xA4,0x92,0x52,
- 0x84,0xff//歌曲结束符号
- //劳动的快乐 说不尽,劳动的创造 最光荣
- };
- //—————————————————唯一——————————————————//
- uchar code wy[]=
- {
- 0x04,0x43,0x43,0x43,0x33,0x23,0x13,0x33,0x54,0x83,0x83,0x93,0xA3,0x92,0x81,
- 0x63,0x62,0xA3,0x93,0x83,0x96,0x04,0x04,
- //最近我无法呼吸,连自己的影子也都想逃避
- 0xA4,0x94,0x82,0x82,0x82,0x52,0x82,0x92,0xA4,
- //Ba By 你就是我的唯一
- 0x72,0x72,0x72,0x52,0x72,0x82,0x94,0x04,0xA2,0xA2,0xB2,0xA2,0x82,0x92,
- //两个世界都变心,回去谈何容易
- 0x04,0xA4,0x94,0x82,0x82,0x82,0x52,0x82,0x92,0xA4,
- //确定 你就是我的唯一
- 0x72,0x72,0x72,0x52,0x72,0x82,0x92,0xA2,0x84,0x64,0x03,0x51,0xB2,0xA2,0x82,
- 0x61,0x51,
- //独自对着电话说我爱你,我真的爱你
- 0x04,0xA4,0x94,0x82,0x82,0x82,0x82,0x72,0x82,0x52,0x32,0x68,
- //BABY 我已不能多爱你一些
- 0x02,0xA4,0x94,0x82,0x82,0x82,0x82,0x72,0x82,0x54,0x42,0x66,0xff
- //其实 早已超过了爱的极限
- };
- //————————————————同桌的你——————————————————//
- uchar code tzdn[]=
- {
- 0x52,0x52,0x52,0x52,0x32,0x42,0x56,0x86,0x62,0x62,0x62,0x62,0x42,0x62,0x56,
- 0x04,
- //明天你是否会想起,昨天你写的日记
- 0x52,0x52,0x52,0x52,0x72,0x62,0x52,0x44,0x02,0x42,0x42,0x42,0x42,0x33,0x21,
- 0x16,0x02,
- //明天你是否还惦记,曾经最爱哭的你
- 0x82,0x82,0x82,0x82,0x52,0x32,0x86,0x82,0xA4,0x92,0x92,0x92,0x93,0x81,0x72,
- 0x66,0x02,
- //谁娶了多愁善感的你,谁看了你的日记
- 0x72,0x72,0x72,0x72,0x72,0x82,0x96,0x54,0x02,0x72,0x72,0x82,0x92,0x82,0x72,
- 0x16,0x02,
- //谁把你的长发盘起,谁给你做的嫁衣
- 0x84,0x82,0x82,0x52,0x62,0x86,0xA6,0x94,0x92,0x92,0x82,0x72,0x66,0x74,0x72,
- 0x72,0x72,0x82,0x96,0x56,
- //啦……,啦……,啦……
- 0x72,0x72,0x82,0x92,0x82,0x72,0x86,0x94,0x92,0x92,0x62,0x72,0x96,0xB6,0x94,
- 0x92,0x92,0x82,0x72,0x66,
- //啦……,啦……,啦……
- 0x72,0x72,0x72,0x72,0x72,0x82,0x96,0x56,0x72,0x72,0x82,0x92,0x82,0x72,0x96,
- 0x86,0xff
- //啦……,啦……,啦……,啦……
- };
- //———————————————小小葫芦娃—————————————————//
- uchar code hlw[]=
- {
- 0x12,0x12,0x35,0x11,0x12,0x31,0x02,
- //葫芦娃,葫芦娃
- 0x62,0x62,0x61,0x51,0x62,0x51,0x12,0x31,0x02,
- //一根藤上七朵花
- 0x81,0x61,0x61,0x51,0x65,0x51,0x12,0x21,0x02,
- //风吹雨打都不怕
- 0x75,0x51,0x32,0x58,
- //啦啦啦啦
- 0x81,0x01,0x61,0x61,0x51,0x51,0x62,0x61,0x01,
- //叮当当冬冬当当
- 0x52,0x11,0x32,0x02,0x81,0x01,0x61,0x61,0x51,0x51,0x61,0x61,0x01,0x51,0x11,
- 0x22,0x02,
- //葫芦娃,叮当当冬冬当当,七朵花
- 0x35,0x11,0x62,0x18,
- //啦啦啦啦
- 0x31,0x52,0x61,0x31,0x52,0x61,
- //葫芦娃,葫芦娃
- 0x85,0x01,0x71,0x52,0x65,0x02,0xff
- //七朵花
- };
- //————————————————千年之恋 ————————————————//
- uchar code qnzl[]=
- {
- 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[]={256,293,329,349,392,440,494,523,586,658,697,783,879,987};
- void delay(uint z) //延时165MS,即十六分音符
- {
- uint x,y;
- for(x=z;x>0;x--)
- for(y=13333;y>0;y--);
- }
- void delay1(uint z) //延时1MS
- {
- uint x,y;
- for(x=z;x>0;x--)
- for(y=120;y>0;y--);
- }
- void timer0() interrupt 1 //定时器0,用于产生各种音调
- {
- TH0=timeh;
- TL0=timel;
- speaker=~speaker;
- }
- void song() //播放歌曲函数
- {
- uint temp;
- uchar jp;//jp是简谱
- i=0;
- temp=tzdn[i]; //同桌的你
- jp=temp/16; //取数的高4位
- if(jp!=0)
- {
- timeh=(65536-1/cuzhi[jp])/256;
- timel=(65536-1/cuzhi[jp])%256;
- }
- else
- {
- TR0=0;
- speaker=1;//关扬声器
- }
- delay(temp%16); //取数的低4位
- TR0=0; //唱完一个音停10MS
- speaker=1;
- delay1(10);
- TR0=1;
- i++;
- }
- void main()
- {
- count=0;//不唱歌
- TMOD=0x11;//定时器工作方式
- TH0=0;
- TL0=0; //定时器0赋初值
- ET0=1; //定时器0溢出中断使能
- TR1 = 1; //开始计时
- ET1 = 1; //定时器1溢出中断使能
- while(1)
- {
- song();
- delay1(1000);
- }
- }
复制代码 |