Assembly language and interface technology_verification experiment

Table of contents

8254-Timer Application Experiment

experimental code

8254-Comparison experiment

Wiring Instructions

experimental code

8255-verification experiment

experimental code

8255 - Self-designed experiments

wiring diagram

experimental code

8259-PC internal interrupt nesting experiment

experimental code

8259-Extended multi-interrupt application experiment

experimental code

Proteus exercises

Experiment code:


8254-Timer Application Experiment

Requirements: Set the counter 0 as mode 0, set the initial value of the counter to 5, and connect the GATE to the switch.

After the program starts running, operate as follows:

Set the switch to a high level, observe the on and off of the LED light, then press a single pulse, and count how many single pulses have passed before the light on and off of the LED light changes.

experimental code

IO8254_MODE EQU 283H ;8254 控制寄存器端口地址
IO8254_COUNT0 EQU 280H ;8254 计数器 0 端口地址
IO8254_COUNT1 EQU 281H ;8254 计数器 1 端口地址
IO8254_COUNT2 EQU 282H ;8254 计数器 2 端口地址
STACK1 SEGMENT STACK
DW 256 DUP(?)
STACK1 ENDS
CODE SEGMENT
ASSUME CS:CODE
START: MOV DX, IO8254_MODE ;初始化 8254 工作方式
MOV AL,11H ;计数器 0,方式 0,十进制编码
;依据8254的方式控制字格式,计数器0对应D7D6位00,读写格式选择读写低 8位即D6D5位01,工作方式0对应D3D2D1位000,十进制数对应D0位1,即00010001,十六进制即11H
OUT DX, AL
MOV DX, IO8254_COUNT0;装入计数初值
MOV AL, 05H
OUT DX,AL
MOV AX,4C00H ;返回到 DOS
INT 21
CODE ENDS
END STAR

8254-Comparison experiment

Requirements: Refer to the program of experiment 1, use counter 0 and counter 1, set counter 0 to mode 2, and counter 1 to mode 3, modify the code and wiring diagram, observe the change of GATE signal under different working modes, the difference of experimental operation phenomenon, and compare Analyze the difference of different working methods of 8254.

Wiring Instructions

GATE is connected to the same switch (using the extension area), LED lights are connected to two lights respectively, and CLK0 and CLK1 are connected to the rising edge single pulse at the same time.

experimental code

IO8254_MODE   EQU   283H       ;8254控制寄存器端口地址
IO8254_COUNT0 EQU   280H     ;8254计数器0端口地址
IO8254_COUNT1 EQU   281H     ;8254计数器1端口地址
IO8254_COUNT2 EQU   282H     ;8254计数器2端口地址
STACK1 SEGMENT STACK
        DW 256 DUP(?)
STACK1 ENDS
CODE SEGMENT
        ASSUME CS:CODE
START: MOV DX, IO8254_MODE       ;初始化8254工作方式
       MOV AL,15H                               ;计数器0,方式2, 10进制  0001 0101
       OUT DX, AL
       MOV DX, IO8254_COUNT0        ;装入计数初值到计数器0
       MOV AL,05H
       OUT DX,AL
       MOV DX, IO8254_MODE           ;初始化8254工作方式
       MOV AL,57H                               ;计数器1,方式3, 10进制  0101 0111
       OUT DX, AL              
       MOV DX, IO8254_COUNT1        ;装入计数初值到计数器1
       MOV AL,05H                              ;计数初值为5 
       OUT DX,AL
       MOV AX,4C00H                         ;返回到DOS
       INT 21H
       
CODE ENDS
     END START

8255-verification experiment

Requirements: When designing the wiring and filling in the code, choose to use the B port for input and the A port for output to realize the basic input and output experiment.

Write a program to complete the data transmission from the toggle switch to the data light. It is required that as long as the switch is toggled, the display of the data light will change.

experimental code

IO8255_MODE EQU 28BH
IO8255_A EQU 288H
IO8255_B EQU 289H
IO8255_C EQU 28AH
CODE SEGMENT
ASSUME CS: CODE
START: MOV DX, IO8255_MODE ;8255 初始化
MOV AL, 82H;1 00 0 0 0 1 0
OUT DX, AL
INOUT: MOV DX, IO8255_B ;读入数据
IN AL,DX
MOV DX,IO8255_A ;输出数据
OUT DX,AL
MOV DL,0FFH ;判断是否有按键
MOV AH, 06H
INT 21H
JZ INOUT ;若无,则继续
MOV AH,4CH ;否则返回
INT 21H
CODE ENDS
END START

