个位是表示 1~7 这七个音符
十位是表示音符所在的音区:1-低音,2-中音,3-高音;
百位表示这个音符是否要升半音: 0-不升,1-升半音。
音长最多由三位数字组成:
个位表示音符的时值,其对应关系是:
|数值(n): |0 |1 |2 |3 | 4 | 5 | 6
|几分音符: |1 |2 |4 |8 |16 |32 |64 音符=2^n
十位表示音符的演奏效果(0-2): 0-普通,1-连音,2-顿音
百位是符点位: 0-无符点,1-有符点
调用演奏子程序的格式
Play(乐曲名,调号,升降八度,演奏速度);
|乐曲名: 要播放的乐曲指针,结尾以(0,0)结束;
|调号(0-11): 是指乐曲升多少个半音演奏;
|升降八度(1-3) : 1:降八度, 2:不升不降, 3:升八度;
|演奏速度(1-12000): 值越大速度越快;
********************************************************************/ // #ifndef __SOUNDPLAY_H_REVISION_FIRST__
#define __SOUNDPLAY_H_REVISION_FIRST__ //
#include
#include
#define uchar unsigned char
#define uint unsigned int
sbit BEEP=P2^1;
23struct music_type
{uchar tone;
uchar delay;
};
uchar th0,tl0;
uint code tonetable[]={
64138,64291,64426,64489,64603,64704,64795,
64837,64913,64981,65012,65070,65120,65166,
65186,65225,65259,65274,65303,65328,65351
};
struct music_type code notetab[]={
3+7,0x02,5+7,0x02,6+7,0x02,6+7,0x01,5+7,0x01,6+7,0x03,3+7,0x01,2+7,0x 04,
3+7,0x02,5+7,0x02,6+7,0x02,6+7,0x01,5+7,0x01,6+7,0x02,3+7,0x06,
3+7,0x02,5+7,0x02,6+7,0x02,6+7,0x01,5+7,0x01,6+7,0x03,3+7,0x01,2+7,0x 04,
5+7,0x02,3+7,0x02,2+7,0x01,3+7,0x01,2+7,0x01,1+7,0x01,2+7,0x02,6+0,0x 06,
6+0,0x02,2+7,0x06,5+7,0x02,3+7,0x06,2+7,0x01,1+7,0x01,6+0,0x06,
5+7,0x02,3+7,0x02,2+7,0x01,3+7,0x01,2+7,0x01,1+7,0x01,2+7,0x02,6+0,0x 06,
0,0x00,};
void T0_serv() interrupt 1
{TH0=th0;
TL0=tl0;
BEEP=~BEEP;
}
void delay_10us(uchar n)
{do
{_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}while(--n);
}
void delay_ms(uint n)
24{do delay_10us(131);
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/ruanjian/article-26593-9.html
倘若国内蒸蒸日上
只要他不像那样耍赖坐滩