#include<reg52.h>
#define unchar unsigned char
#define unint unsigned int
unchar code SONG_TONE[]=
{212,190,169,159,142,126,119,106};
unchar code SONG_LONG[]=
{12,12,12,12,21,12,12,12};
sbit BEEP = P1^4;
sbit key1=P3^0;
sbit key2=P3^1;
sbit key3=P3^2;
sbit key4=P3^3;
sbit key5=P3^4;
sbit key6=P3^5;
sbit key7=P3^6;
sbit key8=P3^7;
void main(void)
{
unint a,b,c,n;
if(key1 == 0)
{
a = 0;
while(SONG_LONG[a]!=0||SONG_TONE[a]!=0)
{
for(b=0;b<SONG_LONG[a]*20;b++)
{
for(n=0;n<10;n++)
{
BEEP=~BEEP;
for(c=0;c<SONG_TONE[a]/4;c++);
}
break;
}
break;
}
BEEP=1;
}
if(key2==0)
{
a = 1;
while(SONG_LONG[a]!=0||SONG_TONE[a]!=0)
{
for(b=0;b<SONG_LONG[a]*20;b++)
{
for(n=0;n<10;n++)
{
BEEP=~BEEP;
for(c=0;c<SONG_TONE[a]/4;c++);
}
break;
}
break;
}
BEEP=1;
}
if(key3 == 0)
{
a = 2;
while(SONG_LONG[a]!=0||SONG_TONE[a]!=0)
{
for(b=0;b<SONG_LONG[a]*20;b++)
{
for(n=0;n<10;n++)
{
BEEP=~BEEP;
for(c=0;c<SONG_TONE[a]/4;c++);
}
break;
}
break;
}
BEEP=1;
}
if(key4 == 0)
{
a = 3;
while(SONG_LONG[a]!=0||SONG_TONE[a]!=0)
{
for(b=0;b<SONG_LONG[a]*20;b++)
{
for(n=0;n<10;n++)
{
BEEP=~BEEP;
for(c=0;c<SONG_TONE[a]/4;c++);
}
break;
}
break;
}
BEEP=1;
}
if(key5 == 0)
a = 4;
while(SONG_LONG[a]!=0||SONG_TONE[a]!=0)
{
for(b=0;b<SONG_LONG[a]*20;b++)
{
for(n=0;n<10;n++)
{
BEEP=~BEEP;
for(c=0;c<SONG_TONE[a]/4;c++);
}
break;
}
break;
}
|