问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

...是汇编。在数码管上显示四首歌的序号,1~4。

发布网友 发布时间:2024-10-08 10:59

我来回答

1个回答

热心网友 时间:2024-10-10 00:12

#include <reg52.h>
#include "Music.h"
#include "SoundPlay.h"
#include "lcd.h"
#define SYSTEM_OSC 12000000 //定义晶振频率12000000HZ
#define SOUND_SPACE 4/5 //定义普通音符演奏的长度分率,//每4分音符间隔
sbit BeepIO = P2^0; //定义输出管脚
unsigned char code duan[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//duan code 0~9
unsigned int code FreTab[12] = { 262,277,294,311,330,349,369,392,415,440,466,494 }; //原始频率表
unsigned char code SignTab[7] = { 0,2,4,5,7,9,11 }; //1~7在频率表中的位置
unsigned char code LengthTab[7]= { 1,2,4,8,16,32,64 };
unsigned char Sound_Temp_TH0,Sound_Temp_TL0; //音符定时器初值暂存
unsigned char Sound_Temp_TH1,Sound_Temp_TL1; //音长定时器初值暂存
//*******************************************************************
#define MaxNo 3 //定义歌曲数目
unsigned char code *Sound;
unsigned char code * code Music[MaxNo]={Music_4,Music_8,Music_7,Music_6,Music_5,Music_9,Music_3,Music_2,Music_1};
signed char FlagNo=0;
static unsigned char KeyScan(void);
static void Beep(void);
bit RunStop = 1;//1表示运行
sbit KeyB =P3^2; // 上一首
sbit KeyF =P3^3; //下一首
sbit KeyT =P3^5; //暂停
extern void Delay1ms(unsigned int);
void InitialSound(void)
{
BeepIO = 0;
Sound_Temp_TH1 = (65535-(1/1200)*SYSTEM_OSC)/256; // 计算TL1应装入的初值 (10ms的初装值)
Sound_Temp_TL1 = (65535-(1/1200)*SYSTEM_OSC)%256; // 计算TH1应装入的初值
TH1 = Sound_Temp_TH1;
TL1 = Sound_Temp_TL1;
TMOD |= 0x11; //两个定时器都工作在方式1
ET0 = 1;
ET1 = 0;
TR0 = 0;
TR1 = 0;
EA = 1;
FlagNo = 0;
Sound = Music[FlagNo];
P1 = duan[FlagNo+1];
}
void BeepTimer0(void) interrupt 1 //音符发生中断
{
BeepIO = !BeepIO;
TH0 = Sound_Temp_TH0;
TL0 = Sound_Temp_TL0;
}
//*******************************************************************
void Play(unsigned char Signature,unsigned Octachord,unsigned int Speed)
{
unsigned int NewFreTab[12]; //新的频率表
unsigned char i,j;
unsigned int Point,LDiv,LDiv0,LDiv1,LDiv2,LDiv4,CurrentFre,Temp_T,SoundLength;
unsigned char Tone,Length,SL,SH,SM,SLen,XG,FD;
#ifdef USE_LCD
lcd_init();
lcd_write_string(0,"MusicPlayer");
#endif
Again :
Delay1ms(600);
for(i=0;i<12;i++) // 根据调号及升降八度来生成新的频率表
{
j = i + Signature;
if(j > 11)
{
j = j-12;
NewFreTab[i] = FreTab[j]*2;
}
else
NewFreTab[i] = FreTab[j];
if(Octachord == 1)
NewFreTab[i]>>=2;
else if(Octachord == 3)
NewFreTab[i]<<=2;
}
SoundLength = 0;
while(Sound[SoundLength] != 0x00) //计算歌曲长度
{
SoundLength+=2;
}
Point = 0;
Tone = Sound[Point];
Length = Sound[Point+1]; // 读出第一个音符和它时时值
LDiv0 = 12000/Speed; // 算出1分音符的长度(几个10ms)
LDiv4 = LDiv0/4; // 算出4分音符的长度
LDiv4 = LDiv4-LDiv4*SOUND_SPACE; // 普通音最长间隔标准
TR0 = 0;
TR1 = 1;
while(Point < SoundLength)
{
if(KeyScan())goto Again; /*more keyscan for speed*/
SL=Tone%10; //计算出音符
SM=Tone/10%10; //计算出高低音
SH=Tone/100; //计算出是否升半
CurrentFre = NewFreTab[SignTab[SL-1]+SH]; //查出对应音符的频率
if(KeyScan())goto Again; /*more keyscan for speed*/
if(SL!=0)
{
if (SM==1) CurrentFre >>= 2; //低音
if (SM==3) CurrentFre <<= 2; //高音
Temp_T = 65536-(50000/CurrentFre)*10/(12000000/SYSTEM_OSC);//计算计数器初值
Sound_Temp_TH0 = Temp_T/256;
Sound_Temp_TL0 = Temp_T%256;
TH0 = Sound_Temp_TH0;
TL0 = Sound_Temp_TL0 + 12; //加12是对中断延时的补偿
}
if(KeyScan())goto Again; /*more keyscan for speed*/
SLen=LengthTab[Length%10]; //算出是几分音符
XG=Length/10%10; //算出音符类型(0普通1连音2顿音)
FD=Length/100;
LDiv=LDiv0/SLen; //算出连音音符演奏的长度(多少个10ms)
if (FD==1)
LDiv=LDiv+LDiv/2;
if(XG!=1)
if(XG==0) //算出普通音符的演奏长度
if (SLen<=4)
LDiv1=LDiv-LDiv4;
else
LDiv1=LDiv*SOUND_SPACE;
else
LDiv1=LDiv/2; //算出顿音的演奏长度
else
LDiv1=LDiv;
if(SL==0) LDiv1=0;
LDiv2=LDiv-LDiv1; //算出不发音的长度
if(KeyScan())goto Again; /*more keyscan for speed*/
if (SL!=0)
{
TR0=1;
for(i=LDiv1;i>0;i--) //发规定长度的音
{
while(TF1==0);
TH1 = Sound_Temp_TH1;
TL1 = Sound_Temp_TL1;
TF1=0;
if(KeyScan())goto Again; /*more keyscan for speed*/
}
}
if(KeyScan())goto Again; /*more keyscan for speed*/
if(LDiv2!=0)
{
TR0=0; BeepIO=0;
for(i=LDiv2;i>0;i--) //音符间的间隔
{
while(TF1==0);
TH1 = Sound_Temp_TH1;
TL1 = Sound_Temp_TL1;
TF1=0;
if(KeyScan())goto Again; /*more keyscan for speed*/
}
}
Point+=2;
Tone=Sound[Point];
Length=Sound[Point+1];
if(KeyScan())goto Again; /*more keyscan for speed*/
#ifdef USE_LCD
lcd_write_char(12,FlagNo+49);
#endif
}
BeepIO = 0;
FlagNo ++;
if (FlagNo == MaxNo)FlagNo =0;
Sound = Music[FlagNo];
P1 = duan[FlagNo+1];
}
/**************************************************************
功能: 键盘扫描函数
入参: viod KeyF 下一首
KeyB 上一首
KeyT 暂停
返回: unsigned char
1 需跳转 0 不跳转
***************************************************************/
static unsigned char KeyScan(void)
{
unsigned char Cont;
if (KeyF == 0){ //前进
Delay1ms(5);
if (KeyF == 0){
while(KeyF == 0){
EA = 0;
FlagNo ++;
if (FlagNo == MaxNo)FlagNo =0;
P1 = duan[FlagNo+1];
Beep();
Delay1ms(600); //是长按
EA = 1;
}
if (FlagNo == MaxNo)FlagNo =0;
Sound = Music[FlagNo];
P1= duan[FlagNo+1]; //刷显示
while(KeyF == 0);
return 1;
}
}
if (KeyB == 0){ //后退
Delay1ms(5);
if (KeyB == 0){
while(KeyB == 0){
EA = 0;
FlagNo --;
if (FlagNo == -1)FlagNo =MaxNo-1;
P1 = duan[FlagNo+1];//刷显示
Beep();
Delay1ms(600); //是长按
EA = 1;
}
if (FlagNo == -1)FlagNo =MaxNo-1;
Sound = Music[FlagNo];
P1 = duan[FlagNo+1];
while(KeyB == 0);
return 1;
}
}
if (KeyT == 0){ //暂停
Delay1ms(20);
Cont = 0;
EA = 0;
TR0 = 0;
TR1 = 0;
if (KeyT == 0){
RunStop = ~RunStop;
while(KeyT == 0); //等待第一次释放
Beep();
if (!RunStop){ //是暂停 则关中断和定时器
EA = 0;
TR0 = 0;
TR1 = 0;
while(KeyT == 0); //检测第二次按键 并等待它释放(若有的话)
while (KeyT){ //第二次释放了 等待第三次按下
P1 = duan[Cont++%10]; //第三次未按下 则暂停数秒0~9
Delay1ms(100);
} //此处暂停 直到再次有按键低电平
EA = 1; //重开定时器和中断
TR0 = 1;
TR1 = 1;
Sound = Music[FlagNo];
P1 = duan[FlagNo+1]; //恢复原来的显示
}
}
EA = 1;
TR0 = 1;
TR1 = 1;
return 0;
}
return 0;
}
void Beep(void)
{
unsigned char i;
for(i = 0;i < 200 ;i ++){
BeepIO = ~BeepIO;
Delay1ms(1);
}
}
Playmusic:
#include <REG52.H>
#include "Music.h"
#include "SoundPlay.h"
void Delay1ms(unsigned int count)
{
unsigned int i,j;
for(i=0;i<count;i++)
for(j=0;j<120;j++);
}
main()
{
InitialSound();
while(1)
{
Play(0,3,380);
Delay1ms(500);
}
}
Music:
#include "Music.h" //*****************************Music********************************
//挥着翅膀的女孩
unsigned char code Music_1[]={
0x17,0x02, 0x17,0x03, 0x18,0x03, 0x19,0x02, 0x15,0x03,
0x16,0x03, 0x17,0x03, 0x17,0x03, 0x17,0x03, 0x18,0x03,
0x19,0x02, 0x16,0x03, 0x17,0x03, 0x18,0x02, 0x18,0x03,
0x17,0x03, 0x15,0x02, 0x18,0x03, 0x17,0x03, 0x18,0x02,
0x10,0x03, 0x15,0x03, 0x16,0x02, 0x15,0x03, 0x16,0x03,
0x17,0x02, 0x17,0x03, 0x18,0x03, 0x19,0x02, 0x1A,0x03,
0x1B,0x03, 0x1F,0x03, 0x1F,0x03, 0x17,0x03, 0x18,0x03,
0x19,0x02, 0x16,0x03, 0x17,0x03, 0x18,0x03, 0x17,0x03,
0x18,0x03, 0x1F,0x03, 0x1F,0x02, 0x16,0x03, 0x17,0x03,
0x18,0x03, 0x17,0x03, 0x18,0x03, 0x20,0x03, 0x20,0x02,
  0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x20,0x03, 0x21,0x03,
0x20,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x1F,0x03,
0x1B,0x03, 0x19,0x03, 0x19,0x03, 0x15,0x03, 0x1A,0x66,
0x1A,0x03, 0x19,0x03, 0x15,0x03, 0x15,0x03, 0x17,0x03,
0x16,0x66, 0x17,0x04, 0x18,0x04, 0x18,0x03, 0x19,0x03,
0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x20,0x03, 0x21,0x03,
0x20,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x1F,0x03,
0x1B,0x03, 0x19,0x03, 0x19,0x03, 0x15,0x03, 0x1A,0x66,
0x1A,0x03, 0x19,0x03, 0x19,0x03, 0x1F,0x03, 0x1B,0x03,
0x1F,0x00, 0x1A,0x03, 0x1A,0x03, 0x1A,0x03, 0x1B,0x03,
0x1B,0x03, 0x1A,0x03, 0x19,0x03, 0x19,0x02, 0x17,0x03,
0x15,0x17, 0x15,0x03, 0x16,0x03, 0x17,0x03, 0x18,0x03,
0x17,0x04, 0x18,0x0E, 0x18,0x03, 0x17,0x04, 0x18,0x0E,
0x18,0x66, 0x17,0x03, 0x18,0x03, 0x17,0x03, 0x18,0x03,
  0x20,0x03, 0x20,0x02, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66,
0x20,0x03, 0x21,0x03, 0x20,0x03, 0x1F,0x03, 0x1B,0x03,
0x1F,0x66, 0x1F,0x04, 0x1B,0x0E, 0x1B,0x03, 0x19,0x03,
0x19,0x03, 0x15,0x03, 0x1A,0x66, 0x1A,0x03, 0x19,0x03,
0x15,0x03, 0x15,0x03, 0x17,0x03, 0x16,0x66, 0x17,0x04,
0x18,0x04, 0x18,0x03, 0x19,0x03, 0x1F,0x03, 0x1B,0x03,
0x1F,0x66, 0x20,0x03, 0x21,0x03, 0x20,0x03, 0x1F,0x03,
0x1B,0x03, 0x1F,0x66, 0x1F,0x03, 0x1B,0x03, 0x19,0x03,
0x19,0x03, 0x15,0x03, 0x1A,0x66, 0x1A,0x03, 0x19,0x03,
  0x19,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x00, 0x18,0x02,
0x18,0x03, 0x1A,0x03, 0x19,0x0D, 0x15,0x03, 0x15,0x02,
0x18,0x66, 0x16,0x02, 0x17,0x02, 0x15,0x00, 0x00,0x00};
//同一首歌
unsigned char code Music_2[]={
0x0F,0x01, 0x15,0x02, 0x16,0x02, 0x17,0x66, 0x18,0x03,
0x17,0x02, 0x15,0x02, 0x16,0x01, 0x15,0x02, 0x10,0x02
0x15,0x00, 0x0F,0x01, 0x15,0x02, 0x16,0x02, 0x17,0x02,
0x17,0x03, 0x18,0x03, 0x19,0x02, 0x15,0x02, 0x18,0x66,
0x17,0x03, 0x19,0x02, 0x16,0x03, 0x17,0x03, 0x16,0x00,
0x17,0x01, 0x19,0x02, 0x1B,0x02, 0x1B,0x70, 0x1A,0x03,
0x1A,0x01, 0x19,0x02, 0x19,0x03, 0x1A,0x03, 0x1B,0x02,
0x1A,0x0D, 0x19,0x03, 0x17,0x00, 0x18,0x66, 0x18,0x03,
0x19,0x02, 0x1A,0x02, 0x19,0x0C, 0x18,0x0D, 0x17,0x03,
0x16,0x01, 0x11,0x02, 0x11,0x03, 0x10,0x03, 0x0F,0x0C,
0x10,0x02, 0x15,0x00, 0x1F,0x01, 0x1A,0x01, 0x18,0x66,
0x19,0x03, 0x1A,0x01, 0x1B,0x02, 0x1B,0x03, 0x1B,0x03,
0x1B,0x0C, 0x1A,0x0D, 0x19,0x03, 0x17,0x00, 0x1F,0x01,
0x1A,0x01, 0x18,0x66, 0x19,0x03, 0x1A,0x01, 0x10,0x02,
0x10,0x03, 0x10,0x03, 0x1A,0x0C, 0x18,0x0D, 0x17,0x03,
0x16,0x00, 0x0F,0x01, 0x15,0x02, 0x16,0x02, 0x17,0x70,
0x18,0x03, 0x17,0x02, 0x15,0x03, 0x15,0x03, 0x16,0x66,
0x16,0x03, 0x16,0x02, 0x16,0x03, 0x15,0x03, 0x10,0x02,
0x10,0x01, 0x11,0x01, 0x11,0x66, 0x10,0x03, 0x0F,0x0C,
0x1A,0x02, 0x19,0x02, 0x16,0x03, 0x16,0x03, 0x18,0x66,
0x18,0x03, 0x18,0x02, 0x17,0x03, 0x16,0x03, 0x19,0x00,
0x00,0x00 };
//两只蝴蝶
unsigned char code Music_3[] ={
0x17,0x03, 0x16,0x03, 0x17,0x01, 0x16,0x03, 0x17,0x03,
0x16,0x03, 0x15,0x01, 0x10,0x03, 0x15,0x03, 0x16,0x02,
0x16,0x0D, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x10,0x03,
0x10,0x0E, 0x15,0x04, 0x0F,0x01, 0x17,0x03, 0x16,0x03,
0x17,0x01, 0x16,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x01,
0x10,0x03, 0x15,0x03, 0x16,0x02, 0x16,0x0D, 0x17,0x03,
0x16,0x03, 0x15,0x03, 0x10,0x03, 0x15,0x03, 0x16,0x01,
0x17,0x03, 0x16,0x03, 0x17,0x01, 0x16,0x03, 0x17,0x03,
0x16,0x03, 0x15,0x01, 0x10,0x03, 0x15,0x03, 0x16,0x02,
0x16,0x0D, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x10,0x03,
0x10,0x0E, 0x15,0x04, 0x0F,0x01, 0x17,0x03, 0x19,0x03,
0x19,0x01, 0x19,0x03, 0x1A,0x03, 0x19,0x03, 0x17,0x01,
0x16,0x03, 0x16,0x03, 0x16,0x02, 0x16,0x0D, 0x17,0x03,
0x16,0x03, 0x15,0x03, 0x10,0x03, 0x10,0x0D, 0x15,0x00,
0x19,0x03, 0x19,0x03, 0x1A,0x03, 0x1F,0x03, 0x1B,0x03,
0x1B,0x03, 0x1A,0x03, 0x17,0x0D, 0x16,0x03, 0x16,0x03,
0x16,0x0D, 0x17,0x01, 0x17,0x03, 0x17,0x03, 0x19,0x03,
0x1A,0x02, 0x1A,0x02, 0x10,0x03, 0x17,0x0D, 0x16,0x03,
0x16,0x01, 0x17,0x03, 0x19,0x03, 0x19,0x03, 0x17,0x03,
0x19,0x02, 0x1F,0x02, 0x1B,0x03, 0x1A,0x03, 0x1A,0x0E,
0x1B,0x04, 0x17,0x02, 0x1A,0x03, 0x1A,0x03, 0x1A,0x0E,
0x1B,0x04, 0x1A,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03,
0x17,0x0D, 0x16,0x03, 0x17,0x03, 0x19,0x01, 0x19,0x03,
0x19,0x03, 0x1A,0x03, 0x1F,0x03, 0x1B,0x03, 0x1B,0x03,
0x1A,0x03, 0x17,0x0D, 0x16,0x03, 0x16,0x03, 0x16,0x03,
0x17,0x01, 0x17,0x03, 0x17,0x03, 0x19,0x03, 0x1A,0x02,
0x1A,0x02, 0x10,0x03, 0x17,0x0D, 0x16,0x03, 0x16,0x01,
0x17,0x03, 0x19,0x03, 0x19,0x03, 0x17,0x03, 0x19,0x03,
0x1F,0x02, 0x1B,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04,
0x17,0x02, 0x1A,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04,
0x17,0x16, 0x1A,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04,
0x1A,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03, 0x0F,0x02,
0x10,0x03, 0x15,0x00, 0x00,0x00 };
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
二年级作文青山210个字 天命奇御祝贺爆竹支线任务怎么过_爆竹任务玩法攻略 爆竹皇后剧情 爆竹皇后幕后花絮 如何计算止水钢板 止水钢板如何计算 贵港有没有卧铺车到南京 乾隆,雍正,康熙3个皇帝那个当的好那个差怎么评价? 康熙、雍正。乾隆。在位时都有什么事件?? ...康熙雍正乾隆各自的生平及他们在位时发生的重大历史事件。_百度知 ... 经典动作平板支撑你真的做对了吗? ...数码管显示电路。 设计要求:每隔2S显示数字加1,显示初值_百度... 减压蒸发指的是什么方法 烟台市正高级职称暖气补助是多少? 泉州中心站到泉州书城怎么坐公交车 泉州东站到东街钟楼打的士要好多钱 给答案就行,全效学习上的。 九年级上册全效学习人教版答案 泉州中心站去中山路买衣服要坐什么公交 数学应用题,急急急? 西影厂艺术街区开放时间 ...座面周长25.12m高是1.5 m这堆小麦的体积是? ...妖星入斗征三园,信传陈侯遇夏舒,是什么意思 淮北哪些艺术街区值得一逛? 霞浦有什么艺术街巷值得一逛? 黑龙江汤旺哪些艺术街区值得一逛? 数学,一个底面周长12.56米的小麦堆高1.5米每方米小麦重540千克这堆小麦... 电脑经常不定期出现花屏现象,不知道为什么?,是显卡问题还是显示器问题... 久为麟儿积善功,熊熊叫梦喜相逢,天神默佑还期许,红日临门兆司龙... 中国最低处为哪个城市 乳腺癌不可怕,预防治疗有方法 怎么判定是乳腺癌晚期啊。。。知情者请进。。。急急急。。。 ...管,c口低四位接开关,通过控制开关在屏幕上及右边数码管显示... 我想问一问大伙,手机分为智能手机,音乐手机和底端手机标准是什么? 为什么有分智能手机和音乐手机 两者有什么区分 求祥 苜蓿当年亩产干草多少吨? 音乐手机和智能手机有什么区别 手机智能机和音乐手机有什么异同 钱鼎的简介 陈树藩武昌起义 恒海法师方志记载 张宝麟的介绍 有一首歌中!有一句歌词是《想你想断肠》男人唱的歌名叫什么呢? 2024腾冲火山热海旅游区门票价格 腾冲热海腾冲交通 去腾冲旅游要多少钱 2022腾冲热海风景区门票价格 ...上趴着睡导致走路时走几步就得趴在路上息吧一会是怎么? 腾冲热海风景区腾冲热海风景区 大兴区安定到朝阳区垡头