单片机音乐代码

哪位高手帮我编写一个单片机音乐程序代码(刘德华——开心马骝 ),只要后面的DB表格形式,就是它的曲谱代码!发邮件至szlt520@yahoo.com.cn!!
先谢谢!请尽快!明天要用!
如果大家有其它什么音乐程序也请发给我吧!拜托!!!

第1个回答  2009-05-12
#include "reg51.h"
#define uint unsigned int
#define uchar unsigned char
uchar * TABLE ;
code uint TABLE1 [15]={64260,64400,64524,64580,
64684,64777,64820,64898,
64968,65030,65058,65110,
65157,65178,65217};
code uchar SONG [ ]={
//1. 迟来的爱
};
code uchar SONG1 [ ]={
//2.两只蝴蝶
};
code uchar SONG3 [ ]={
//4.一个师傅三个徒弟
};

uchar hjsz;
uchar ljsz;
uchar jpm;
uchar yfm;
uchar t0 =0;
uint i=0;
sbit Speaker =P1^0;
uint k;
void Delay1()
{
for ( k=0;k<20000;k++);
}
void Lignt( )
{ uchar t;
for(t=0;t<10;t++)
{
P2=0xff;
Delay1();
P2=0x00;
Delay1();
}
}
void Lignt1( )
{
P2=0xaa;
Delay1();
P2=0x55;
Delay1();
}
void Delay(uchar t0)//延时
{
while(t0--) //决定节拍
Lignt1();
}
void Delay2(uchar w0)//延时
{
while(w0--) //决定节拍
Lignt();
}
void T0Int() interrupt 1//TIMER0
{
TL0 = ljsz;
TH0 = hjsz;
Speaker=!Speaker;
}
void ExtInt0() interrupt 0//INT0
{
if(t0>10)
t0=0;
i=0; // 全局变量,指向歌谱的第1个
switch(t0++)
{
case 0 : TABLE=SONG;break; //选择第1首
case 1 : TABLE=SONG1;break;//选择第2首
case 2 : TABLE=SONG2;break;//选择第3首
case 3 : TABLE=SONG3;break;//选择第4首
case 4 : TABLE=SONG4;break;//选择第5首
case 5 : TABLE=SONG5;break;//选择第6首
case 6 : TABLE=SONG6;break;//选择第7首
case 7 : TABLE=SONG7;break;//选择第8首
case 8 : TABLE=SONG8;break;//选择第9首
case 9 : TABLE=SONG9;break;//选择第10首
}
}
void songsing()//发音程序
{
i=0;
while(TABLE[i])
{
jpm=TABLE[i]&0x0f; //节拍值
yfm=(TABLE[i]>>0x04)&0x0f;//简谱值
if(yfm) //简谱为1,取计数值
{
yfm=yfm-1;
hjsz=(uchar)(TABLE1[yfm]>>0x08);//取计数值高字节
TH0 = hjsz;
ljsz=(uchar)(TABLE1[yfm]); //取计数值低字节
TL0 = ljsz;
TR0 = 1; //启动TIMER0
}
else TR0 = 0; //简谱为0,不发音
Delay(jpm); //节拍延时
i++;
}
}
void main(void)
{
TMOD =0X01;//设TIMER0在MODE1
TCON =0X01;//外部中断INT0,下降沿触发
IE =0x83;//开中断(INT0,TIMER0)
IP =0x00;//设置中断优先级
TABLE=SONG0;
while(1)
{
Lignt( );
songsing();//调用发音程序
TR0 = 0;//停止TIMER0
Delay2(1);
TABLE=SONG0;// 更改歌曲0
songsing();
}
}本回答被提问者和网友采纳
第2个回答  2009-05-12
自己编吧,下一个曲谱就出来了
第3个回答  2009-05-12
哈哈!!也发一份给我!我明天用来泡妞!

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网