KEYPO6:CJNE R0,#0E7H,KEYPO7 ; 输入6音,非6音跳转
SETB P2.4
MOV R3,#200
MAIN06:MOV TMOD,#01H
MOV TL0,#0E9H
MOV TH0,#0FBH
SETB TR0
WAIT6:JNB TF0,WAIT6
CLR TF0
CPL P2.4
CLR P2.3
MOV A,#10000010B
MOV P0,A
DJNZ R3,MAIN06
LJMP KEYP0
KEYPO7:CJNE R0,#0CFH,KEYPO8 ; 输入7音,非7音跳转
SETB P2.4
MOV R3,#200
MAIN07:MOV TMOD,#01H
MOV TL0,#05BH
MOV TH0,#0FCH
SETB TR0
WAIT7:JNB TF0,WAIT7
CLR TF0
CPL P2.4
CLR P2.3
MOV A,#11111000B
MOV P0,A
DJNZ R3,MAIN07
LJMP KEYP0
KEYPO8:CJNE R0,#0DBH,KEYPO9 ; 输入i音,非i音跳转
SETB P2.4
MOV R3,#200
MAIN08:MOV TMOD,#01H
MOV TL0,#08FH
MOV TH0,#0FCH
SETB TR0
WAIT8:JNB TF0,WAIT8
CLR TF0
CPL P2.4
CLR P2.3
MOV A,#10000000B
MOV P0,A
DJNZ R3,MAIN08
LJMP KEYP0
KEYPO9:CJNE R0,#0EBH,KEYPO10 ;跳转到第一首歌程序
LJMP MUSTART1
KEYPO10:CJNE R0,#0D7H,JIELI ;跳转到第二首歌程序
LJMP MUSTART2
JIELI:JMP KEYP0 ;返回主程序
MUSTART1: ;歌曲1的播放程序
MOV R0,#00H ;节拍表指针置零
MOV R1,#00H ;音符表指针置零
RTAB:MOV A,R0
MOV DPTR,#RYTH
MOVC A,@A+DPTR ;查表法将一个节拍数据取出放R2计数器中
MOV R2,A
TTAB:MOV A,R1
MOV DPTR,#TONE
MOVC A,@A+DPTR
MOV R3,A ;取出音符表高8位
INC R1 ;指针加1
MOV A,R1
MOV DPTR,#TONE
MOVC A,@A+DPTR
MOV R4,A ;取出低8位
SETB P2.4 ;输出相应音调的方波
LOOP:MOV R5,#3BH
MAIN:MOV TMOD,#01H
MOV TL0,R4
MOV TH0,R3
SETB TR0
WAIT:JNB TF0,WAIT
CLR TF0
CPL P2.4
MAYA:JB P3.2,MAYB ;判断P3.2口是否有为1
JB P3.4,MAYB ;判断P3.4口是否有为1
LJMP RA ;P3.4口为0则跳转到程序RA
MAYB:JB P3.3,JIELI ;判断P3.3口是否有为1
JB P3.5,JIELI ;判断P3.5口是否有为1
LJMP MUSTART2 ;P3.5口为0则放第二首歌
RA: DJNZ R5,MAIN ;无打断则继续放第一首歌
DJNZ R2,LOOP
INC R0 ;两个表的指针都加1
INC R1
CJNE R1,#88,RTAB ;判断是否取完
LJMP KEYP0
TONE:
DB 0FBH,68H,0FDH,6EH,0FDH,45H,0FCH,0EFH,0FCH,8FH,0FCH,8FH,0FCH,8FH,0FCH,5BH,0FCH,8FH
DB 0FCH,0EFH,0FDH,45H,0FBH,68H,0FBH,68H,0FCH,8FH,0FCH,5BH,0FBH,0E9H,0FBH,68H,0FBH,68H
DB 0FAH,0DBH,0FAH,8CH,0F9H,21H,0FAH,8CH,0FAH,0D8H,0FBH,68H,0FBH,68H,0FBH,68H,0FBH,68H
DB 0FBH,0E9H,0FBH,0E9H,0FBH,68H,0FBH,0E9H,0FCH,5BH,0FAH,8CH,0FCH,8FH,0FCH,8FH,0FCH,5BH
DB 0FCH,8FH,0FCH,0EFH,0FCH,0EFH,0FCH,0EFH,0FCH,8FH,0FDH,45H,0FDH,6EH,0FCH,0EFH
RYTH:
DB 04,04,04,04,04,04,04,04,04,04
DB 04,05,04,04,04,04,04,04,04,04
DB 04,04,04,06,04,04,04,07,04,04
DB 04,04,04,06,04,04,04,07,04,04
DB 04,04,04,04
MUSTART2:
MOV R0,#00H
MOV R1,#00H
上一页 [1] [2] [3] [4] [5] [6] 下一页