实验内容
用实验箱上的16个按键模拟钢琴的16个音符。
代码
IOY0 EQU 0600H
MY8254_COUNT0 EQU 0600H
MY8254_COUNT1 EQU 0602H
MY8254_COUNT2 EQU 0640H
MY8254_MODE EQU 0606H
MY8255_A EQU 0640H
MY8255_B EQU 0642H
MY8255_C EQU 0644H
MY8255_MODE EQU 0646H
STACK1 SEGMENT STACK
DW 256 DUP(?)
STACK1 ENDS
DATA SEGMENT
FREQ_LIST DW 262H, 294H, 330H, 349H, 392H, 440H, 496H
DW 524H, 588H, 660H, 698H, 784H, 880H, 988H
DTABLE DB 3FH, 06H, 5BH, 4FH, 66H, 6DH, 7DH, 07H
DB 7FH, 6FH, 77H, 7CH, 39H, 5EH, 79H, 71H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV DX,MY8254_MODE
MOV AL,81H
OUT DX,AL
MOV DX,MY8254_MODE
MOV AL,36H
OUT DX,AL
BEGIN1:
CALL CCSCAN
JNZ INK1
JMP BEGIN1
INK1:
CALL CCSCAN
JNZ INK2
JMP BEGIN1
INK2:
MOV CH,OFEH
MOV CL,00H
COLUM:
MOV AL,CH
MOV DX,MY8255_A
OUT DX,AL
MOV DX,MY8255_C
IN AL,DX
L1:
TEST AL,01H
JNZ L2
MOV AL,00H
JMP KCODE
L2:
TEST AL,02H
JNZ L3
MOV AL,04H
JMP KCODE
L3:
TEST AL,04H
JNZ L4
MOV AL,08H
JMP KCODE
L4:
TEST AL,08H
JNZ NEXT
MOV AL,0CH
KCODE:
ADD AL,CL
CALL PLAY
PUSH AX
KON:
CALL DALLY
CALL CCSCAN
JNZ KON
POP AX
JMP BEGIN1
NEXT:
INC CL
MOV AL,CH
TEST AL,08H
JZ KERR
ROL AL,1
MOV CH,AL
JMP COLUM
KERR:
JMP BEGIN1
CCSCAN:
MOV AL,00H
MOV DX,MY8255_A
OUT DX,AL
MOV DX,MY8255_C
IN AL,DX
NOT AL
AND AL,0FH
RET
PLAY PROC
MOV AH,0
MOV SI,AX
SHL SI,1
MOV DX,0FH
MOV AX,4240H
DIV WORD PTR[SI]
MOV DX,MY8254_COUNT0
OUT DX,AL
MOV AL,AH
OUT DX,AL
RET
PLAY ENDP
DALLY PROC
D0: MOV CX,0010H
D1: MOV AX,02H
D2: DEC AX
JNZ D2
LOOP D1
DEC DL
JNZ D0
RET
DALLY ENDP
CODE ENDS
END START