单片机音乐盒,1602液晶显示歌曲名、歌手名、播放时间,播放时跑马灯亮

时间:2019-05-15 10:05:46下载本文作者:会员上传
简介:写写帮文库小编为你整理了多篇相关的《单片机音乐盒,1602液晶显示歌曲名、歌手名、播放时间,播放时跑马灯亮》,但愿对你工作学习有帮助,当然你在写写帮文库还可以找到更多《单片机音乐盒,1602液晶显示歌曲名、歌手名、播放时间,播放时跑马灯亮》。

第一篇:单片机音乐盒,1602液晶显示歌曲名、歌手名、播放时间,播放时跑马灯亮

单片机音乐盒,1602液晶显示歌曲名、歌手名、播放时间,播放时跑

马灯亮

2010-07-16 19:05:08| 分类: 单片机 | 标签: |字号大中小 订阅

/**P2.0口到三极管基极之间的限流电阻接1K左右的,要使用无缘的蜂鸣器或者照片中的小喇叭,用有源的蜂鸣器失真太大,单片机使用AT89S52**/

#include #include #define uint unsigned int #define uchar unsigned char

#define LCD1602_DATA P0 //1602液晶数据口

#define lamp_data P3 //跑马灯数据口 sbit LCD1602_RS=P2^7;//1602液晶写命令/数据 sbit LCD1602_RW=P2^6;//1602液晶读/写控制 sbit LCD1602_EN=P2^5;//1602液晶使能控制

sbit BeepIO = P2^0;//蜂鸣器 sbit esc=P1^2;//取消播放音乐

sbit up=P1^0;sbit down=P1^3;sbit play=P1^1;char number;//歌曲编号 bit flag;//播放标志

char t;

uchar ms50;//跑马灯用 char count,sec,min;//歌曲时间显示

char code song[][17]={ “1.Fairy Tale ”,“2.Love Transfer ”,“3.Girl With Wing”, “4.The Same Song ”,“5.Two Butterfly ”,“6.Coral Sea ”};char code singer[][12]={ “Guang liang”,“Chen yixun ”,“Rong zuer ”, “Liu chang ”,“Pang long ”,“Zhou jielun”};uchar code lamp[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};

//以下为播放音乐的设置 #define SYSTEM_OSC 12000000 #define SOUND_SPACE 4/5 uint code FreTab[12] = { 262,277,294,311,330,349,369,392,415,440,466,494 };//原始频率表

uchar code SignTab[7] = { 0,2,4,5,7,9,11 };//1~7在频率表中的位置

uchar code LengthTab[7]= { 1,2,4,8,16,32,64 };uchar Sound_Temp_TH0,Sound_Temp_TL0;//音符定时器初值暂存

uchar Sound_Temp_TH1,Sound_Temp_TL1;//音长定时器初值暂存

bit stop;/***********************延时函数(单位ms)**************************/

void delay(uint z)

{ uint x;uchar y;for(x=z;x>0;x--)for(y=112;y>0;y--);

} /*********************************************************** ******************LCD1602驱动程序****************** ************************************************************/ /***********************************************************

忙检测

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

void LCD1602_check_busy()

{

LCD1602_DATA = 0xff;LCD1602_RS = 0;LCD1602_RW = 1;LCD1602_EN = 1;while(LCD1602_DATA & 0x80);

LCD1602_EN = 0;

} /**********************************************************

写指令

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

void LCD1602_write_cmd(uchar cmd)

{

LCD1602_check_busy();LCD1602_RS = 0;LCD1602_RW = 0;LCD1602_DATA = cmd;LCD1602_EN = 1;

_nop_();LCD1602_EN = 0;

} /***********************************************************

写数据

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

void LCD1602_write_data(uchar dat)

{

LCD1602_check_busy();LCD1602_RS = 1;LCD1602_RW = 0;LCD1602_DATA = dat;LCD1602_EN = 1;

_nop_();LCD1602_EN = 0;

}

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

1602初始化

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

void LCD1602_init()

{ LCD1602_write_cmd(0x38);//8位数据,双列显示,5*7字形 LCD1602_write_cmd(0x0c);//开显示,关光标,光标不闪烁

LCD1602_write_cmd(0x01);//清屏

} /************************************************************

设置显示坐标

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

void LCD1602_set_postion(uchar x , uchar y)

{ if(!y)

LCD1602_write_cmd(0x80+x);

else if(y)

LCD1602_write_cmd(0xc0+x);

} /************************************************************

指定位置写字符

*************************************************************/ void LCD1602_write_char(uchar x , uchar y , uchar chardata)