8255 - Self-designed experiments

Requirements: Use the digital tube and 8255 chip to design and realize the cyclic display of numbers from 9 to 0 on the digital tube.

wiring diagram

experimental code

MY8255_A EQU 288H        ;8255的端口A地址
MY8255_B EQU 289H        ;8255的端口B地址
MY8255_C EQU 28AH        ;8255的端口C地址
MY8255_MODE EQU 28BH   ;8255的控制寄存器地址
DATA SEGMENT                  ;定义LED段码表
    COUNT DB -1
    TAB_LED  DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H ,7FH,6FH ;0-9
DATA ENDS
CODE SEGMENT
    ASSUME DS:DATA, CS:CODE
    START: MOV AX,DATA
    MOV DS,AX
    MOV AL,82H          ;1000 0010  A端口方式0输出,B方式0输入
    MOV DX,MY8255_MODE
    OUT DX,AL
LOOP1:
    MOV AL, COUNT
    MOV BX,OFFSET TAB_LED       ;取LED段码表首地址
    XLAT                           ;查出AL对应的LED段控制码
    MOV DX,MY8255_A              ;8255的A端口是LED段码输出口
    OUT DX,AL                     ;输出段控制信号
    CALL DALLY
    ADD COUNT,1
    CMP COUNT,10
    JL LOOP1
    SUB COUNT,10
    JZ LOOP1
    DALLY PROC NEAR                    ;软件延时子程序  
    D1: MOV AX,00FFH
    D2: DEC AX  
    JNZ D2
    LOOP D1
    RET
    DALLY ENDP
CODE ENDS  
END START

8259-PC internal interrupt nesting experiment

Requirements: Use a single pulse to simulate the interrupt generation of two interrupt sources, fill in the interrupt handler, and experience the process of interrupt nesting.

After the program starts running, operate as follows:

A. Press the single pulse button connected to IRQ, and 6 Ls will be displayed on the screen. Before the 6th display on the screen ends, press the single pulse button connected to IRQ10 to observe the phenomenon;

B. Press the single pulse button connected to IRQ10, and 6 Rs will be displayed on the screen. Before the 6th display on the screen ends, press the single pulse button connected to IRQ to observe the phenomenon.

experimental code

CODE SEGMENT
ASSUME CS:CODE ,DS: DATA
START:
.86
CLI
MOV AX,CS
MOV DS,AX
MOV DX,OFFSET INT10
MOV AX,2572H
INT 21H
MOV DX,OFFSET INT3
MOV AX,250BH
INT 21H
IN AL,21H
AND AL,0F3H
OUT 21H,AL
IN AL,0A1H
AND AL,0FBH
OUT 0A1H,AL
MOV CX,6
STI
WAIT: JMP WAI
INT10: CLI
PUSHAD
PUSHFD
MOV CX,6
NEXT10_1:
MOV DX,4CH
MOV AH,02H
INT 21H
MOV DX,20H
MOV AH,02H
INT 21H
CALL DELAY1
LOOP NEXT10_1
MOV DX,0DH
MOV AH,02H
INT 21H
MOV DX,0AH
MOV AH,02H
INT 21H
MOV AL,20H
OUT 0A0H,AL
OUT 20H,AL
POPFD
POPAD
STI
IRET
INT3: CLI
PUSHAD
PUSHFD
MOV CX,10
NEXT3_1:
MOV DX,52H
MOV AH,02H
INT 21H
MOV DX,20H
MOV AH,02H
INT 21H
CALL DELAY1
LOOP NEXT3_1
MOV DX,0DH
MOV AH,02H
INT 21H
MOV DX,0AH
MOV AH,02H
INT 21H
MOV AL,20H
OUT 20H,AL
OUT 0A0H,AL
POPFD
POPAD
STI
IRET
DELAY1 PROC
PUSHAD
PUSHFD
MOV CX,0FH
DELAY_LOOP1:
MOV BX,0FFFFH
DELAY_LOOP2:
DEC BX
NOP
JNZ DELAY_LOOP2
LOOP DELAY_LOOP1
POPFD
POPAD
RET
DELAY1 ENDP
CODE ENDS
END START

