#include <reg51.h>
sbit mic=P2^1; //定义喇叭接口
bit flag; //定义标志位
unsigned char i; //定义变量
unsigned char song[]=
{
1,1,2,1,4,3,1,1,2,1,5,4,
1,1,8,6,4,3,2,2,7,7,6,4,5,4,15
}; //定义生日歌歌谱
int tone[]=
{
1012,903,852,759,716,638,568,506,478,426,379
}; //定义简谱音调
unsigned char beat[]=
{
60,10,40,40,40,80,60,10,40,40,40,80,
60,10,40,40,40,40,40,60,10,40,40,40,80
}; //定义节拍
unsigned char beath=(65536-50000)/256;
unsigned char beatl=(65536-50000)%256; //定义节拍变量
unsigned char time,j,k;
int toneh,tonel;
void main()
{ //IE=0x8a;
mic=0;
i=0;
time=30;
TMOD=1; //定义计时器工作方式
EA=1; //开总中断
while(song[i]!=15)
{
toneh=(65536-tone[song[i]])/256;
tonel=(65536-tone[song[i]])%256;
TH0=toneh;
TL0=tonel;
ET0=1;
ET1=1;
TR0=1;
//for(j=150;j>0;j--)
// for(k=200;k>0;k--);
time=beat[i];
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
flag=0;
TR1=1;
while(flag==0);
i++;
}
}
void time0() interrupt 1
{
TH0=toneh;
TL0=tonel;
mic=~mic;
}
void time1() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
if(--time==0)
{
flag=1;
TR1=0;
}
}
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。