#include
sbitspeaker=P3^7;
unsignedcharDo=108;
unsignedcharbeat_H=(65536-62500)/256,beat_L()=(65536-62500)%256;
unsignedchartone_H=(65536-1908)/256,tone_L()=(65536-1908)%256;
charTImes,counts=5;
bitbeat_flag;
//=====TImer0中止子程序======================
voidtone_TImer(void)interrupt1
{TH0=tone_H;
TL0=tone_L;
speaker=~speaker;
}
main()
{chari;
IE=0x82;
TH0=beat_H;
TL0=beat_L;
for(i=0;i{TImes=2;
beat_flag=0;
TR0=1;
if(beat_flag==0)
{speaker=~speaker;delay8us(tone[Do]);}
//===静音(1/4拍)=====================================
speaker=0;
times=2;
beat_flag=0;
TR0=1;
while(beat_flag=0);
}
}
//======================================================
voidbeat_timer(void)interrupt1
{TH0=beat_H;
TL0=beat_L;
if(–times==0)
{beat_flag=1;
TR0=0;
}
}
//============================================
voiddelay8us(unsignedcharx)
{unsignedchari,j;
for(i=0;ifor(j=0;j《1;j++);
}