蜂鸣器仿真HAPPY birthday_软件集子_百度空间
 #include "reg51.h"

sbit P1_3=P1^3;

unsigned char code TABLE[]=
{
0x82,0x01,0x81,0x94,0x84,0xB4,0xA4,0x04,
0x82,0x01,0x81,0x94,0x84,0xC4,0xB4,0x04,
0x82,0x01,0x81,0xF4,0xD4,0xB4,0xA4,0x94,
0xE2,0x01,0xE1,0xD4,0xB4,0xC4,0xB4,0x04,
0x82,0x01,0x81,0x94,0x84,0xB4,0xA4,0x04,      
0x82,0x01,0x81,0x94,0x84,0xC4,0xB4,0x04,
0x82,0x01,0x81,0xF4,0xD4,0xB4,0xA4,0x94,
0xE2,0x01,0xE1,0xD4,0xB4,0xC4,0xB4,0x04,0
};//延时和取音阶下标

unsigned int code TABLE1[]=
{
64260,64400,64524,64580,64684,64777,64820,
64898,64968,65030,65058,65110,65157,65178,65217
};  //音阶  
unsigned char th0_temp,tl0_temp;

void SING(unsigned char hi);
void DELAY(unsigned char lo);

main()
{
unsigned char i,hi,lo,coute;

TMOD=    0X01;
ET0    =    1;
EA    =    1;
TR0    =    1;
while(1)
{
P1_3=    1;
coute=    0;//中断初始化

while(TABLE[coute]!=0)
{
i=TABLE[coute];
coute++;
lo=i&0x0f;
hi=(i&0xf0)>>4;
if(hi>0)
SING(hi);
else
TR0=0;
DELAY(lo);
}
}

}

void SING(unsigned char hi)
{
th0_temp=(TABLE1[hi-1]/256);
TH0=th0_temp;
tl0_temp=(TABLE1[hi-1]%256);
TL0=tl0_temp;
TR0=1;
}
void DELAY(unsigned char lo)
{
unsigned char temp1,temp2;
do
{
for(temp1=0;temp1<150;temp1++)
for(temp2=0;temp2<200;temp2++);
}
while(lo--);
}
void INTT0() interrupt 1//定时器0中断
{
TH0=th0_temp;
TL0=tl0_temp;
P1_3=~P1_3;
}


郑重声明:资讯 【蜂鸣器仿真HAPPY birthday_软件集子_百度空间】由 发布,版权归原作者及其所在单位,其原创性以及文中陈述文字和内容未经(企业库qiyeku.com)证实,请读者仅作参考,并请自行核实相关内容。若本文有侵犯到您的版权, 请你提供相关证明及申请并与我们联系(qiyeku # qq.com)或【在线投诉】,我们审核后将会尽快处理。
—— 相关资讯 ——