我改了几次都不行啊,蜂鸣器都成嗡嗡叫了,
/***********************************************音乐**************************/
code unsigned char sszymmh[]={
6,2,3, 5,2,1, 3,2,2, 5,2,2, 1,3,2,
6,2,1, 5,2,1,6,2,4, 3,2,2, 5,2,1, 6,2,1, 5,2,2, 3,2,2, 1,2,1,
6,1,1, 5,2,1, 3,2,1, 2,2,4, 2,2,3, 3,2,1, 5,2,2,5,2,1, 6,2,1,
3,2,2, 2,2,2, 1,2,4, 5,2,3, 3,2,1,2,2,1, 1,2,1, 6,1,1, 1,2,1,
5,1,6, 0,0,0
};
/*--------------发如雪片段------------------------*/
code unsigned char FA_RU_XUE[]={
3,2,1, 3,2,1, 3,2,1, 3,2,4, 2,2,1, 2,2,1, 1,2,1,
2,2,1, 3,2,1, 2,2,1, 1,2,1, 2,2,3, 3,2,2,
2,2,1, 6,1,1, 1,2,1, 2,2,4, 1,2,1, 1,2,1, 2,2,1,
3,2,1, 5,2,2, 5,2,1, 3,2,1, 5,2,5,
5,2,1, 5,2,1, 5,2,1, 6,2,4, 5,2,1,
3,2,1, 4,2,1, 5,2,2, 6,2,1, 4,2,1, 4,2,5,
2,2,1, 2,2,1, 1,2,1, 3,1,1, 2,2,1, 1,2,1, 6,1,1, 2,2,1, 1,2,1, 2,2,1,
1,2,1, 1,2,4,0,0,0
};
/*-------------------------------------------------*/
/*------------------2002年的第一场雪-----------------------*/
code unsigned char yi_xue[]={
6,2,1, 6,2,1, 6,2,1, 6,2,1, 6,2,1, 6,2,1,
7,2,2, 6,2,1, 5,2,1, 3,2,1, 3,2,2,
3,2,1, 5,2,1, 5,2,1, 5,2,1, 5,2,1, 5,2,2, 5,2,1, 5,2,1,
2,2,1, 3,2,1, 3,2,2, 0,0,0,
};
/*-------------------------------------------------*/
code unsigned char FREQH[]={0xF2,0xF3,0xF5,0xF5,0xF6,0xF7,0xF8,
0xF9,0xF9,0xFA,0xFA,0xFB,0xFB,0xFC,0xFC, //1,2,3,4,5,6,7
0xFC,0xFD,0xFD,0xFD,0xFD,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFF,
} ;
code unsigned char FREQL[]={0x42,0xC1,0x17,0xB6,0xD0,0xD1,0xB6,
0x21,0xE1,0x8C,0xD8,0x68,0xE9,0x5B,0x8F, //1,2,3,4,5,6,7
0xEE,0x44, 0x6B,0xB4,0xF4,0x2D, 0x47,0x77,0xA2,0xB6,0xDA,0xFA,0x16,
};
void delay1(unsigned char t)
{
unsigned char sum1;
unsigned long sum2;
for(sum1=0;sum1<t;sum1++)
{
for(sum2=0;sum2<5000;sum2++)//节奏快慢
{;}
}
TR0=0;
}
/*-------------计时器T0工作,使波形反一下------------*/
void t0int() interrupt 1
{
TR0=0;
BELL=!BELL;
TH0=timer0h;
TL0=timer0l;
TR0=1;
}
/*----------------------歌曲---------------------------*/
void song()
{
TH0=timer0h;
TL0=timer0l;
TR0=1;
delay1(time);
}
/*---------------------播放歌曲程序------------------------*/
void playsong(unsigned char *playp )
{
unsigned int k,i=0;
time=1;
while(time)
{
k=playp+7*playp[i+1]+6;
timer0h=FREQH[k];
timer0l=FREQL[k];
time=playp[i+2];
i=i+3;
song();
}
}
void delay2(unsigned char u)
{
unsigned int a,b;
for (a=0;a<=u;a++)
for(b=0;b<=1085;b++);
}
void
main(void)
{
TMOD=1; //置CT0定时工作方式1
EA=1;
ET0=1;//IE=0x82 //CPU开中断,CT0开中断
IT0=0;
switch(temp11) {
case 0xff :
{
LCD_dsp_string(1,1,"music:zhilaohu ");//在第一行第一列显示"LCD
playsong(zhilaohu);
BELL = 1;
break;
}
case 0xfe:
{
LCD_dsp_string(1,1,"music:yldbwdx ");//在第一行第一列显示"LCD TEST"
playsong(yldbwdx);
BELL = 1;
break;
}
case 0xfd:
{
LCD_dsp_string(1,1,"music:xc ");//在第一行第一列显示"LCD TEST"
playsong(xc);
BELL = 1;
break;
}
default:break;
}
}
}
中断中改temp11,来选择歌曲,求帮助 |