{

LCD1602_set_postion(x,y);LCD1602_write_data(chardata);

} /************************************************************

指定位置写字符串

*************************************************************/ void LCD1602_write_string(uchar x , uchar y , uchar *string)

{

LCD1602_set_postion(x,y);

while((*string)!= '')

{

LCD1602_write_data(*string);

string++;

} } /********************************************************************

************播放音乐函数************ ********************************************************************/

void InitialSound()

{

BeepIO = 0;

Sound_Temp_TH1 =(65535-(1/1200)*SYSTEM_OSC)/256;// 计算TL1应装入的初值(10ms的初装值)Sound_Temp_TL1 =(65535-(1/1200)*SYSTEM_OSC)%256;// 计算TH1应装入的初值

TH1 = Sound_Temp_TH1;TL1 = Sound_Temp_TL1;

TMOD |= 0x11;ET0 = 1;ET1 = 0;TR0 = 0;TR1 = 0;EA = 1;

}

void BeepTimer0()interrupt 1 //音符发生中断

{

if(esc==0)

{ delay(5);if(esc==0)stop=1;while(!esc);

} //////////////// BeepIO =!BeepIO;TH0 = Sound_Temp_TH0;TL0 = Sound_Temp_TL0;

} //************************************************************************** void Play(unsigned char *Sound,unsigned char Signature,unsigned Octachord,unsigned int Speed)

{

unsigned int NewFreTab[12];//新的频率表

unsigned char i,j;unsigned int Point,LDiv,LDiv0,LDiv1,LDiv2,LDiv4,CurrentFre,Temp_T,SoundLength;unsigned char Tone,Length,SL,SH,SM,SLen,XG,FD;for(i=0;i<12;i++)// 根据调号及升降八度来生成新的频率表

{

j = i + Signature;

if(j > 11)

{ j = j-12;

NewFreTab[i] = FreTab[j]*2;

} else

NewFreTab[i] = FreTab[j];

if(Octachord == 1)NewFreTab[i]>>=2;else if(Octachord == 3)NewFreTab[i]<<=2;

}

SoundLength = 0;while(Sound[SoundLength]!= 0x00)//计算歌曲长度

{

SoundLength+=2;

} Point = 0;

Tone = Sound[Point];Length = Sound[Point+1];// 读出第一个音符和它时时值

LDiv0 = 12000/Speed;// 算出1分音符的长度(几个10ms)

LDiv4 = LDiv0/4;// 算出4分音符的长度

LDiv4 = LDiv4-LDiv4*SOUND_SPACE;// 普通音最长间隔标准

TR0 = 0;TR1 = 1;

while(Point < SoundLength)

{

SL=Tone%10;//计算出音符

SM=Tone/10%10;//计算出高低音

SH=Tone/100;//计算出是否升半

CurrentFre = NewFreTab[SignTab[SL-1]+SH];//查出对应音符的频率

if(SL!=0)

{

if(SM==1)CurrentFre >>= 2;//低音

if(SM==3)CurrentFre <<= 2;//高音

Temp_T = 65536-(50000/CurrentFre)*10/(12000000/SYSTEM_OSC);//计算计数器初值

Sound_Temp_TH0 = Temp_T/256;Sound_Temp_TL0 = Temp_T%256;

TH0 = Sound_Temp_TH0;

TL0 = Sound_Temp_TL0 + 12;//加12是对中断延时的补偿

} SLen=LengthTab[Length%10];//算出是几分音符 XG=Length/10%10;//算出音符类型(0普通1连音2顿音)

FD=Length/100;LDiv=LDiv0/SLen;//算出连音音符演奏的长度(多少个10ms)

if(FD==1)LDiv=LDiv+LDiv/2;

if(XG!=1)

if(XG==0)//算出普通音符的演奏长度

if(SLen<=4)LDiv1=LDiv-LDiv4;

else

LDiv1=LDiv*SOUND_SPACE;

else

LDiv1=LDiv/2;//算出顿音的演奏长度

else LDiv1=LDiv;if(SL==0)LDiv1=0;

LDiv2=LDiv-LDiv1;//算出不发音的长度

if(SL!=0)

{ TR0=1;

for(i=LDiv1;i>0;i--)//发规定长度的音

{

while(TF1==0);TH1 = Sound_Temp_TH1;TL1 = Sound_Temp_TL1;

TF1=0;} } if(LDiv2!=0)

{

TR0=0;BeepIO=0;

for(i=LDiv2;i>0;i--)//音符间的间隔

{

while(TF1==0);TH1 = Sound_Temp_TH1;TL1 = Sound_Temp_TL1;

TF1=0;} } //////////////// if(stop)

Point=SoundLength;

/////////////// Point+=2;Tone=Sound[Point];Length=Sound[Point+1];

} /////////////// stop=0;BeepIO=1;ET0 = 0;ET1 = 0;TR0 = 0;TR1 = 0;EA = 0;//////////////

}

