谁能给我几首51单片机流行歌曲 的源代码!

谁能给我几首51单片机流行歌曲 的源代码!,第1张

#include <REG52.H>

#include "SoundPlay.h"

void Delay1ms(unsigned int count)

{

unsigned int i,j

for(i=0i<简渗counti++)

for(j=0j<120j++)

}

//差者*****************************Music******************************************************

//挥着翅虚咐薯膀的女孩

unsigned char code Music_Girl[]={ 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_Same[]={ 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_Two[] ={ 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 }

//***********************************************************************************

main()

{

InitialSound()

while(1)

{

Play(Music_Girl,0,3,360)

Delay1ms(500)

Play(Music_Same,0,3,360)

Delay1ms(500)

Play(Music_Two,0,3,360)

Delay1ms(500)

}

}

程序名: MCS51U实验板配套程序-歌碰哪曲:兰花草

电路介笑空码绍:蜂鸣器亏大接P2.0;实验前要连接J12

***********************************************************************

OUT BIT P2.0

ORG 0

AJMP START

ORG 0BH

AJMP TIM0

START: MOV TMOD,#1

MOV IE,#10000010B

START0: MOV 30H,#0

NEXT:MOV A,30H

MOV DPTR,#TABLE

MOVC A,@A+DPTR

MOV R2,A

JZ END0

ANL A,#0FH

MOV R5,A

MOV A,R2

SWAP A

ANL A,#0FH

JNZ SING

CLR TR0

AJMP D1

SING:DEC A

MOV 22H,A

RL A

MOV DPTR,#TABLE1

MOVC A,@A+DPTR

MOV TH0,A

MOV 21H,A

MOV A,22H

RL A

INC A

MOVC A,@A+DPTR

MOV TL0,A

MOV 20H,A

SETB TR0

D1: CALL DELAY

INC 30H

AJMP NEXT

END0:CLR TR0

AJMP START0

TIM0:PUSH ACC

PUSH PSW

MOV TL0,20H

MOV TH0,21H

CPL OUT

POP PSW

POP ACC

RETI

DELAY: MOV R7,#2

D2: MOV R4,#125

D3: MOV R3,#248

DJNZ R3,$

DJNZ R4,D3

DJNZ R7,D2

DJNZ R5,DELAY

RET

====================================

TABLE1: DW 64021,64103,64260,64400

DW 64524,64580,64684,64777

DW 64820,64898,64968,65030

DW 64934

TABLE: 1

DB 42H,82H,82H,82H,84H,02H,72H

DB 62H,72H,62H,52H,48H

DB 0B2H,0B2H,0B2H,0B2H,0B4H,02H,0A2H

2

DB 12H,0A2H,0D2H,92H,88H

DB 82H,0B2H,0B2H,0A2H,84H,02H,72H

DB 62H,72H,62H,52H,44H,02H,12H

3

DB 12H,62H,62H,52H,44H,02H,82H

DB 72H,62H,52H,32H,48H

DB 00H

END

#include "reg51.h"

#define uintunsigned 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=0k<20000k++)

}

void Lignt( )

{ uchar t

for(t=0t<10t++)

{

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=SONGbreak//选择第1首

case 1 : TABLE=SONG1break//选择第2首

case 2 : TABLE=SONG2break//选择第3首

case 3 : TABLE=SONG3break//选择第4首

case 4 : TABLE=SONG4break//选择第5首

case 5 : TABLE=SONG5break//选择州旁第6首

case 6 : TABLE=SONG6break//选择第7首

case 7 : TABLE=SONG7break//选择第8首

case 8 : TABLE=SONG8break//选择第9首

case 9 : TABLE=SONG9break//选择第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()

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8266878.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-14
下一篇 2023-04-14

发表评论

登录后才能评论

评论列表(0条)

保存