控制/MCU
#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++);
}
全部0条评论
快来发表一下你的评论吧 !