Skip to content

[微机实验/TD-PITE] 数码管显示实验

Published: at 15:22

ToC

实验内容

使七段共阴极数码管显示如下内容:

  1. 从右到左逐位显示移动的数字 0~9。即一开始是 0 从右到左移动,然后是 1,然后是 2,以此类推。最后在 9 移动完后返回 0,继续循环。
  2. 使六位数码管从左到右显示稳定的数字 123456

实验接线

照着书上连就可以了。在这个实验中,PC 甚至可以不连(笑)

代码

数字滚动

A8255 EQU 0600H
B8255 EQU 0602H
C8255 EQU 0604H
CON8255 EQU 0606H
SSEG SEGMENT STACK
DW 0, 0, 0, 0
SSEG ENDS
DATA SEGMENT
TBL:
DB 3FH ;; 0
DB 06H ;; 1
DB 5BH ;; 2
DB 4FH ;; 3
DB 66H ;; 4
DB 6DH ;; 5
DB 7DH ;; 6
DB 07H ;; 7
DB 7FH ;; 8
DB 6FH ;; 9
SEQ:
DB 00011111B ;; POS 0
DB 00101111B ;; POS 1
DB 00110111B ;; POS 2
DB 00111011B ;; POS 3
DB 00111101B ;; POS 4
DB 00111110B ;; POS 5
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, SS:SSEG
START PROC
MOV AX, DATA
MOV DS, AX
MOV AL, 10001001B ;; A B OUT, C IN
MOV DX, CON8255
OUT DX, AL
MOV AX, 0000H
LO:
CALL PUT
CALL DELAY
INC AL
CMP AL, 6
JNE LO
MOV AL, 0
INC AH
CMP AH, 10
JNE LO
MOV AH, 0
JMP LO
MOV AX, 4C00H
INT 21H
START ENDP
;; NUM: AH
;; POS: AL
PUT PROC
PUSH AX
;; SELECT POS
LEA BX, SEQ
PUSH AX
MOV AH, 0
MOV SI, AX
;; OUTPUT POS
MOV DX, A8255
MOV AL, [BX+SI]
OUT DX, AL
POP AX
;; SELECT NUM
LEA BX, TBL
MOV AL, AH
MOV AH, 0
MOV SI, AX
;; OUTPUT DATA
MOV DX, B8255
MOV AL, [BX+SI]
OUT DX, AL
POP AX
RET
PUT ENDP
DELAY PROC
MOV CX, 0FFFFH
LOOP $
MOV CX, 0FFFFH
LOOP $
RET
DELAY ENDP
CODE ENDS
END START

持久显示

A8255 EQU 0600H
B8255 EQU 0602H
C8255 EQU 0604H
CON8255 EQU 0606H
SSEG SEGMENT STACK
DW 0, 0, 0, 0
SSEG ENDS
DATA SEGMENT
TBL:
DB 3FH ;; 0
DB 06H ;; 1
DB 5BH ;; 2
DB 4FH ;; 3
DB 66H ;; 4
DB 6DH ;; 5
DB 7DH ;; 6
DB 07H ;; 7
DB 7FH ;; 8
DB 6FH ;; 9
SEQ:
DB 00011111B ;; POS 0
DB 00101111B ;; POS 1
DB 00110111B ;; POS 2
DB 00111011B ;; POS 3
DB 00111101B ;; POS 4
DB 00111110B ;; POS 5
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, SS:SSEG
START PROC
MOV AX, DATA
MOV DS, AX
MOV AL, 10001001B ;; A B OUT, C IN
MOV DX, CON8255
OUT DX, AL
MOV AX, 0000H
LO:
MOV AX, 0105H
CALL PUT
CALL DELAY
MOV AX, 0204H
CALL PUT
CALL DELAY
MOV AX, 0303H
CALL PUT
CALL DELAY
MOV AX, 0402H
CALL PUT
CALL DELAY
MOV AX, 0501H
CALL PUT
CALL DELAY
MOV AX, 0600H
CALL PUT
CALL DELAY
JMP LO
MOV AX, 4C00H
INT 21H
START ENDP
;; NUM: AH
;; POS: AL
PUT PROC
PUSH AX
;; SELECT POS
LEA BX, SEQ
PUSH AX
MOV AH, 0
MOV SI, AX
;; OUTPUT POS
MOV DX, A8255
MOV AL, [BX+SI]
OUT DX, AL
POP AX
;; SELECT NUM
LEA BX, TBL
MOV AL, AH
MOV AH, 0
MOV SI, AX
;; OUTPUT DATA
MOV DX, B8255
MOV AL, [BX+SI]
OUT DX, AL
POP AX
RET
PUT ENDP
DELAY PROC
MOV CX, 0FFH
LOOP $
RET
DELAY ENDP
CODE ENDS
END START

