#include"reg51.h"
#define uchar unsigned char
#define uint unsigned int
sbit buzzer=P2^7;
void delay(uint z);
void scan();
sbit S1=P3^1;
sbit S2=P3^2;
sbit S3=P3^3;
bit flag=1;
uchar buf,high,low,n;
char i;
uint sound;
uchar code num[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uint code table[]={0,63628,63835,64021,64103,64260,64399,64523,64579,64684,64777,64819,64898, 64968,65030,65058,65110,65157,65178,65217,65252,65282};
uchar code music1[]={8,4,9,4,10,4,8,4,9,4,10,4,8,4,10,4,11,4,12,8,10,4,11,4,12,8,12,3,13,1,12,3,11,1,10, 4,8,4,12,3,13,1,12,3,11,1,10,4,8,4,9,4,5,4,8,8,9,4,5,4,8,8,0xff};
uchar code music2[]={10,10,10,9,8,9,10,12,10,10,9,8,9,10,20,19,20,17,19,19,19,15,20,19,17,19,19,19, 15,16,17,16,19,17,16,15,16,19,8,20,19,19,8,20,19,17,19,20,8,8,20,19,10,10,12,9,8,8,0xff};
uchar code music3[]={12,4,15,2,13,2,12,4,12,4,10,2,12,2,13,2,15,4,12,4,12,4,13,4,12,2,10,2,9,4,9,4,10, 4,12,2,10,2,9,2,10,2,8,4,13,4,12,4,13,4,12,4,13,4,12,4,10,4,13,4,12,4,12,2,12,2,10,2,9,2,8,2,8,8,2,8,2,9,2,10,2,8,8,0xff};
uchar code music4[]={8,3,8,3,8,3,5,3,10,3,10,3,10,3,8,4,8,3,10,3,12,3,12,4,10,3,11,3,10,3,9,6,9,3,10,3, 11,3,11,4,10,3,9,3,10,3,8,4,8,3,10,3,9,3,5,4,7,3,9,3,8,6,0xff};
uchar code music5[]={0,2,8,2,10,2,11,2,12,2,12,2,11,2,12,4,13,2,14,2,15,2,10,2,10,2,11,2,12,8,13,4,12, 2,11,2,12,2,15,2,15,4,13,4,13,2,14,2,15,4,14,4,12,4,10,2,11,2,10,2,11,2,12,4,13,2,14,2,15,4,14,2,13,2,12,8,12,2,13,24,9,8,16,0xff};
uchar code *menu[]={0,music1,music2,music3,music4,music5};
uchar *p;
char j;
void int0() interrupt 0
{if(S2==0)
{delay(1);
if(S2==0)
{j++;
if(j==6)
{j=1;}
P0=num[j];
TR0=0;TR1=0;
n=0;i=3;
p=menu[j];
}
delay(1);
while(! S2);
}
}
void int1() interrupt 2
{
if(S3==0)
{ delay(1);
if(S3==0)
{ j--;
if(j==0){j=5;}
P0=num[j];TR0=0;TR1=0;n=0;i=3;p=menu[j];}
delay(1);
while(! S3);
}
}
void t1() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
n--;
scan();
}
void t0() interrupt 1
{
TH0=high;
TL0=low;
buzzer=!buzzer;
}
void init() +
-
{
TMOD=0x11;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
EA=1;ET0=1;ET1=1;EX0=1;
EX1=1;IT0=1;IT1=1;
}
void main()
{
init();
while(1)
{
for{j=1;j<6;j++}
{P0=num[i];
i=0;p=menu[j];
delay(200);
while(p[i]!=0)
{
buf=p[i];
if(buf!=0)
{
sound=table[buf];
high=sound/256;
low=sound%256;
TH0=high;
TL0=low;
if(flag)
{
TR0=1;
}
else
{
while{!flag }}
}
else{
TR0=0;
}
i++;
n=p[i]*2;
TR1=1;
while(n!=0);
i++;
}
}
}
}
void scan()
{
if(S1==0)
{
delay(10);
if(S1==0)
{
flag=!flag;
TR0=~TR0;
}
while(!S1)
{
delay(10);
}
while(!S1);
}
}
void delay(uint z)
{uint x,y;
for(x=0;x<100;x++)
for(y=0;y<z;y++);
}
|