//歌曲《童话》

uchar code fairy_tale[]={ 0x0F,0x67, 0x19,0x03, 0x18,0x03, 0x17,0x02, 0x17,0x03,0x18,0x04, 0x17,0x0E, 0x17,0x02, 0x17,0x03, 0x18,0x03, 0x17,0x03, 0x18,0x03, 0x17,0x03, 0x16,0x04, 0x15,0x18, 0x15,0x03, 0x17,0x03, 0x19,0x03, 0x1A,0x02, 0x1A,0x03, 0x1A,0x04, 0x19,0x0E, 0x19,0x03, 0x16,0x03, 0x16,0x03, 0x18,0x04, 0x17,0x0E, 0x17,0x15, 0x15,0x03, 0x17,0x03, 0x19,0x03, 0x1A,0x02, 0x1A,0x03, 0x1A,0x04, 0x19,0x0E, 0x19,0x03, 0x16,0x03, 0x16,0x03, 0x18,0x03, 0x17,0x03, 0x18,0x03, 0x17,0x03, 0x16,0x04, 0x15,0x0E, 0x15,0x02, 0x16,0x03, 0x17,0x03, 0x10,0x02, 0x10,0x03, 0x15,0x03, 0x15,0x02, 0x11,0x02, 0x15,0x14, 0x16,0x03, 0x17,0x03, 0x10,0x02, 0x10,0x03, 0x15,0x03, 0x15,0x0D, 0x11,0x03, 0x11,0x0D, 0x15,0x03, 0x15,0x00, 0x00,0x00 };

//爱情呼叫转移