实验效果

这里就只展示数字滚动的效果好了(

选做实验

选做实验 1-2

说明

编写显示子程序,实现一个或多个数码管的稳定显示。使用入口参数定义拟显示的位置和显示的内容。

利用(1)实现的子程序,重新完成基本实验 1)和 2)。

实现

这部分其实在上面的实验里已经实现了,就是这个 PUT 函数。它可以将 AH 的数字显示在 AL 的位置上。

;; NUM: AH
;; POS: AL
PUT PROC
PUSH AX
;; SELECT POS
LEA BX, SEQ
PUSH AX
MOV AH, 0
MOV SI, AX
;; OUTPUT POS
MOV DX, A8255
MOV AL, [BX+SI]
OUT DX, AL
POP AX
;; SELECT NUM
LEA BX, TBL
MOV AL, AH
MOV AH, 0
MOV SI, AX
;; OUTPUT DATA
MOV DX, B8255
MOV AL, [BX+SI]
OUT DX, AL
POP AX
RET
PUT ENDP

选做实验 3

说明

在数码管上显示学号后 6 位,并使用 6 个开关控制对应数码管的亮灭。

实现

通过开关控制就可以了,只需要多连一个 8255 即可。

A8255 EQU 0600H
B8255 EQU 0602H
C8255 EQU 0604H
CON8255 EQU 0606H
SSEG SEGMENT STACK
DW 0, 0, 0, 0
SSEG ENDS
DATA SEGMENT
TBL:
DB 3FH ;; 0
DB 06H ;; 1
DB 5BH ;; 2
DB 4FH ;; 3
DB 66H ;; 4
DB 6DH ;; 5
DB 7DH ;; 6
DB 07H ;; 7
DB 7FH ;; 8
DB 6FH ;; 9
SEQ:
DB 00011111B ;; POS 0
DB 00101111B ;; POS 1
DB 00110111B ;; POS 2
DB 00111011B ;; POS 3
DB 00111101B ;; POS 4
DB 00111110B ;; POS 5
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, SS:SSEG
START PROC
MOV AX, DATA
MOV DS, AX
MOV AL, 10001001B ;; A B OUT, C IN
MOV DX, CON8255
OUT DX, AL
MOV AX, 0000H
;; DISPLAY 181117
LO:
MOV AX, 0105H
CALL PUT_COND
MOV AX, 0804H
CALL PUT_COND
MOV AX, 0103H
CALL PUT_COND
MOV AX, 0102H
CALL PUT_COND
MOV AX, 0101H
CALL PUT_COND
MOV AX, 0700H
CALL PUT_COND
JMP LO
MOV AX, 4C00H
INT 21H
START ENDP
;; NUM: AH
;; POS: AL
PUT_COND PROC
PUSH AX
MOV BX, 1
MOV CL, AL
SHL BL, CL
MOV DX, C8255
IN AL, DX
TEST BL, AL
JZ PUT_EXIT
POP AX
PUSH AX
CALL PUT
CALL DELAY
PUT_EXIT:
POP AX
RET
PUT_COND ENDP
;; NUM: AH
;; POS: AL
PUT PROC
PUSH AX
;; SELECT POS
LEA BX, SEQ
PUSH AX
MOV AH, 0
MOV SI, AX
;; OUTPUT POS
MOV DX, A8255
MOV AL, [BX+SI]
OUT DX, AL
POP AX
;; SELECT NUM
LEA BX, TBL
MOV AL, AH
MOV AH, 0
MOV SI, AX
;; OUTPUT DATA
MOV DX, B8255
MOV AL, [BX+SI]
OUT DX, AL
POP AX
RET
PUT ENDP
DELAY PROC
MOV CX, 0FFH
LOOP $
RET
DELAY ENDP
CODE ENDS
END START

