微机原理——简易电子琴

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

MY8255_A EQU 0600H
MY8255_B EQU 0602H
MY8255_C EQU 0604H
MY8255_CON EQU 0606H
A8254 EQU 0640H
B8254 EQU 0642H
C8254 EQU 0644H
CON8254 EQU 0646H
SSTACK SEGMENT STACK
DW 16 DUP(?)
SSTACK ENDS

DATA SEGMENT
YINFU DW 09F7H,08E0H,07E8H,0778H,06A7H,05EDH,0598H,04FBH
DW 0470H,03F4H,03BBH,0353H,02F6H,02CBH,027DH,0238H
BUFF DW 100 DUP(?)
BUFF_TIME DW 100 DUP(?)
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV DX,CON8254 ;8254控制字
MOV AL,36H
OUT DX,AL
MOV DX,MY8255_CON ;8255控制字
MOV AL,81H
OUT DX,AL
BEGIN: CALL CCSCAN ;扫描
JNZ INK1
JMP CLEAR ;若无键盘按下,则跳清除通道0
JMP BEGIN
CLEAR: MOV DX,CON8254 ;通道0清除
MOV AL,36H
OUT DX,AL
INK1: CALL DALLY
CALL DALLY
CALL CCSCAN
JNZ INK2 ;有键按下,转到INK2
JMP BEGIN
;========================================
;确定按下键的位置
;========================================
INK2: MOV CH,0FEH
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 ;is L1?
JNZ L2

MOV AL,00H ;L1
JMP KCODE

L2: TEST AL,02H ;is L2?
JNZ L3

MOV AL,04H ;L2
JMP KCODE

L3: TEST AL,04H ;is L3?
JNZ L4

MOV AL,08H ;L3
JMP KCODE

L4: TEST AL,08H ;is L4?
JNZ NEXT

MOV AL,0CH ;L4

KCODE: ADD AL,CL
CALL PUTBUF

NEXT: INC CL
MOV AL,CH
TEST AL,08H
JZ KERR
ROL AL,1
MOV CH,AL
JMP COLUM
KERR: JMP BEGIN
;========================================
;键盘扫描子程序
;========================================
CCSCAN: MOV AL,00H
MOV DX,MY8255_A
OUT DX,AL
MOV DX,MY8255_C
IN AL,DX
NOT AL
AND AL,0FH
RET
;====== 延时子程序 ======
DALLY: PUSH CX
MOV CX,0006H
T1: MOV AX,009FH
T2: DEC AX
JNZ T2
LOOP T1
POP CX
RET
;====== 发声程序 ======
PUTBUF: ADD AL,AL
MOV SI,OFFSET YINFU
AND AX,0FFH
ADD SI,AX
MOV AX,[SI]
MOV DX,A8254 ;通道0置位
OUT DX,AL
MOV AL,AH
OUT DX,AL
GOBACK: RET

CODE ENDS
END START

相关文档
最新文档