8259-Extended multi-interrupt application experiment

Requirements: Use the query method, apply the 8259 interrupt source provided by the experiment box, and submit an interrupt request to the PC. The toggle switch initiates a request for an interrupt, and the corresponding interrupt request number is displayed on the screen.

experimental code

;*****************************************************************
; 8259中断查询方式应用实验
;请根据所学原理推断横线处需填写的源代码
;*****************************************************************
I8259_1 EQU 2B0H ; 8259 的 ICW1 端口地址
I8259_2 EQU 2B1H ; 8259 的 ICW2 端口地址
I8259_3 EQU 2B1H ; 8259 的 ICW3 端口地址
I8259_4 EQU 2B1H ; 8259 的 ICW4 端口地址
O8259_1 EQU 2B1H ; 8259 的 OCW1 端口地址
O8259_2 EQU 2B0H ; 8259 的 OCW2 端口地址
O8259_3 EQU 2B0H ; 8259 的 OCW3 端口地址
DATA SEGMENT
MES1 DB ‘YOU CAN PLAY A KEY ON THE KEYBOARD!',0DH, 0AH, 24H
MES2 DD MES1
MESS1 DB 'Oops, 2021 is coming to an end * 0 *!',0DH,0AH,'$' MESS2 DB 'Oops, 2021 is coming to an end * 1 *!',0DH,0AH,'$' MESS3 DB 'Oops, 2021 is coming to an end * 2 *!',0DH,0AH,'$' MESS4 DB 'Oops, 2021 is coming to an end * 3 *!',0DH,0AH,'$' MESS5 DB 'Oops, 2021 is coming to an end * 4 *!',0DH,0AH,'$' MESS6 DB 'Oops, 2021 is coming to an end * 5 *!',0DH,0AH,'$' MESS7 DB 'Oops, 2021 is coming to an end * 6 *!',0DH,0AH,'$' MESS8 DB 'Oops, 2021 is coming to an end * 7 *!',0DH,0AH,'$' DATA ENDS
STACKS SEGMENT
DB 100 DUP(?)
STACKS ENDS
STACK1 SEGMENT STACK
DW 256 DUP(?)
STACK1 ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, SS:STACKS, ES:DATA
.386
START: MOV AX,DATA
MOV DS, AX
MOV ES, AX
MOV AX, STACKS
MOV SS, AX
MOV DX, I8259_1 ;初始化 8259 的 ICW1
MOV AL, 13H ;边沿触发、单片 8259、需要 ICW4
OUT DX,AL
MOV DX,I8259_2 ;初始化 8259 的 ICW2
MOV AL,0B0H
OUT DX,AL
MOV AL,03H
OUT DX,AL
MOV DX, O8259_1 ;初始化 8259 的中断屏蔽操作命令字
MOV AL, 00H ;打开屏蔽位
OUT DX,AL
QUERY: MOV AH,1 ;判断是否有按键按下
INT 16H
JNZ QUIT ;有按键则退出
MOV DX, O8259_3 ;向 8259 发送查询命令
MOV AL, 6CH	;设置OCW3,由OCW3的格式和实验要求得,系统可以响应任何未被屏蔽信号,即ESMM=1,SMM=1,终端查询方式P=1,OCW3命令为0110 1100B,即6CH
OUT DX,AL
IN AL,DX ;读出查询字
TEST AL,80H ;判断中断是否已响应
JZ QUERY ;没有响应则继续查询
AND AL,07H
CMP AL,00H
JE IR0ISR ;若为 IR0 请求,跳到 IR0 处理程序
CMP AL,01H
JE IR1ISR ;若为 IR1 请求,跳到 IR1 处理程序
CMP AL,02H
JE IR2ISR ;若为 IR2 请求,跳到 IR2 处理程序
CMP AL,03H
JE IR3ISR ;若为 IR3 请求,跳到 IR3 处理程序
CMP AL,04H
JE IR4ISR ;若为 IR4 请求,跳到 IR4 处理程序
CMP AL,05H
JE IR5ISR ;若为 IR5 请求,跳到 IR5 处理程序
CMP AL,06H
JE IR6ISR ;若为 IR6 请求,跳到 IR6 处理程序
CMP AL,07H
JE IR7ISR ;若为 IR7 请求,跳到 IR7 处理程序
JMP QUERY
IR0ISR: MOV AX,DATA
MOV DS,AX
MOV DX,OFFSET MESS1 ;显示提示信息
MOV AH,09
INT 21H
JMP EOI
IR1ISR: MOV AX,DATA
MOV DS,AX
MOV DX,OFFSET MESS2 ;显示提示信息
MOV AH,09
INT 21H
JMP EOI
IR2ISR: MOV AX,DATA
MOV DS,AX
MOV DX,OFFSET MESS3 ;显示提示信息
MOV AH,09
INT 21H
JMP EOI
IR3ISR: MOV AX,DATA
MOV DS,AX
MOV DX,OFFSET MESS4 ;显示提示信息
MOV AH,09
INT 21H
JMP EOI
IR4ISR: MOV AX,DATA
MOV DS,AX
MOV DX,OFFSET MESS5 ;显示提示信息
MOV AH,09
INT 21H
JMP EOI
IR5ISR: MOV AX,DATA
MOV DS,AX
MOV DX,OFFSET MESS6 ;显示提示信息
MOV AH,09
INT 21H
JMP EOI
IR6ISR: MOV AX,DATA
MOV DS,AX
MOV DX,OFFSET MESS7 ;显示提示信息
MOV AH,09
INT 21H
JMP EOI
IR7ISR: MOV AX,DATA
MOV DS,AX
MOV DX,OFFSET MESS8 ;显示提示信息
MOV AH,09
INT 21H
EOI: MOV DX,O8259_2 ;向 8259 发送中断结束命令
MOV AL,20H
;设置OCW2命令字,当为中断结束命令时EOI=1,R=0,SL=0,D4D3=00,结束当前正在处理的中断,L2-L0均为0,即0010 0000B=20H
OUT DX,AL
;将设置好的命令字的值写入OCW2端口,使中断结束
JMP QUERY
QUIT: MOV AX,4C00H ;结束程序退出
INT 21H
CODE ENDS
END START

