#单片机#歌曲——世上只有妈妈
#define uchar unsigned char
#define uint unsigned int
sbit k3=P3^5;
sbit sound=P0^4;
bit FY=0;
uchar Song_Index=0,Tone_Index=0;
uchar k, key,flag;
uchar code DSY_CODE[]= {0xc0,0xf9,0xa4,0xb0,
{13,12,10,12,15,13,12,13,10,12,13,12,10,8,1,12,10,9,9,10,12,12,13,10,9,8,12,10,9,8,6,8,5,-1};
char code Len[]=
{3,1,2,2,2,1,1,4,2,1,1,2,2,1,1,1,1,4,3,1,2,1,1,2,2,4,3,1,1,1,1,1,6,-1};
uint code tab[]= {0,63628,63835,64021,64103,64260,64400,64524, //0,低1,低2,低3,低4,低5,低6,
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=114;y>0;y--);
}
void main()
{
TMOD=0x01;//设置定时器0工作方式1
TH0=(tab[0])/256;
TL0=(tab[0])%6;//赋初值
EA=1;//开总中断
ET0=1;//开定时器中断0
P2=0X00;
while(1)
{
Tone_Index=0;
P0=DSY_CODE;
TH0=(tab[Song[Tone_Index]])/256;
TR0 = 1;
delay(250*Len[Tone_Index]);
Tone_Index ;
TR0=0;
}
}
}
void timer0() interrupt 1
{
TH0=(tab[Song[Tone_Index]])/256;
TL0=(tab[Song[Tone_Index]])%6;
sound=!sound;
}
单片机歌 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)