《单片机原理与应用课程设计》说明书
本设计是以AT89C51芯片的电路为基础,利用keil和proteus仿真软件,设计出一个多功能音乐盒。音乐盒主要由五大模块构成,包括AT89C51芯片、4*4矩阵键盘、蜂鸣器、晶振复位电路和12864液晶显示器。有开机键(开机时显示welcom),暂停键、播放键、上一曲、下一曲以及10个用来选择歌曲的键。此外用户可以按照自己的喜好选择音乐并将其转化成机器码存入单片机的存储器中。对于不同型号的单片机只需要相应的改变一下地址即可。该软、硬件系统具有很好的通用性,很高的实际使用价值。
2.1芯片AT89C51的介绍 AT89C51是一种带4K字节闪存可编程可擦除只读存储器(FPEROM—Flash Programmable and Erasable Read Only Memory)的低电压,高性能CMOS 8位微处理器,俗称单片机。AT89C2051是一种带2K字节闪存可编程可擦除只读存储器的单片机。单片机的可擦除只读存储器可以反复擦除100次。该器件采用ATMEL高密度非易失存储器制造技术制造,与工业标准的MCS-51指令集和输出管脚相兼容。由于将多功能8位CPU和闪烁存储器组合在单个芯片中,ATMEL的AT89C51是一种高效微控制器,AT89C2051是它的一种精简版本。AT89C51单片机为很多嵌入式控制系统提供了一种灵活性高且价廉的方案。外形及引脚排列如图2.1所示 图3.2 AT89C51引脚排列图 2.2 LCD12864的显示 12864是一种图形点阵液晶显示器,它主要由行驱动器/列驱动器及128×64全点阵液晶显示器组成。它有8页(8行一页)、128列,可完成图形显示,也可以显示8×4个汉字。 12864硬件模块说明: 图2.2中,IC1为行驱动器,IC2、IC3为行驱动器,外部的CPU通过13根线对模块进行控制。其中DB7—DB0为并行数据总线,E、R/W、D均为控制信号线,CSA、CSB则为选屏信号,分别控制左、右半屏。 图2.2 12864的硬件模块图 2.3 音调的产生 频率的高低决定了音调的高低。音乐的十二平均率规定:每两个八度音(如简谱中的中音1和高音1)之间的频率相差一倍。在两个八度音之间又分为十二个半音。另外,音名A(简谱中的低音6)的频率为440Hz,音名B到C之间、E到F之间为半音,其余为全音。由此可以计算出简谱中从低音1到高音1之间每个音名对应的频率,所有不同频率的信号都是从同一个基准频率分频得到的。 1、要产生音频脉冲,只要算出某一音频的周期(1/频率),然后将此周期除以2,即为半周期的时间。利用定时器计时这半个周期时间,每当计时到后就将输出脉冲的I/O反相,然后重复计时此半周期时间再对I/O反相,就可在I/O脚上得到此频率的脉冲。 2、利用AT89C51的内部定时器使其工作在计数器模式MODE1下,改变计数值TH0及TL0以产生不同频率的方法。 此外结束符和休止符可以分别用代码00H和FFH来表示,若查表结果为00H,则表示曲子终了;若查表结果为FFH,则产生相应的停顿效果。 3、例如频率为523Hz,其周期T=1/523=1912us,因此只要令计数器计时956us/1us=956,在每次技术956次时将I/O反相,就可得到中音DO(523Hz)。 计数脉冲值与频率的关系公式如下: N=Fi2Fr N:计算值; Fi:内部计时一次为1us,故其频率为1MHz; 4、其计数值的求法如下: 初值T=65536-N=65536-Fi2Fr 例如:设K=65536,F=1000000=Fi=1MHz,球低音DO(261Hz)。中音DO(523Hz)。高音的DO(1046Hz)的计算值 T=65536-N=65536-Fi2Fr=65536-10000002Fr=65536-500000/Fr 低音DO的T=65536-500000/262=63627 低音DO的T=65536-500000/523=64580 低音DO的T=65536-500000/1047=65059 表2.3 C调各音符频率与计数值T的对照表
2.4 节拍的确定 若要构成音乐,光有音调是不够的,还需要节拍,让音乐具有旋律(固定的律动),而且可以调节各个音的快满度。“节拍”,即Beat,简单说就是打拍子,就像我们听音乐不自主的随之拍手或跺脚。若1拍实0.5s,则1/4 拍为0.125s。至于1拍多少s,并没有严格规定,就像人的心跳一样,大部分人的心跳是每分钟72下,有些人快一点,有些人慢一点,只要听的悦耳就好。音持续时间的长短即时值,一般用拍数表示。休止符表示暂停发音。 一首音乐是由许多不同的音符组成的,而每个音符对应着不同频率,这样就可以利用不同的频率的组合,加以与拍数对应的延时,构成音乐。了解音乐的一些基础知识,我们可知产生不同频率的音频脉冲即能产生音乐。对于单片机来说,产生不同频率的脉冲是非常方便的,利用单片机的定时/计数器来产生这样的方波频率信号。因此,需要弄清楚音乐中的音符和对应的频率,以及单片机定时计数的关系。 表2.41节拍与节拍码对照
每个音符使用1个字节,字节的高4位代表音符的高低,低4位代表音符的节拍,表2.41为节拍码的对照。如果1拍为0.4秒,1/4拍实0.1秒,只要设定延迟时间就可求得节拍的时间。假设1/4拍为1DELAY,则1拍应为4DELAY,以此类推。所以只要求得1/4拍的DELAY时间,其余的节拍就是它的倍数,如图5.3为1/4和1/8节拍的时间设定。 表2.42 1/4和1/8节拍的时间设定
2.5 音符的编码 do re mi fa so la si分别编码为1~7,重音do编为8,重音re编为9,停顿编为0。播放长度以十六分音符为单位(在本程序中为165ms),一拍即四分音符等于4个十六分音符,编为4,其它的播放时间以此类推。音调作为编码的高4位,而播放时间作为低4位,如此音调和节拍就构成了一个编码。以0xff作为曲谱的结束标志。 举例1:音调do,发音长度为两拍,即二分音符,将其编码为0x18 举例2:音调re,发音长度为半拍,即八分音符,将其编码为0x22 歌曲播放的设计。先将歌曲的简谱进行编码,储存在一个数据类型为unsigned char 的数组中。程序从数组中取出一个数,然后分离出高4位得到音调,接着找出相应的值赋给定时器0,使之定时操作蜂鸣器,得出相应的音调;接着分离出该数的低4位,得到延时时间,接着调用软件延时。 3.1设计思路 程序设计部分主要有:字模部分、LCD12864显示、简谱音调及节拍、计时、键盘扫描部分。硬件设计部分见下图3.11: 设计思路见如下实验控制流程图3.12: 3.2 设计程序见附件 1、按下开机键ON/C 2、按下歌曲键0播放第一首歌 3、操作说明 4×4键盘共16个键,操作说明如下: “0”:歌曲0,《母亲》 “1”:歌曲1,《世上只有妈妈好》 “2”:歌曲2,《儿行千里》 “3”:歌曲3,《感恩的心》 “4”:歌曲4,《七子之歌》 “5”:歌曲5,《小青蛙》 “6”:歌曲6,《找朋友》 “7”:歌曲7,《千年之恋》 “8”:歌曲8,《两只老虎》 “9”:歌曲9,《寂寞沙洲冷》 “ON/C”:开机键 “=”:暂停键,此时音乐和播放时间都暂停 “×”(乘号):播放键 “+”:下一曲,播放下一首歌曲 “-”:上一曲,播放上一首歌曲 参考资料 [1] 谭浩强.C语言程序设计(第二版)[M],北京:清华大学出版社,1991. [2] 曾屹.单片机原理与应用(第一版)[M],中南大学出版社,2009.
单片机源程序如下:
- /* C语言音乐盒源程序设计 */
- #include <reg51.h>
- #include <intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar count=0,count1=0; //count1 歌曲标志
- uchar key,count2,h=1,i;
- uchar temp; //temp歌调
- uchar s1,s2,m1,m2;
- uchar second,minute,j=0;
- void delay1(uint z); //延时1ms
- sbit key2=P3^2; // 按key2可切换歌曲
- sbit key1=P3^3;
- sbit fm=P3^7;//蜂鸣器连续的IO口
- sbit rs=P2^2;
- sbit rw=P2^1;
- sbit e=P2^0;
- sbit busy=P0^0;
- sbit CS1=P2^4;
- sbit CS2=P2^3;
- //==================字模====================//
- char code shu[22][8]={
- {0xFF,0x1F,0xEF,0xF7,0xF7,0xEF,0x1F,0xFF},
- {0xFF,0xF0,0xEF,0xDF,0xDF,0xEF,0xF0,0xFF},/*"0",0*/
- {0xFF,0xEF,0xEF,0x07,0xFF,0xFF,0xFF,0xFF},
- {0xFF,0xDF,0xDF,0xC0,0xDF,0xDF,0xFF,0xFF},/*"1",1*/
- {0xFF,0x8F,0xF7,0xF7,0xF7,0x77,0x8F,0xFF},
- {0xFF,0xCF,0xD7,0xDB,0xDD,0xDE,0xCF,0xFF},/*"2",2*/
- {0xFF,0xCF,0xF7,0x77,0x77,0xB7,0xCF,0xFF},
- {0xFF,0xE7,0xDF,0xDF,0xDF,0xEE,0xF1,0xFF},/*"3",3*/
- {0xFF,0xFF,0x3F,0xDF,0xEF,0x07,0xFF,0xFF},
- {0xFF,0xF8,0xFB,0xDB,0xDB,0xC0,0xDB,0xFF},/*"4",4*/
- {0xFF,0x07,0xF7,0x77,0x77,0xF7,0xF7,0xFF},
- {0xFF,0xE6,0xDE,0xDF,0xDF,0xEE,0xF1,0xFF},/*"5",5*/
- {0xFF,0x1F,0xEF,0x77,0x77,0xE7,0xFF,0xFF},
- {0xFF,0xF0,0xEE,0xD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0xFF,0xFF,0xFF,0xFF},/*" ",3*/
- {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},/*" ",4*/
- {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},/*" ",5*/
- {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},/*" ",6*/
- {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},/*" ",7*/
- };
-
- /* 于键消抖的延时函数 */
- void delay5()
- { uint t;
- for (t=400;t>0;t--);
- }
-
- /*======音乐按键扫描函数======= */
- uchar keyscan(void) //键盘扫描
- { {unsigned char key_l,key,s;
- key_l=P1&0x0f;
- if(key_l!=0x0f) // 判断是否有按键按下
- { delay5() ; //消抖
- if(key_l!=0x0f) //再次判断是否有按键按下
- {
- key_l=P1&0x0f; //扫描列 得到列值
- P1=0X7f; //0111 1111
- if(P1!=0x7f) key=P1;
- P1=0Xbf; //1011 1111
- if(P1!=0xbf) key=P1;
- P1=0Xdf;
- if(P1!=0xdf) key=P1;
- P1=0Xef;
- if(P1!=0xef) key=P1;
- P1=0x0f;
- } delay1(1000);
- }
- switch(key)
- {
- case 0xeb: count1=1;i=0; TR1=1;second=0;s1=0;s2=0; break;
- case 0xd7: count1=2;i=0; TR1=1;second=0;s1=0;s2=0; break;
- case 0xdb: count1=3;i=0; TR1=1;second=0;s1=0;s2=0; break;
- case 0xdd: count1=4;i=0; TR1=1;second=0;s1=0;s2=0; break;
- case 0xb7: count1=5;i=0; TR1=1;second=0;s1=0;s2=0; break;
- case 0xbb: count1=6;i=0; TR1=1;second=0;s1=0;s2=0; break;
- case 0xbd: count1=7;i=0; TR1=1;second=0;s1=0;s2=0; break;
- case 0x77: count1=8;i=0; TR1=1;second=0;s1=0;s2=0; break;
- case 0x7b: count1=9;i=0; second=0;s1=0;s2=0; TR1=1; break;
- case 0x7d: count1=10;i=0; second=0;s1=0;s2=0; TR1=1; break;
- case 0xe7: count2=1; break; //开机键ON/C
- case 0xed: count2=2;h=0; s=second;break; //暂停键 =
- case 0xee: count1=count1+1;i=0; delay1(100); TR1=1;second=0;s1=0;s2=0; break; //下一曲 +
- case 0xde: count1=count1-1;i=0; delay1(100); TR1=1; second=0;s1=0;s2=0; break; //上一曲 -
- case 0xbe: count2=5;h=1; TR0=1; s=second; break; TR1=1; //播放键
- default:break;
- }
- P1 = 0x0f;
- }
- }
- //=======外部中断INT0==========//
- void ZD() interrupt 0
- {
- keyscan();
- }
- //===========显示延迟=======================//
- delay2(int a)
- {int b;
- for(;a>0;a--)
- for(b=0;b<255;b++);
- }
- check() //查忙
- {e=1;
- rw=1;
- rs=0;
- P0=0xff;
- if(busy);
- }
- /*写指令程序*/
- wc(unsigned char dat)
- {check();
- e=0;
- rw=0;
- rs=0;
- P0=dat;
- e=1;
- e=0;
- }
- /* 写数据程序*/
- wd(unsigned char dat)
- {check();
- e=0;
- rw=0;
- rs=1;
- P0=dat;
- e=1;
- e=0;
- }
-
- void zifu(unsigned char page,unsigned char lineadd,int n,int a, unsigned char table[][8])
- { int j,k,i;
- unsigned char temp[16];
- if(lineadd<0X80) //128列
- {CS1=0;
- CS2=1;} //左半屏left
- for(j=2*a;j<n+2*a;j++)
- {
- if(lineadd>=0X80)
- {
- CS1=1; //right
- CS2=0;
- lineadd=lineadd-0X40;
- }
- for(k=0;k<8;k++)
- {temp[k]=table[j][k];}
- j+=1;
- for(k=0;k<8;k++)
- {temp[8+k]=table[j][k];}
- wc(page);
- wc(lineadd);
- for(i=0;i<8;i++)
- { wd(temp[i]);}
- wc(page+1);
- wc(lineadd);
- for(i=8;i<16;i++)
- { wd(temp[i]);}
- lineadd+=8;
- } }
- void hanzi(unsigned char page,unsigned char lineadd,int n,unsigned char table[][16])
- {unsigned char temp[32];
- int j,k,i;
- if(lineadd<0X80)
- {CS1=0;
- CS2=1;} //left
- for(j=0;j<n;j++)
- {
- if(lineadd>=0X80)
- {
- CS1=1; //right
- CS2=0;
- lineadd=lineadd-0X40;
- }
- for(k=0;k<16;k++)
- {temp[k]=table[j][k];}
- j+=1;
- for(k=0;k<16;k++)
- {temp[16+k]=table[j][k];}
- wc(page);
- wc(lineadd);
- for(i=0;i<16;i++)
- { wd(temp[i]);}
- wc(page+1);
- wc(lineadd);
- for(i=16;i<32;i++)
- { wd(temp[i]);}
- lineadd+=16;
- }
- }
-
- //------------------简谱音调对应的定时器初值--------//
- //适合11.0592M的晶振
- uchar code cuzhi[]={
- 0xff,0xff,//占位 停顿
- 0xFC,0x8E,//中音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
- };
- /* 函数声明*/
- void delay1(uint z);//延时1mS
- void delay(uint z); //延时165ms,即十六分音符
- void song();
- void beep(); //蜂鸣器叫一声
- /* 初始化程序 */
- void inti()
- { wc(0X3f);//显示开关关 0011 1111
- wc(0XC0);//修改显示起始行 1100 0000
- wc(0XB8);//修改页地址,x地址 1011 1000
- wc(0X40);//修改列地址,y地址 0100 0000
- }
-
- uchar timeh,timel,i;
- //---------------------------简谱---------------------------------------
- //编程规则:字节高位是简谱,低位是节拍持续时间,
- //代表多少个十六分音符
- //1-7代表中音,8-E代表高音,0代表停顿
- //最后的0是结束标志
- //===================== 歌曲 ============//
- 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 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 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//结束标志
- //用一生守候
- };
- 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 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 xqw[]={//小青蛙
- 0x52,0x32,0x32,0x32,0x52,0x32,0x32,0x32,0x54,0x61,0x52,0x32,0x42,0x24,
- //小青蛙呀 小青蛙呀 在池塘里玩耍
- 0x42,0x22,0x22,0x22,0x42,0x22,0x22,0x22,0x44,0x51,0x42,0x22,0x32,0x18,
- //东边跳跳 西边跳跳 多么快乐 逍遥
- };
- char code zpy[]={//找朋友
- 0x14,0x14,0x14,0x24,0x34,0x54,0x58,0x54,0x64,0x54,0x34,0x24,0x34,0x24,
- //找找找 找朋友 找到一个好朋友
- 0x34,0x14,0x18,0x54,0x34,0x28,0x14,0x24,0x34,0x54,0x24,0x34,0x14,
- //敬个礼 握握手 我是你的好朋友
- };
-
- //===========计时程序=========//
- void jishi()
- { s1=s2=m1=m2=0;
- s1=second/10; //秒十位
- s2=second%10; //秒个位
- m1=minute/10;
- m2=minute%10;
- }
- void timer() interrupt 3 //T1分秒计时
- { TH1=15536/256;
- TL1=15536%256;
- j++;
- if(j==20)
- {j=0;
- if(second++>=60)
- {second=0;
- minute++;
- }
- }
- }
- void show()
- {jishi();
- zifu(0xba,0x40,2,m1,&shu);
- zifu(0xba,0x48,2,m2,&shu);
- zifu(0xba,0x50,2,0x0a,&shu);
- zifu(0xba,0x58,2,s1,&shu);
- zifu(0xba,0x60,2,s2,&shu);
-
- }
-
- //=========唱歌显示歌名============//
- void song()
- {
- uint temp; //temp歌调
- uchar jp; //jp是简谱
- while(1)
- { if(h==0)
- { do{TR0=0; //停止T0工作
- fm=1;}while(h==0);}
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
单片机课程设计-数字音乐盒设计.doc
(338 KB, 下载次数: 105)
|