uchar code love_transfer[]={ 0x0F,0x03, 0x10,0x03, 0x15,0x03, 0x16,0x03, 0x15,0x03,0x16,0x03, 0x17,0x0D, 0x17,0x03, 0x17,0x0D, 0x17,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x16,0x03, 0x17,0x0D, 0x17,0x03, 0x17,0x0D, 0x17,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x16,0x67, 0x15,0x0E, 0x15,0x03, 0x10,0x03, 0x15,0x67, 0x16,0x0E, 0x16,0x03, 0x17,0x03, 0x17,0x66, 0x0F,0x03, 0x10,0x03, 0x15,0x03, 0x16,0x03, 0x15,0x03, 0x16,0x03, 0x15,0x0D, 0x15,0x03, 0x19,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x0D, 0x15,0x03, 0x17,0x0D, 0x17,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x16,0x67, 0x16,0x0E, 0x16,0x03, 0x16,0x03, 0x16,0x67, 0x15,0x0E, 0x15,0x03, 0x10,0x03, 0x16,0x66, 0x0F,0x03, 0x10,0x03, 0x15,0x03, 0x16,0x03, 0x15,0x03, 0x16,0x03, 0x17,0x0D, 0x17,0x03, 0x19,0x0D, 0x19,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x16,0x03, 0x17,0x0D, 0x17,0x03, 0x1A,0x0D, 0x1A,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x16,0x67, 0x15,0x0E, 0x15,0x03, 0x10,0x03, 0x15,0x67, 0x16,0x0E, 0x16,0x03, 0x17,0x03, 0x19,0x66, 0x0F,0x03, 0x10,0x03, 0x15,0x03, 0x16,0x03, 0x15,0x03, 0x16,0x03, 0x15,0x0D, 0x15,0x03, 0x1A,0x0D, 0x1A,0x03, 0x19,0x03, 0x17,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x0D, 0x15,0x03, 0x17,0x0D, 0x17,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x16,0x67, 0x16,0x0E, 0x16,0x03, 0x16,0x03, 0x16,0x67, 0x15,0x0E, 0x15,0x03, 0x10,0x03, 0x15,0x66, 0x15,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x03, 0x1A,0x03, 0x1F,0x67, 0x1A,0x0E, 0x1A,0x03, 0x19,0x03, 0x1A,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03, 0x17,0x03, 0x19,0x03, 0x1A,0x03, 0x19,0x0D, 0x19,0x03, 0x19,0x03, 0x1A,0x03, 0x19,0x03, 0x1A,0x67, 0x1A,0x0E, 0x1A,0x03, 0x1A,0x03, 0x1A,0x67, 0x19,0x0E, 0x19,0x03, 0x1A,0x03, 0x19,0x03, 0x17,0x0D, 0x17,0x16, 0x15,0x03, 0x16,0x03, 0x17,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x0D, 0x15,0x03, 0x15,0x03, 0x16,0x03, 0x17,0x03, 0x1A,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x0D, 0x15,0x03, 0x15,0x03, 0x15,0x03, 0x15,0x03, 0x1F,0x67, 0x1F,0x0E, 0x1F,0x03, 0x1F,0x03, 0x1F,0x67, 0x1A,0x0E, 0x1A,0x03, 0x1F,0x03, 0x1A,0x66, 0x19,0x0D, 0x19,0x03, 0x15,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x03, 0x1B,0x03, 0x1A,0x03, 0x19,0x03, 0x1A,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03, 0x17,0x03, 0x19,0x03, 0x1A,0x03, 0x19,0x0D, 0x19,0x03, 0x19,0x03, 0x1A,0x03, 0x19,0x03, 0x1A,0x67, 0x1A,0x0E, 0x1A,0x03, 0x1A,0x03, 0x1A,0x67, 0x19,0x0E, 0x19,0x03, 0x1A,0x03, 0x19,0x03, 0x17,0x0D, 0x17,0x16, 0x15,0x03, 0x16,0x03, 0x17,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x0D, 0x15,0x03, 0x15,0x03, 0x16,0x03, 0x17,0x03, 0x1A,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x1F,0x15, 0x1F,0x03, 0x1A,0x03, 0x1F,0x03, 0x1A,0x03, 0x19,0x0D, 0x19,0x03, 0x19,0x03, 0x1A,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03, 0x17,0x03, 0x16,0x0D, 0x16,0x03, 0x15,0x03, 0x10,0x03, 0x15,0x03, 0x15,0x03, 0x16,0x03, 0x15,0x00, 0x15,0x0B, 0x15,0x03, 0x1F,0x03, 0x1A,0x03, 0x1F,0x03, 0x20,0x03, 0x1F,0x0D, 0x1F,0x03, 0x1F,0x03, 0x20,0x03, 0x1F,0x03, 0x1A,0x03, 0x1F,0x03, 0x21,0x03, 0x20,0x0D, 0x20,0x03, 0x1F,0x03, 0x1A,0x03, 0x1F,0x03, 0x20,0x02, 0x15,0x00, 0x00,0x00 };