效果

注意左下角的开关(

选做实验 4

说明

在左侧的三个数码管上显示 123,每隔 1 秒钟向右移动一位(循环)。

实现

这里用到的是 8254 延时,不过实验的时候 8254 好像出了什么状况不大行。因此以下代码仅供参考。

A8255 EQU 0600H
B8255 EQU 0602H
C8255 EQU 0604H
CON8255 EQU 0606H
C008254 EQU 0640H
C018254 EQU 0642H
C028254 EQU 0644H
CON8254 EQU 0646H
SSEG SEGMENT STACK
DW 0, 0, 0, 0
SSEG ENDS
DATA SEGMENT
TBL:
DB 3FH ;; 0
DB 06H ;; 1
DB 5BH ;; 2
DB 4FH ;; 3
DB 66H ;; 4
DB 6DH ;; 5
DB 7DH ;; 6
DB 07H ;; 7
DB 7FH ;; 8
DB 6FH ;; 9
SEQ:
DB 00011111B ;; POS 0
DB 00101111B ;; POS 1
DB 00110111B ;; POS 2
DB 00111011B ;; POS 3
DB 00111101B ;; POS 4
DB 00111110B ;; POS 5
POS DB 05
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, SS:SSEG
START PROC
;; INIT 8255
MOV AL, 10001001B
MOV DX, CON8255
OUT DX, AL
;; MIR6
MOV AX, OFFSET MIR6
MOV SI, 38H
MOV [SI], AX
MOV AX, CS
MOV SI, 3AH
MOV [SI], AX
MOV AX, DATA
MOV DS, AX
;; INIT 8259
CLI
MOV AL, 11H
OUT 20H, AL
MOV AL, 08H
OUT 21H, AL
MOV AL, 04H
OUT 21H, AL
MOV AL, 07H
OUT 21H, AL
MOV AL, 2FH
OUT 21H, AL
STI
;; INIT 8254
MOV DX, CON8254
MOV AL, 00110110B
OUT DX, AL
MOV DX, C008254
MOV AL, 00H
OUT DX, AL
MOV AL, 48H
OUT DX, AL
MOV AX, 0000H
LO:
MOV AH, 01H
MOV AL, POS
CALL PUT_PRE
CALL PUT
CALL DELAY
INC AH
DEC AL
CALL PUT_PRE
CALL PUT
CALL DELAY
INC AH
DEC AL
CALL PUT_PRE
CALL PUT
CALL DELAY
JMP LO
MOV AX, 4C00H
INT 21H
START ENDP
MIR6:
DEC AX
DEC POS
CMP POS, 0
JGE MIR6_END
ADD POS, 6
MIR6_END:
IRET
PUT_PRE PROC
CMP AH, 0
JGE SKIP_AH
ADD AH, 10
SKIP_AH:
CMP AL, 0
JGE FIN_PRE
ADD AL, 6
FIN_PRE:
RET
PUT_PRE ENDP
;; NUM: AH
;; POS: AL
PUT PROC
PUSH AX
;; SELECT POS
LEA BX, SEQ
PUSH AX
MOV AH, 0
MOV SI, AX
;; OUTPUT POS
MOV DX, A8255
MOV AL, [BX+SI]
OUT DX, AL
POP AX
;; SELECT NUM
LEA BX, TBL
MOV AL, AH
MOV AH, 0
MOV SI, AX
;; OUTPUT DATA
MOV DX, B8255
MOV AL, [BX+SI]
OUT DX, AL
POP AX
RET
PUT ENDP
DELAY PROC
MOV CX, 0FFH
LOOP $
RET
DELAY ENDP
DELAY_LONG PROC
MOV CX, 0FFFFH
LOOP $
MOV CX, 0FFFFH
LOOP $
MOV CX, 0FFFFH
LOOP $
MOV CX, 0FFFFH
LOOP $
RET
DELAY_LONG ENDP
CODE ENDS
END START

Previous Post
Airsonic Advanced+Google Drive+Caddy 部署纪实
Next Post
[微机实验/TD-PITE] 键盘扫描及数码管显示实验