Music Box program to do before 51

Button for songs with a liquid crystal display

Before very long code, somewhat forgotten Kazakhstan

#include <REG52.H>
#include <INTRINS.H>
#include "lcd.h"
#define uchar unsigned char
#define uint unsigned int
unsigned char Count;
sbit _Speak =P1^5 ;
sbit Beep = P1^5;

typedef unsigned int u16; // define shaping the character type
typedef unsigned char u8;

sbit k1 = P3 ^ 0; ?? ?? P31 // k1
SBIT k2 = the P3 ^ 1;
sbit k3 = P3 ^ 2;
sbit k4 = P3 ^ 3;

u8 Disp[]=" the song srkl ";
u8 Disp2[]=" the song znpa ";
u8 Disp3[]=" the song bygh ";

unsigned char n = 0; // defined character
unsigned char code music_tab [] = {
0x18, 0x30, 0x1C, 0x10, // string defined song August osmanthus
0x20, 0x40, 0x1C, 0x10,
0x18, 0x10, 0x20, 0x10 ,
0x1C, 0x10, 0x18, 0x40,
0x1C, 0x20, 0x20, 0x20,
0x1C, 0x20, 0x18, 0x20,
0x20, 0x80, 0xFF, 0x20,
0x30, 0x1C, 0x10, 0x18,
0x20, 0x15, 0x20, 0x1C,
0x20 , 0x20, 0x20, 0x26,
0x40, 0x20, 0x20, 0x2B,
0x20, 0x26, 0x20, 0x20,
0x20, 0x30, 0x80, 0xFF,
0x20, 0x20, 0x1C, 0x10,
0x18, 0x10, 0x20, 0x20,
0x26, 0x20 , 0x2B, 0x20,
0x30, 0x20, 0x2B, 0x40,
0x20, 0x20, 0x1C, 0x10,
0x18, 0x10, 0x20, 0x20,
0x26, 0x20, 0x2B, 0x20,
0x30, 0x20, 0x2B , 0x40,
0x20, 0x30, 0x1C , 0x10,
0x18, 0x20, 0x15 , 0x20,
0x1C, 0x20, 0x20 , 0x20,
0x26, 0x40, 0x20 , 0x20,
0x2B, 0x20, 0x26 , 0x20,
0x20, 0x20, 0x30 , 0x80,
0x20, 0x30, 0x1C , 0x10,
0x20, 0x10, 0x1C , 0x10,
0x20, 0x20, 0x26 , 0x20,
0x2B, 0x20, 0x30 , 0x20,
0x2B, 0x40, 0x20 , 0x15,
0x1F, 0x05, 0x20 , 0x10,
0x1C, 0x10, 0x20 , 0x20,
0x26, 0x20, 0x2B , 0x20,
0x30, 0x20, 0x2B , 0x40,
0x20, 0x30, 0x1C , 0x10,
0x18, 0x20, 0x15 , 0x20,
0x1C, 0x20, 0x20 , 0x20,
0x26, 0x40, 0x20 , 0x20,
0x2B, 0x20, 0x26 , 0x20,
0x20, 0x20, 0x30 , 0x30,
0x20, 0x30, 0x1C , 0x10,
0x18, 0x40, 0x1C , 0x20,
0x20, 0x20, 0x26 , 0x40,
0x13, 0x60, 0x18 , 0x20,
0x15, 0x40, 0x13 , 0x40,
0x18, 0x80, 0x00
};


unsigned char code SONG[] ={ //生日快乐歌
0x26,0x20,0x20,0x20,0x20,0x20,0x26,0x10,0x20,0x10,0x20,0x80,0x26,0x20,0x30,0x20,
0x30,0x20,0x39,0x10,0x30,0x10,0x30,0x80,0x26,0x20,0x20,0x20,0x20,0x20,0x1c,0x20,
0x20,0x80,0x2b,0x20,0x26,0x20,0x20,0x20,0x2b,0x10,0x26,0x10,0x2b,0x80,0x26,0x20,
0x30,0x20,0x30,0x20,0x39,0x10,0x26,0x10,0x26,0x60,0x40,0x10,0x39,0x10,0x26,0x20,
0x30,0x20,0x30,0x20,0x39,0x10,0x26,0x10,0x26,0x80,0x26,0x20,0x2b,0x10,0x2b,0x10,
0x2b,0x20,0x30,0x10,0x39,0x10,0x26,0x10,0x2b,0x10,0x2b,0x20,0x2b,0x40,0x40,0x20,
0x20,0x10,0x20,0x10,0x2b,0x10,0x26,0x30,0x30,0x80,0x18,0x20,0x18,0x20,0x26,0x20,
0x20,0x20,0x20,0x40,0x26,0x20,0x2b,0x20,0x30,0x20,0x30,0x20,0x1c,0x20,0x20,0x20,
0x20,0x80,0x1c,0x20,0x1c,0x20,0x1c,0x20,0x30,0x20,0x30,0x60,0x39,0x10,0x30,0x10,
0x20,0x20,0x2b,0x10,0x26,0x10,0x2b,0x10,0x26,0x10,0x26,0x10,0x2b,0x10,0x2b,0x80,
0x18,0x20,0x18,0x20,0x26,0x20,0x20,0x20,0x20,0x60,0x26,0x10,0x2b,0x20,0x30,0x20,
0x30,0x20,0x1c,0x20,0x20,0x20,0x20,0x80,0x26,0x20,0x30,0x10,0x30,0x10,0x30,0x20,
0x39,0x20,0x26,0x10,0x2b,0x10,0x2b,0x20,0x2b,0x40,0x40,0x10,0x40,0x10,0x20,0x10,
0x20,0x10,0x2b,0x10,0x26,0x30,0x30,0x80,0x00};

