我编写了一个代码,根据XM-853套件中按下的按钮记录音符。但是在编译代码时,我的大学教授提供了一些有关子例程的问题,并且我的部分代码无法激发。如果有人可以帮助我,我衷心感谢您!
在#TECLADO
,#scan1
,#scan2
...的一行中,MIDE-51给我错误 未定义符号 ,并在带有cmp
和je
MIDE-51的行给我错误 非法语句语法 。
DO EQU 1715 ; part time to C
RE EQU 1705 ; part time to D
MI EQU 1515 ; part time to E
FA EQU 1430 ; part time to F
SO EQU 1265 ; part time to G
LA EQU 1135 ; part time to A
SI EQU 1010 ; part time to SI
org 0000h
mov TMOD, #01h ; config timer 0
clr P1.7 ; set off buzzer
lcall read_key ; subroutine read_key
read_key: push dpl
push dph
push 00h
mov dptr,#TECLADO
wait_key: mov a,#scan1
movx @dptr,a ; config scan1
lcall delay_key15k
movx a,@dptr
cjne a,#00h,keyscan1 ;tecla pressionada em scan1
mov a,#scan2
movx @dptr,a ; config scan2
lcall delay_key15k
movx a,@dptr
cjne a,#00h,keyscan2 ;tecla pressionada em scan2
mov a,#scan3
movx @dptr,a ; config scan2
lcall delay_key15k
movx a,@dptr
cjne a,#00h,keyscan3 ;tecla pressionada em scan3
mov a,#scan4
movx @dptr,a ; config scan2
lcall delay_key15k
movx a,@dptr
cjne a,#00h,gokeyscan4 ;tecla pressionada em scan4
sjmp wait_key
gokeyscan4:ljmp keyscan4
keyscan1: mov 00h,a
lcall delay_key25k
movx a,@dptr
cjne a,00h,wait_key
lcall delay_key25k
movx a,@dptr
cjne a,00h,wait_key
cjne a,#01h,key_b
mov a,#0ah
ljmp ret_key
key_b: cjne a,#02h,key_c
mov a,#0bh
ljmp ret_key
key_c: cjne a,#04h,key_d
mov a,#0ch
ljmp ret_key
key_d: cjne a,#08h,wait_key
mov a,#0dh
ljmp ret_key
keyscan2: mov 00h,a
lcall delay_key25k
movx a,@dptr
cjne a,00h,wait_key
lcall delay_key25k
movx a,@dptr
cjne a,00h,wait_key
cjne a,#01h,key_6
mov a,#03h
sjmp ret_key
key_6: cjne a,#02h,key_9
mov a,#06h
sjmp ret_key
key_9: cjne a,#04h,key_e
mov a,#09h
sjmp ret_key
key_e: cjne a,#08h,espera2
mov a,#0eh
sjmp ret_key
espera2: ljmp wait_key
keyscan3: mov 00h,a
lcall delay_key25k
movx a,@dptr
cjne a,00h,espera3
lcall delay_key25k
movx a,@dptr
cjne a,00h,espera2
cjne a,#01h,key_5
mov a,#02h
sjmp ret_key
espera3: ljmp wait_key
key_5: cjne a,#02h,key_8
mov a,#05h
sjmp ret_key
key_8: cjne a,#04h,key_0
mov a,#08h
sjmp ret_key
key_0: cjne a,#08h,espera3
mov a,#00h
sjmp ret_key
keyscan4: mov 00h,a
lcall delay_key25k
movx a,@dptr
cjne a,00h,espera4
lcall delay_key25k
movx a,@dptr
cjne a,00h,espera4
cjne a,#01h,key_4
mov a,#01h
sjmp ret_key
espera4: ljmp wait_key
key_4: cjne a,#02h,key_7
mov a,#04h
sjmp ret_key
key_7: cjne a,#04h,key_f
mov a,#07h
sjmp ret_key
key_f: cjne a,#08h,espera4
mov a,#0fh
ret_key: pop 00h
pop dph
pop dpl
lcall delay_key50k
ret
delay_key50k: push psw
clr psw.3
clr psw.4 ; config banco 0
push 00h
push 01h
mov r0,#182
loopkey0: mov r1,#90
loopkey1: nop
djnz r1, loopkey1
nop
djnz r0, loopkey0
mov r0, #38
loopkey3: nop
djnz r0,loopkey3
pop 01h
pop 00h
pop psw
ret
delay_key25k: push psw
clr psw.3
clr psw.4 ; config banco 0
push 00h
push 01h
mov r0,#91
loopkey0_25: mov r1,#90
loopkey1_25: nop
djnz r1, loopkey1_25
nop
djnz r0, loopkey0_25
mov r0, #16
loopkey3_25: nop
djnz r0,loopkey3_25
pop 01h
pop 00h
pop psw
ret
delay_key15k: push psw
clr psw.3
clr psw.4 ; config banco 0
push 00h
push 01h
mov r0,#101
loopkey0_15: mov r1,#48
loopkey1_15: nop
djnz r1, loopkey1_15
nop
djnz r0, loopkey0_15
mov r0, #11
loopkey3_15: nop
djnz r0,loopkey3_15
pop 01h
pop 00h
pop psw
nop
ret
S0: ; tec 0 press
cmp a, #00h
je PLAY_DO ; if tec 0, play C
jmp S1
S1: ; tec 1 press
cmp a, #01h
je PLAY_RE ; if tec 1, play D
jmp S2
S2:
cmp a, #02h
je PLAY_MI
jmp S3
S3:
cmp a, #03h
je PLAY_FA
jmp S4
S4:
cmp a, #04h
je PLAY_SO
jmp S5
S5:
cmp a, #05h
je PLAY_LA
jmp S6
S6:
cmp a, #06h
je PLAY_SI
ljmp S0
sjmp S0 ; caso não identifique nenhuma tecla
PLAY_DO: ; subrotina para tocar C
MOV R1, #50
D1_L1: MOV R0, #21
D1_L2: MOV TH0, #HIGH(-DO)
MOV TL0, #LOW(-DO)
SETB TR0
JNB TF0, $
CLR TR0
CLR TF0
CLR P1.7
DJNZ R0, D1_L2
DJNZ R1, D1_L1
CLR P1.7
RET
PLAY_RE: ; subrotina para tocar D
MOV R1, #50
RE_L1: MOV R0, #21
RE_L2: MOV TH0, #HIGH(-RE)
MOV TL0, #LOW(-RE)
SETB TR0
JNB TF0, $
CLR TR0
CLR TF0
CLR P1.7
DJNZ R0, RE_L2
DJNZ R1, RE_L1
CLR P1.7
RET
PLAY_MI: ; subrotina para tocar E
MOV R1, #50
MI_L1: MOV R0, #21
MI_L2: MOV TH0, #HIGH(-MI)
MOV TL0, #LOW(-MI)
SETB TR0
JNB TF0, $
CLR TR0
CLR TF0
CLR P1.7
DJNZ R0, MI_L2
DJNZ R1, MI_L1
CLR P1.7
RET
PLAY_FA: ; subrotina para tocar F
MOV R1, #50
FA_L1: MOV R0, #21
FA_L2: MOV TH0, #HIGH(-FA)
MOV TL0, #LOW(-FA)
SETB TR0
JNB TF0, $
CLR TR0
CLR TF0
CLR P1.7
DJNZ R0, FA_L2
DJNZ R1, FA_L1
CLR P1.7
RET
PLAY_SO: ; subrotina para tocar G
MOV R1, #50
SO_L1: MOV R0, #21
SO_L2: MOV TH0, #HIGH(-SO)
MOV TL0, #LOW(-SO)
SETB TR0
JNB TF0, $
CLR TR0
CLR TF0
CLR P1.7
DJNZ R0, SO_L2
DJNZ R1, SO_L1
CLR P1.7
RET
PLAY_LA: ; subrotina para tocar A
MOV R1, #50
LA_L1: MOV R0, #21
LA_L2: MOV TH0, #HIGH(-LA)
MOV TL0, #LOW(-LA)
SETB TR0
JNB TF0, $
CLR TR0
CLR TF0
CLR P1.7
DJNZ R0, LA_L2
DJNZ R1, LA_L1
CLR P1.7
RET
PLAY_SI: ; subrotina para tocar B
MOV R1, #50
SI_L1: MOV R0, #21
SI_L2: MOV TH0, #HIGH(-SI)
MOV TL0, #LOW(-SI)
SETB TR0
JNB TF0, $
CLR TR0
CLR TF0
CLR P1.7
DJNZ R0, SI_L2
DJNZ R1, SI_L1
CLR P1.7
RET
END