单片机蜂鸣器c语言《兰花草》音乐代码

我要C语言啊!!大哥
2024-12-02 18:04:24
推荐回答(5个)
回答1:

程序名: 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

回答2:

;程序名: 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

回答3:

给个//同一首歌
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 };

回答4:

lz最好还是学学汇编吧,很有用的

回答5:

我现在有点忙,我过两天写出来发给你!!