uchar code SONG_TONE[]={212,212,190,212,159,169,212,212,190,212,142,159,
212,212,106,126,159,169,190,119,119,126,159,142,159,0};

uchar code SONG_LONG[]={9,3,12,12,12,24,9,3,12,12,12,24,
9,3,12,12,12,12,12,9,3,12,12,12,24,0};


void Time0_Init()
{
TMOD = 0x01;
IE = 0x82;
TH0 = 0xD8;
TL0 = 0xEF; //12MZ,10ms
}


Time0_Int void () interrupt. 1
{
TH0 is = 0xD8;
TL0 = 0xEF;
the Count ++; // timer interrupt. 1
N--;
}

void Delay100ms() //@12.000MHz
{
unsigned char i, j, k;

_nop_();
_nop_();
i = 5;
j = 144;
k = 71;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}

 


void Delay_xMs(unsigned int x)
{
unsigned int i,j;
for( i =0;i < x;i++ )
{
for( j =0;j<3;j++ );
}
}

void delay1(u16 i)
{
while(i--);
}

 

void delayms (unsigned char a) // delay function
{
the while (- A); //
}

void delay (unsigned char m) //
{
unsigned i=3*m;
while(--i);
}

void DelayMmS(uint x)
{
uchar t;
while(x--) for(t=0;t<120;t++);
}

 


void PlayMusic()
{
uint i=0,j,k;
while(SONG_LONG[i]!=0||SONG_TONE[i]!=0)
{ //??????,SONG_LONG ?????
for(j=0;j<SONG_LONG[i]*20;j++)
{
Beep=~Beep;
//SONG_TONE ?????????????
for(k=0;k<SONG_TONE[i]/3;k++);
}
DelayMmS(10);
i++;
}
}

void Play_Song(unsigned char i)
{
unsigned char Temp1,Temp2;
unsigned int Addr;
Count = 0; //??????0
Addr = i * 217;
while(1)
{
Temp1 = SONG[Addr++];
if ( Temp1 == 0xFF ) //???
{
TR0 = 0;
Delay_xMs(100);
}
else if ( Temp1 == 0x00 ) //?????
{
return;
}
else
{
Temp2 = SONG[Addr++];
TR0 = 1;
while(1)
{
_Speak = ~_Speak;
Delay_xMs(Temp1);
if ( Temp2 == Count )
{
Count = 0;
break;
}
}
}
}
}

 

 

 

 

 

void wquanyingyue()
{
unsigned char p,m; //m???????
unsigned char i=0;
TMOD&=0x0f;
TMOD|=0x01;
TH0=0xd8;TL0=0xef;
IE=0x82;
play:
while(1)
{
a: p=music_tab[i];
if(p==0x00) { i=0, delayms(1000); goto play;} //???????,??1?,????????
else if(p==0xff) { i=i+1;delayms(100),TR0=0; goto a;} //??????,??100ms,???????
else {m=music_tab[i++], n=music_tab[i++];} //????? ? ????
TR0=1; //????1
while(n!=0) Beep=~Beep,delay(m); //??????, ??P1?????(?????!)
TR0=0; //????1
}
}

void ShowTheWorld1()
{
u8 i;
u8 k;
LcdInit();
while(k<=5)
{
for(i=0;i<16;i++)
{
LcdWriteData(Disp[i]); //液晶屏显示歌曲
}
Delay100ms();
k++;
}
}
void ShowTheWorld2()
{
u8 i;
u8 k;
LcdInit();
while(k<=5)
{
for(i=0;i<16;i++)
{
LcdWriteData(Disp2[i]);
}
Delay100ms();
k++;
}
}
void ShowTheWorld3()
{
u8 i;
u8 k;
k=0;
LcdInit();
while(k<=5)
{
for(i=0;i<16;i++)
{
LcdWriteData(Disp3[i]);
}
Delay100ms();
k++;
}
}

keypros void ()
{

LcdInit ();
IF (K1 == 0) // ???? ???? Kl
{
DELAY1 (1000); delay eliminating jitter //
IF (K1 == 0)
{
Time0_Init () ;
the while (. 1)
{
ShowTheWorld2 (); // command and display song play songs
Play_Song (0);

}

}
The while (K1!); // ????????
}

if (K2 == 0) // ???? ???? Kl
{
DELAY1 (1000); delay eliminating jitter //
if ( == 0 K2) ?????????? //
{
Beep = 0;
the while (. 1)
{
ShowTheWorld1 ();
PlayMusic (); // // ?????? player then displays a song life songs
DelayMmS (500); // ??????????


}
the while (K2!); // ????????
}
}

IF (K3 == 0) // ???? ???? Kl
{
DELAY1 (1000); delay eliminating jitter //
IF (K3 == 0) // ??????????
{
ShowTheWorld3 (); // command and display song play songs
wquanyingyue ();



}
the while (K3!);
}
IF (K4 == 0) // ???? ???? Kl
{
DELAY1 (1000); // 10ms ???? ????
if(k4==0) //??????????
{

}
while(!k3);
}
}


main void ()
{

the while (. 1)
{
keypros (); // repeatedly executed key scanning function
}
}

Guess you like

Origin www.cnblogs.com/blg2/p/11953915.html