#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit sound=P3^0;
sbit K1=P1^0;
sbit K2=P1^1;
sbit K3=P1^2;
sbit K4=P1^3;
char i,j;
int C;
#define L1 262
#define L2 294
#define L3 330
#define L4 349
#define L5 392
#define L6 440
#define L7 494
#define Z1 523
#define Z2 587
#define Z3 659
#define Z4 698
#define Z5 784
#define Z6 880
#define Z7 987
#define H1 1046
#define H2 1174
#define H3 1318
#define H4 1396
#define H5 1567
#define H6 1760
#define H7 1975
unsigned int code f[]={ Z6,Z7,/**/H1,Z7,H1,H3,/**/Z7,Z3,Z3, /**/Z6,Z5,Z6,H1,/**/Z5,Z3,Z3, /**/Z4,Z3,Z4,H1,
Z3,H1,H1,H1,/**/Z7,Z4,Z4,Z7,/**/Z7,Z6,Z7, /**/H1,Z7,H1,H3,/**/Z7,Z3,Z3, /**/Z6,Z5,Z6,H1,
Z5, Z3,/**/Z4,H1,Z7,H1,/**/H2,H2,H2,H1,/**/H1,Z6,Z7,Z5,/**/Z6,H1,H2, /**/H3,H2,H3,H5,
H2,Z5,Z5, /**/H1,Z7,H1,H3,/**/H3, /**/Z6,H1,Z7,H2,/**/H1,Z5,Z5, /**/H4,H3,H2,H1,
H3, /**/Z3,H3, /**/H6,H5,H5, /**/H3,H2,H1,H1,/**/H2,H1,H2,H5,/**/H3,H3,
H6,H5, /**/H3,H2,H1,H1,/**/H2,H1,H2,Z7,/**/Z6,Z6,Z7, /**/Z6,
0xff};
unsigned char code JP[ ]={ 4,4, /**/12,4,8,8, /**/20,4,4, /**/12,4,8,8, /**/20,4,4, /**/12,4,4,12,
20,4,4,4, /**/12,4,8,8, /**/20,4,4, /**/12,4,8,8, /**/20,4,4, /**/12,4,8,8,
32, 4, /**/8,4,6,8, /**/4,4,4,16, /**/8,4,6,8, /**/24,4,4, /**/12,4,8,8,
24,4,4, /**/4,4,8,8, /**/32, /**/4,8,8,6, /**/12,4,16, /**/8,8,8,8,
30, /**/20,8, /**/16,8,8, /**/4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void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void main()
{
init();
keybrard();
}
void Time0() interrupt 1
{
sound=!sound;
TH0=(8192-C)/32;
TL0=(8192-C)%32;
}
void init()
{
EA=1;
ET0=1;
TMOD=0X00;
i=0;
}
void keybrard()
{
if(K1==0)
{
delay(5);
if(K1==0)
{
while(f[i]!=0xff)
{
C=460830/f[i];
TH0=(8192-C)/32;
TL0=(8192-C)%32;
TR0=1;
for(j=0;j<JP[i];j++)
delay(50);
TR0=0;
i++;
}
sound=1;
}
}
if(K2==0)
{
delay(5);
if(K2==0)
{
while(f1[i]!=0xff)
{
C=460830/f1[i];
TH0=(8192-C)/32;
TL0=(8192-C)%32;
TR0=1;
for(j=0;j<JP1[i];j++)
delay(50);
TR0=0;
i++;
}
sound=1;
}
}
if(K3==0)
{
delay(5);
if(K3==0)
{
while(f2[i]!=0xff)
{
C=460830/f2[i];
TH0=(8192-C)/32;
TL0=(8192-C)%32;
TR0=1;
for(j=0;j<JP2[i];j++)
delay(50);
TR0=0;
i++;
}
sound=1;
}
}
if(K4==0)
{
delay(5);
if(K4==0)
{
while(f3[i]!=0xff)
{
C=460830/f3[i];
TH0=(8192-C)/32;
TL0=(8192-C)%32;
TR0=1;
for(j=0;j<JP3[i];j++)
delay(50);
TR0=0;
i++;
}
sound=1;
}
}
}
这是代码,为什么我按K1,放第一首歌,这时候按K2它不会中断第一首歌播放第二首呀??要怎么改呢
此帖出自
小平头技术问答
一周热门 更多>