微机原理实验代码

微机原理实验代码


软延时跑马灯

PORT_A EQU 280H
PORT_B EQU 281H
PORT_C EQU 282H
PORT_CTL EQU 283H
CODE SEGMENT
    ASSUME CS:CODE
START:MOV AL,82H ;送控制字
    MOV DX,PORT_CTL
    OUT DX,AL
AGAIN:ROL AL,1 ;小灯循环右移
    MOV DX,PORT_A
    OUT DX,AL
    MOV BX,0FFFFH   ;延时开始
DELAY_1:MOV CX,0FFFH
DELAY_2:LOOP DELAY_2
    DEC BX
    JNZ DELAY_1 ;延时结束?
    JMP AGAIN
CODE ENDS
END START

硬件延时跑马灯

PORT_T0 EQU 280H
PORT_T1 EQU 281H
PORT_T2 EQU 282H
PORT_CTLT EQU 283H
PORT_A EQU 2A8H
PORT_B EQU 2A9H
PORT_C EQU 2AAH
PORT_CTL EQU 2ABH
ASSUME CS:CODE
CODE SEGMENT
    ;8254初始化,采用通道0和通道1级联方式  
    MOV AL,00110101B    ;通道0控制字
    MOV DX,PORT_CTLT
     OUT DX,AL
    MOV AL,00H  ;先送低字节,再送高字节
    MOV DX,PORT_T0
    OUT DX,AL
    MOV AL,50H
    OUT DX,AL
    MOV AL,01110111B    ;通道1控制字
    MOV DX,PORT_CTLT
    OUT DX,AL
    MOV AL,00H  ;先送低字节,再送高字节
    MOV DX,PORT_T1
    OUT DX,AL
    MOV AL,08H
    OUT DX,AL
    ;8255初始化
    MOV AL,10000010B
    MOV DX,PORT_CTL
    OUT DX,AL
    MOV BL,01H
T:  MOV DX,PORT_B
; T1 检测由低电平到高电平,T2 检测由高电平到低电平
T1: IN AL,DX
    AND AL,01H
    JZ T1
T2: IN AL,DX
    AND AL,01H
    JNZ T2
    MOV AL,BL
    MOV DX,PORT_A
    OUT DX,AL
    ROL BL,1
    JMP T
CODE ENDS
END

4x4键盘

A EQU 280H
B EQU 281H
C EQU 283H
DATA SEGMENT
TABLE1 DB 77H,7BH,7DH,7EH,0B7H,0BBH,0BDH,0BEH
      DB 0D7H,0DBH,0DDH,0DEH,0E7H,0EBH,0EDH,0EEH
TABLE2 DB 40H,79H,24H,30H,19H,12H,02H,78H,00H,18H,80H,03H,43H,21H,06H,0EH
DATA ENDS
CODE SEGMENT 
ASSUME CS:CODE,DS:DATA
    MOV AX,DATA
    MOV DS,AX
    MOV DX,C    ;送8255控制字
    MOV AL,10000010B
    OUT DX,AL
    MOV DX,A    ;向所有行送 0 
    MOV AL,00H
    OUT DX,AL
MOV DX,B    ;读列,查看是否所有键都已松开
WAIT_OPEN:
IN AL,DX
AND AL,0FH
CMP AL,0FH
JNE WAIT_OPEN
WAIT_PRES:  ;各键均以松开,再查看列是否有0
    IN AL,DX
    AND AL,0FH
    CMP AL,0FH
    JE WAIT_PRES
    MOV CX,16EAH
    DELAY: LOOP DELAY   
    IN AL,DX
    AND AL,0FH
    CMP AL,0FH
    JE WAIT_PRES
    MOV AL,0FEH
    MOV CL,AL   
NEXT_ROW:   ;确定是哪一个键
    MOV DX,A
    OUT DX,AL
    MOV DX,B
    IN AL,DX
    AND AL,0FH
    CMP AL,0FH
    JNE ENCODE
    ROL CL,01
    MOV AL,CL
    JMP NEXT_ROW    
ENCODE:
    MOV BX,000FH
    IN AL,DX    
NEXT_TRY:
    CMP AL,TABLE1[BX]
    JE DONE
    DEC BX
    JNS NEXT_TRY
    MOV AH,01
    JMP EXIT
DONE:
    MOV AL,BL
    MOV AH,00

    AND AL,0FH
    XLAT
    NOT AL
    AND AL,7FH
    MOV DX,282H
    OUT DX,AL
MOV BX,0FFFFH
DELAY_ONE: MOV CX,0FFFFH
DELAY_TWO:LOOP DELAY_ONE
    DEC BX
    JNZ DELAY_TWO
JMP START
EXIT:HLT
CODE ENDS
END START

0832驱动电机工作

ASSUME CS:CODE
CODE SEGMENT
START:
    MOV DX,280H
    MOV AL,0FFH
AGAIN:
    MOV BX,80H
    INC AL  ;0832输出电压循环
    OUT DX,AL
DELAY_1:MOV CX,16EEH
DELAY2:LOOP DELAY2
    DEC BX
    JNZ DELAY_1
JMP AGAIN   
CODE ENDS
END

0809采集模拟量,8255输出二进制码

ASSUME CS:CODE
CODE SEGMENT
START:
    ;送控制字
    MOV AL,82H
    MOV DX,293H
    OUT DX,AL
    ;启动
AGAIN:MOV DX,288H
    OUT DX,AL
    ;从 B 口读数据
    MOV DX,291H
F1:IN AL,DX
    TEST AL,80H ;转换结束?
    JZ F1
    ;从 IN0 读数据
    MOV DX,288H
    IN AL,DX
    ;送 A 口
    MOV DX,290H
    OUT DX,AL
JMP AGAIN
CODE ENDS
END START

你可能感兴趣的:(base_theory)