//挥着翅膀的女孩

unsigned char code girl_with_wing[]={ 0x17,0x02, 0x17,0x03, 0x18,0x03, 0x19,0x02, 0x15,0x03, 0x16,0x03, 0x17,0x03, 0x17,0x03, 0x17,0x03, 0x18,0x03, 0x19,0x02, 0x16,0x03, 0x17,0x03, 0x18,0x02, 0x18,0x03, 0x17,0x03, 0x15,0x02, 0x18,0x03, 0x17,0x03, 0x18,0x02, 0x10,0x03, 0x15,0x03, 0x16,0x02, 0x15,0x03, 0x16,0x03, 0x17,0x02, 0x17,0x03, 0x18,0x03, 0x19,0x02, 0x1A,0x03, 0x1B,0x03, 0x1F,0x03, 0x1F,0x03, 0x17,0x03, 0x18,0x03, 0x19,0x02, 0x16,0x03, 0x17,0x03, 0x18,0x03, 0x17,0x03, 0x18,0x03, 0x1F,0x03, 0x1F,0x02, 0x16,0x03, 0x17,0x03, 0x18,0x03, 0x17,0x03, 0x18,0x03, 0x20,0x03, 0x20,0x02, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x20,0x03, 0x21,0x03, 0x20,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x1F,0x03, 0x1B,0x03, 0x19,0x03, 0x19,0x03, 0x15,0x03, 0x1A,0x66, 0x1A,0x03, 0x19,0x03, 0x15,0x03, 0x15,0x03, 0x17,0x03, 0x16,0x66, 0x17,0x04, 0x18,0x04, 0x18,0x03, 0x19,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x20,0x03, 0x21,0x03, 0x20,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x1F,0x03, 0x1B,0x03, 0x19,0x03, 0x19,0x03, 0x15,0x03, 0x1A,0x66, 0x1A,0x03, 0x19,0x03, 0x19,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x00, 0x1A,0x03, 0x1A,0x03, 0x1A,0x03, 0x1B,0x03, 0x1B,0x03, 0x1A,0x03, 0x19,0x03, 0x19,0x02, 0x17,0x03, 0x15,0x17, 0x15,0x03, 0x16,0x03, 0x17,0x03, 0x18,0x03, 0x17,0x04, 0x18,0x0E, 0x18,0x03, 0x17,0x04, 0x18,0x0E, 0x18,0x66, 0x17,0x03, 0x18,0x03, 0x17,0x03, 0x18,0x03, 0x20,0x03, 0x20,0x02, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x20,0x03, 0x21,0x03, 0x20,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x1F,0x04, 0x1B,0x0E, 0x1B,0x03, 0x19,0x03, 0x19,0x03, 0x15,0x03, 0x1A,0x66, 0x1A,0x03, 0x19,0x03, 0x15,0x03, 0x15,0x03, 0x17,0x03, 0x16,0x66, 0x17,0x04, 0x18,0x04, 0x18,0x03, 0x19,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x20,0x03, 0x21,0x03, 0x20,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x1F,0x03, 0x1B,0x03, 0x19,0x03, 0x19,0x03, 0x15,0x03, 0x1A,0x66, 0x1A,0x03, 0x19,0x03, 0x19,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x00, 0x18,0x02, 0x18,0x03, 0x1A,0x03, 0x19,0x0D, 0x15,0x03, 0x15,0x02, 0x18,0x66, 0x16,0x02, 0x17,0x02, 0x15,0x00, 0x00,0x00};

//同一首歌

