微机原理第四次实验

2019-11-25  本文已影响0人  Bug胖
DATA    SEGMENT
    pstart  DB  'Program start.',0DH,0AH,'$'
    pend    DB  'Program will end when input', 27H,'ESC',27H,'.',0DH,0AH,'$'
    sec     DB  ?
    TABLE   DW 261
            DW 293
            DW 329
            DW 349
            DW 392
            DW 440
            DW 493
DATA    ENDS
STACK   SEGMENT     PARA    STACK   'STACK'
    STA     DB 48 DUP(?)
    TOP     EQU LENGTH STA
STACK   ENDS

CODE        SEGMENT
    ASSUME  CS:CODE,DS:DATA,SS:STACK
start:  MOV     AX,DATA
        MOV     DS,AX
        MOV     DX,OFFSET pstart
        MOV     AH,09H
        INT     21H

        MOV     DX,OFFSET pend
        MOV     AH,09H
        INT     21H
        MOV     AX,STACK
        MOV     SS,AX
        MOV     AX,TOP
        MOV     SP,AX
        MOV     AL,90H
        OUT     63H,AL
;--------------键盘控制-------------------
wait1:  MOV     AH,01H          ;输入一个字符=AL,DOS系统功能调用
        INT     21H
        CMP     AL,1BH          ;是否ESC键
        JE      keyESC
        CMP     AL,'1'          ;是a键?
        JE      key1                ;a键处理,初始化定时器8253
        CMP     AL,'2' 
        JE      key2            ;b开启扬声器
        CMP     AL,'3'
        JE      key3            ;c关启扬声器
        CMP     AL,'4'
        JE      key4            ;c关启扬声器
        CMP     AL,'5'
        JE      key5            ;c关启扬声器
        CMP     AL,'6'
        JE      key6            ;c关启扬声器
        CMP     AL,'7'
        JE      key7            ;c关启扬声器
        JMP     find

find:   MOV     AH,0BH
        INT     21H
        AND     AL,11111111B
        CALL    DELAY
        JNZ     find
        IN      AL,61H
        AND     AL,0FCH
        OUT     61H,AL
        JMP     wait1
;-----‘a’键处理,定时器8253通道2初始化,将频率转为计数初值--------
key1:   MOV     BX,TABLE    ;设定时器工作方式,方式3
        JMP     SOUNDF
;------‘b’键处理,并行接口8255,扬声器开启控制--------------
key2:   MOV     BX,TABLE+2          ;读8255PB口
        JMP     SOUNDF
;------‘c’键处理,扬声器关闭控制----------------------------
key3:   MOV     BX,TABLE+4
        JMP     SOUNDF
;-----‘a’键处理,定时器8253通道2初始化,将频率转为计数初值--------
key4:   MOV     BX,TABLE+6      ;设定时器工作方式,方式3
        JMP     SOUNDF
;------‘b’键处理,并行接口8255,扬声器开启控制--------------
key5:   MOV     BX,TABLE+8          ;读8255PB口
        JMP     SOUNDF
;------‘c’键处理,扬声器关闭控制----------------------------
key6:   MOV     BX,TABLE+10
        JMP     SOUNDF
;------‘c’键处理,扬声器关闭控制----------------------------
key7:   MOV     BX,TABLE+12
        JMP     SOUNDF
;------‘ESC’键处理,退出系统--------------------------------
keyESC: MOV     AH,4CH
        INT     21H

SOUNDF: MOV     DX,12H
        MOV     AX,348CH
        DIV     BX
        CALL    SOUND
        CALL    DELAY
        JMP     find

SOUND PROC  NEAR
        PUSH    AX
        MOV     AL,10110110B
        OUT     43H,AL
        POP     AX
        OUT     42H,AL
        MOV     AL,AH
        OUT     42H,AL
        IN      AL,61H
        OR      AL,03H
        OUT     61H,AL
        RET
SOUND   ENDP

DELAY   PROC    NEAR
        PUSH    CX
        PUSH    AX
        MOV     AX,0FFFFH
X11:    MOV     CX,1        ;延时时长控制,此数值变大声音会拉的很长
X12:    LOOP    X12
        DEC     AX
        JNZ     X11
        POP     AX
        POP     CX
        RET
DELAY  ENDP

CODE    ENDS
        END     start

e-before.png 42-1.png 42-2.png b-after.png b-before.png c-after.png c-before.png d-after.png d-before.png e-after.png
上一篇下一篇

猜你喜欢

热点阅读