Proteus exercises

8255 simulation design: use 8255 chip to realize eight lights cycle from right to left.

Experiment code:

IO8255_MODE   EQU   8006H  ;A2 A1作为选择8255内部寄存器的地址信号
IO8255_A      EQU   8000H 
IO8255_B      EQU   8002H 
IO8255_C      EQU   8004H 
 
CODE SEGMENT       
ASSUME CS: CODE 

START:
MOV DX, IO8255_MODE         ;8255 初始化      
MOV AL, 89H              ;方式字89H,A口输出C口输入
OUT DX, AL 

INOUT:  
MOV DX,IO8255_C        ;从C口读入数据,将C口端口号送至DX
IN AL,DX                 ;读入数据,将DX端口号中的内容读入AL
TEST AL,10000000B        ;若C最高位为0,开始流水灯
JNZ INOUT


MOV BX,8
MOV AL,10000000B
PUSH AX

DISPLAYS:  
MOV DX,IO8255_C          ;从C口读入数据,将C口端口号送至DX
IN AL,DX                 ;读入数据,将DX端口号中的内容读入AL
TEST AL,10000000B        ;若C最高位为0,开始流水灯
JNZ EXIT
POP AX
MOV DX,IO8255_A          ;输出数据  
OUT DX,AL                ;DX中存放A端口地址,AL中为输出内容 
CALL DELAY
SHR AL,1   
PUSH AX
DEC BX       
JNZ DISPLAYS            ;不够八次,继续向右流水    
JMP INOUT               ;最后一个灯,重新开始


EXIT:
MOV AL,00000000B
MOV DX,IO8255_A        ;输出数据  
OUT DX,AL                ;DX中存放A端口地址,AL中为输出内容 
JMP START

DELAY PROC NEAR
    MOV CX,5000H
    D0:
    LOOP D0
    RET
DELAY ENDP

CODE ENDS  
END START

Guess you like

Origin blog.csdn.net/weixin_48144018/article/details/124905249