unsigned char code the_same_song[]={ 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 two_butterfly[] ={ 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 };

//珊瑚海

uchar code coral_sea[]={ 0x15,0x03, 0x15,0x03, 0x15,0x03, 0x11,0x03, 0x10,0x03, 0x11,0x03, 0x10,0x03, 0x0F,0x0D, 0x0F,0x0C, 0x0F,0x16, 0x15,0x03, 0x15,0x03, 0x15,0x03, 0x15,0x03, 0x16,0x03, 0x16,0x03, 0x0F,0x03, 0x18,0x67, 0x17,0x0E, 0x17,0x16, 0x17,0x03, 0x19,0x03, 0x19,0x67, 0x15,0x0E, 0x15,0x16, 0x15,0x03, 0x17,0x03, 0x17,0x03, 0x10,0x0D, 0x10,0x16, 0x10,0x03, 0x15,0x03, 0x16,0x16, 0x17,0x03, 0x18,0x66, 0x17,0x03, 0x16,0x15, 0x1F,0x03, 0x1F,0x03, 0x1F,0x03, 0x1F,0x03, 0x1B,0x03, 0x1A,0x03, 0x1B,0x03, 0x1A,0x03, 0x19,0x0D, 0x19,0x03, 0x0F,0x03, 0x16,0x03, 0x17,0x0D, 0x17,0x16, 0x17,0x03, 0x17,0x03, 0x17,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x16,0x03, 0x16,0x0D, 0x17,0x03, 0x17,0x16, 0x17,0x03, 0x16,0x03, 0x16,0x67, 0x17,0x0E, 0x17,0x16, 0x0F,0x03, 0x17,0x03, 0x16,0x03, 0x16,0x0E, 0x17,0x03, 0x17,0x0E, 0x17,0x16, 0x0F,0x03, 0x16,0x03, 0x17,0x66, 0x18,0x03, 0x19,0x66, 0x17,0x03, 0x18,0x15, 0x0F,0x03, 0x16,0x03, 0x16,0x03, 0x17,0x0D, 0x17,0x02, 0x17,0x03, 0x18,0x03, 0x17,0x03, 0x15,0x03, 0x1A,0x0E, 0x19,0x03, 0x19,0x0E, 0x19,0x02, 0x19,0x03, 0x1A,0x03, 0x1B,0x03, 0x20,0x03, 0x20,0x03, 0x1F,0x0D, 0x1F,0x02, 0x1F,0x03, 0x1B,0x03, 0x1A,0x03, 0x1B,0x03, 0x1A,0x0E, 0x19,0x03, 0x19,0x0E, 0x19,0x16, 0x19,0x67, 0x1B,0x03, 0x1B,0x03, 0x1F,0x0D, 0x1F,0x02, 0x1F,0x03, 0x1B,0x03, 0x1A,0x03, 0x1B,0x03, 0x1A,0x0E, 0x19,0x03, 0x19,0x0E, 0x19,0x16, 0x17,0x67, 0x1A,0x03, 0x1A,0x03, 0x15,0x0D, 0x15,0x02, 0x1A,0x03, 0x19,0x03, 0x17,0x03, 0x1A,0x03, 0x1A,0x0C, 0x1A,0x03, 0x19,0x03, 0x19,0x02, 0x0F,0x03, 0x16,0x03, 0x16,0x03, 0x17,0x0D, 0x17,0x02, 0x17,0x03, 0x18,0x03, 0x17,0x03, 0x15,0x03, 0x1A,0x04, 0x19,0x03, 0x19,0x0E, 0x19,0x02, 0x19,0x03, 0x1A,0x03, 0x1B,0x03, 0x20,0x03, 0x20,0x03, 0x1F,0x0D, 0x1F,0x02, 0x1F,0x03, 0x1B,0x03, 0x1A,0x03, 0x1B,0x03, 0x1A,0x0E, 0x19,0x03, 0x19,0x0E, 0x19,0x16, 0x19,0x67, 0x1B,0x03, 0x1B,0x03, 0x1F,0x0D, 0x1F,0x02, 0x1F,0x03, 0x1B,0x03, 0x1A,0x03, 0x1B,0x03, 0x1A,0x0E, 0x19,0x03, 0x19,0x0E, 0x19,0x16, 0x17,0x67, 0x1A,0x03, 0x1A,0x03, 0x15,0x0D, 0x15,0x02, 0x1A,0x03, 0x19,0x03, 0x18,0x03, 0x17,0x03, 0x17,0x0E, 0x16,0x03, 0x16,0x0E, 0x16,0x02, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x16,0x03, 0x16,0x04, 0x15,0x03, 0x15,0x0E, 0x15,0x0C, 0x15,0x15, 0x00,0x00 };

void scankey()

{

//加 按键处理

if(up==0)

{ delay(5);if(up==0)

{

number++;if(number>=6)number=0;} while(!up);//确认是否松开,松开就跳出while语句

LCD1602_write_string(0,0,song[number]);//显示歌曲名称

LCD1602_write_string(0,1,singer[number]);//显示歌手名

} //减 按键处理

if(down==0)

{ delay(5);if(down==0)

{

number--;if(number<=-1)number=5;} while(!down);//确认是否松开,松开就跳出while语句

LCD1602_write_string(0,0,song[number]);//显示歌曲名称

LCD1602_write_string(0,1,singer[number]);//显示歌手名

}

//播放 按键处理

if(play==0)

{ delay(5);if(play==0)

{

flag=1;} while(!play);//确认是否松开,松开就跳出while语句

}

} /*********************************************************** ******************定时器2初始化函数****************** ************************************************************/

void init_timer2()

{ T2CON=0;T2MOD=0;

RCAP2H=(65536-50000)/256;//定时初值50ms

RCAP2L=(65536-50000)%256;TH2=(65536-50000)/256;TL2=(65536-50000)%256;

EA = 1;ET2 = 1;TR2 = 1;

}

/******************主函数******************/

void main()

{

lamp_data=0xff;//关发光二极管

LCD1602_init();LCD1602_write_string(1,0,“Welcome To Use”);//显示欢迎界面

LCD1602_write_string(3,1,“Music Box!”);

delay(7000);

LCD1602_write_cmd(0x01);//清屏

LCD1602_write_string(0,0,song[number]);//显示歌曲名称 LCD1602_write_string(0,1,singer[number]);//显示歌手名

while(1){ scankey();if(flag){

init_timer2();//启动定时器2,开始跑马灯

InitialSound();switch(number)

{ case 0 :Play(fairy_tale,0,3,300);break;//播放音乐

case 1 :Play(love_transfer,0,3,300);break;case 2 :Play(girl_with_wing,0,3,300);break;case 3 :Play(the_same_song,0,3,300);break;case 4 :Play(two_butterfly,0,3,300);break;case 5 :Play(coral_sea,0,3,300);break;

default:break;

} flag=0;EA = 0;ET2 = 0;TR2 = 0;lamp_data=0xff;

t=0;count=0;sec=0;min=0;} } } /*********************************************************** ******************定时器2中断服务函数****************** ************************************************************/

void timer2()interrupt 5

{

TF2=0;//手动清中断标志

ms50++;

if(ms50>=4)//每个灯亮200ms

{ ms50=0;t++;if(t>=15)t=1;if(t<8)lamp_data=lamp[t];

else

lamp_data=lamp[14-t];

}

//计算歌曲播放时间

count++;if(count>=20)

{ count=0;sec++;if(sec>=60)

{ sec=0;min++;if(min>=10)min=0;} }

LCD1602_write_char(12,1,min+0x30);

LCD1602_write_char(13,1,':');LCD1602_write_char(14,1,sec/10+0x30);LCD1602_write_char(15,1,sec%10+0x30);

下载单片机音乐盒,1602液晶显示歌曲名、歌手名、播放时间,播放时跑马灯亮word格式文档
下载单片机音乐盒,1602液晶显示歌曲名、歌手名、播放时间,播放时跑马灯亮.doc
将本文档下载到自己电脑,方便修改和收藏,请勿使用迅雷等下载。
点此处下载文档

文档为doc格式


声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:645879355@qq.com 进行举报,并提供相关证据,工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。

相关范文推荐