ToC 实验内容 实验接线 代码 选做实验 说明 效果 代码 实验内容 在数码管上显示键盘输入的内容,新输入的内容显示在数码管的最右侧。 当数码管显示空间已满时,删除最左侧的文本。 实验接线 这次的接线和上次是一样的。唯一的不同是不能不连 Y1-Y4 了(笑) 代码 1A8255 EQU 0600H2B8255 EQU 0602H3C8255 EQU 0604H4CON8255 EQU 0606H5ROWOUT EQU 200H6 7SSEG SEGMENT STACK8 DW 20 DUP(?)9SSEG ENDS10 11DATA SEGMENT12 TBL:13 DB 3FH ;; 014 DB 06H ;; 115 DB 5BH ;; 216 DB 4FH ;; 317 DB 66H ;; 418 DB 6DH ;; 519 DB 7DH ;; 620 DB 07H ;; 721 DB 7FH ;; 822 DB 6FH ;; 923 DB 77H ;; A24 DB 7CH ;; B25 DB 39H ;; C26 DB 5EH ;; D27 DB 79H ;; E28 DB 71H ;; F29 SEQ:30 DB 00011111B ;; POS 031 DB 00101111B ;; POS 132 DB 00110111B ;; POS 233 DB 00111011B ;; POS 334 DB 00111101B ;; POS 435 DB 00111110B ;; POS 536 VAL:37 DB 6 DUP(0)38 VAL_USED:39 DB 6 DUP(0)40 VAL_HEAD DW 0005H41DATA ENDS42 43CODE SEGMENT44ASSUME CS:CODE, DS:DATA, SS:SSEG45START PROC46 MOV AX, DATA47 MOV DS, AX48 49 MOV AL, 81H ;;10001001B ;; A B OUT, C IN50 MOV DX, CON825551 OUT DX, AL52 53 MOV AX, 0000H54LO:55 CALL VAL_DISPLAY56 CALL SCAN57 CMP AX, 10H58 JE LO59 CALL VAL_INSERT60WAIT_UP:61 CALL VAL_DISPLAY62 CALL KEY_PRESSED63 CMP AX, 164 JE WAIT_UP65 JMP LO66 67 MOV AX, 4C00H68 INT 21H69START ENDP70 71SCAN PROC72BEGIN:73 CALL KEY_PRESSED ;; EXIT IF NOT PRESSED74 CMP AX, 075 JE SCAN_NO_KEY76 77 CALL DELAY78 CALL KEY_PRESSED79 CMP AX, 080 JE SCAN_NO_KEY81 82 MOV CH, 0FEH83 MOV CL, 084COLUMN:85 MOV AL, CH86 MOV DX, A825587 OUT DX, AL88 MOV DX, C825589 IN AL, DX90L1:91 TEST AL, 192 JNZ L293 MOV AL, 00H94 JMP KCODE95L2:96 TEST AL, 297 JNZ L398 MOV AL, 04H99 JMP KCODE100L3:101 TEST AL, 4102 JNZ L4103 MOV AL, 08H104 JMP KCODE105L4:106 TEST AL, 8107 JNZ NEXT108 MOV AL, 0CH109KCODE:110 ADD AL, CL111 JMP SCAN_FIN112NEXT:113 INC CL114 MOV AL, CH115 TEST AL, 08H116 JE SCAN_NO_KEY117 ROL AL, 1118 MOV CH, AL119 JMP COLUMN120 121SCAN_NO_KEY:122 MOV AX, 10H123SCAN_FIN:124 RET125SCAN ENDP126 127;; RETURN WHETHER KEY PRESSED IN AX128KEY_PRESSED PROC129 MOV DX, A8255130 MOV AL, 00H131 OUT DX, AL ;; LINE OUTPUT 0000132 133 MOV DX, C8255134 IN AL, DX ;; GET LINE STATUS135 AND AL, 0FH136 CMP AL, 0FH137 JE KP_NONE138 139 MOV AX, 1 ;; KEY PRESSED140 RET141KP_NONE:142 MOV AX, 0143 RET144KEY_PRESSED ENDP145 146 147;; INSERT AX TO VAL[VAL_HEAD]148;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;149;; INDEX: 0 1 2 3 4 5150;; VALUE: A B C D E F151;; HEAD: |152;; INPUT: 0153;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;154;; INDEX: 0 1 2 3 4 5155;; VALUE: 0 B C D E F156;; HEAD: |157;; (-> 1 BYTE)158;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;159VAL_INSERT PROC160 PUSH BX161 LEA BX, VAL162 MOV SI, VAL_HEAD163 164 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;165 ;; !!!CAUTION!!! ;;166 ;; MAKE SURE TO USE 8-BIT REGISTER ;;167 ;; IF YOU WANT TO MOVE BYTES ;;168 ;; BETWEEN MEMORY AND REGISTER!! ;;169 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;170 MOV [BX+SI], AL ;; NUMBER BYTE171 MOV DL, 1172 MOV [BX+SI+6], DL ;; DISPLAY BYTE173 INC SI174 CMP SI, 5 ;; HEAD <= 5, SKIP175 JLE VI_EXIT176 177 SUB SI, 6 ;; MAKE HEAD IN [0, 5]178 179VI_EXIT:180 MOV VAL_HEAD, SI181 POP BX182 RET183VAL_INSERT ENDP184 185 186;; DISPLAY VAL ARRAY187;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;188;; INDEX: 0 1 2 3 4 5189;; VALUE: A B C D E F190;; HEAD: |191;; THIS IS THE SAME DIRECTION AS SCREEN192;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;193VAL_DISPLAY PROC194 PUSH CX195 MOV CX, 6196 197 LEA BX, VAL198 MOV SI, VAL_HEAD199 200VD_LO:201 PUSH CX202 MOV AH, [BX+SI]203 MOV AL, CL204 DEC AL205 206 MOV DH, [BX+SI+6]207 CMP DH, 0208 JE VD_SKIP_BIT209 210 PUSH BX211 PUSH SI212 CALL PUT213 CALL DELAY214 POP SI215 POP BX216 217VD_SKIP_BIT:218 POP CX219 ;; CALCULATE NEXT SI220 INC SI221 CMP SI, 5 ;; HEAD <= 5, SKIP222 JLE VD_SI_SKIP223 SUB SI, 6224 225VD_SI_SKIP:226 LOOP VD_LO227 228 POP CX229 RET230VAL_DISPLAY ENDP231 232;; NUM: AH233;; POS: AL234PUT PROC235 PUSH AX236 237 ;; SELECT POS238 LEA BX, SEQ239 PUSH AX240 MOV AH, 0241 MOV SI, AX242 243 ;; OUTPUT POS244 MOV DX, A8255245 MOV AL, [BX+SI]246 OUT DX, AL247 POP AX248 249 ;; SELECT NUM250 LEA BX, TBL251 MOV AL, AH252 MOV AH, 0253 MOV SI, AX254 255 ;; OUTPUT DATA256 MOV DX, B8255257 MOV AL, [BX+SI]258 OUT DX, AL259 260 POP AX261 RET262PUT ENDP263 264DELAY PROC265 MOV CX, 0FFH266 LOOP $267 RET268DELAY ENDP269 270CODE ENDS271END START 选做实验 说明 通过键盘输入 0-E,将刚刚输入的一位数字显示在数码管上。 最开始数码管无显示。在输入新数字后,将输入的数字显示在数码管最右端。之后每次输入数字,数字的显示位置向左移动一格。 当显示的数字已经位于最左时,此时输入的数字并不立即向右移动,而是先在最左停顿一次,下一个输入的数字再向右移动。 到达最右时的处理和最左一致。 键盘输入 F 时程序退出。 效果 上面说的这段话简直就不是人话,还是看一下实际的效果吧( 代码 1A8255 EQU 0600H2B8255 EQU 0602H3C8255 EQU 0604H4CON8255 EQU 0606H5ROWOUT EQU 200H6 7SSEG SEGMENT STACK8 DW 20 DUP(?)9SSEG ENDS10 11DATA SEGMENT12 TBL:13 DB 3FH ;; 014 DB 06H ;; 115 DB 5BH ;; 216 DB 4FH ;; 317 DB 66H ;; 418 DB 6DH ;; 519 DB 7DH ;; 620 DB 07H ;; 721 DB 7FH ;; 822 DB 6FH ;; 923 DB 77H ;; A24 DB 7CH ;; B25 DB 39H ;; C26 DB 5EH ;; D27 DB 79H ;; E28 DB 71H ;; F29 DB 00H ;; CLR30 SEQ:31 DB 00011111B ;; POS 032 DB 00101111B ;; POS 133 DB 00110111B ;; POS 234 DB 00111011B ;; POS 335 DB 00111101B ;; POS 436 DB 00111110B ;; POS 537 VAL DB 00H38 VAL_POS DB 00H39 VAL_SHOW DB 00H40 VAL_STEP DB 00H41DATA ENDS42 43CODE SEGMENT44ASSUME CS:CODE, DS:DATA, SS:SSEG45START PROC46 MOV AX, DATA47 MOV DS, AX48 49 MOV AL, 81H ;;10001001B ;; A B OUT, C IN50 MOV DX, CON825551 OUT DX, AL52 53 MOV AX, 0000H54LO:55 CALL NUM_DISPLAY56 CALL SCAN57 CMP AX, 10H58 JE LO59 CMP AX, 0FH60 JE MA_EXIT61 CALL NUM_SET62WAIT_UP:63 CALL NUM_DISPLAY64 CALL KEY_PRESSED65 CMP AX, 166 JE WAIT_UP67 JMP LO68 69MA_EXIT:70 MOV AX, 1000H71 CALL PUT72 MOV AX, 4C00H73 INT 21H74START ENDP75 76SCAN PROC77BEGIN:78 CALL KEY_PRESSED ;; EXIT IF NOT PRESSED79 CMP AX, 080 JE SCAN_NO_KEY81 82 CALL DELAY83 CALL KEY_PRESSED84 CMP AX, 085 JE SCAN_NO_KEY86 87 MOV CH, 0FEH88 MOV CL, 089COLUMN:90 MOV AL, CH91 MOV DX, A825592 OUT DX, AL93 MOV DX, C825594 IN AL, DX95L1:96 TEST AL, 197 JNZ L298 MOV AL, 00H99 JMP KCODE100L2:101 TEST AL, 2102 JNZ L3103 MOV AL, 04H104 JMP KCODE105L3:106 TEST AL, 4107 JNZ L4108 MOV AL, 08H109 JMP KCODE110L4:111 TEST AL, 8112 JNZ NEXT113 MOV AL, 0CH114KCODE:115 ADD AL, CL116 JMP SCAN_FIN117NEXT:118 INC CL119 MOV AL, CH120 TEST AL, 08H121 JE SCAN_NO_KEY122 ROL AL, 1123 MOV CH, AL124 JMP COLUMN125 126SCAN_NO_KEY:127 MOV AX, 10H128SCAN_FIN:129 RET130SCAN ENDP131 132;; RETURN WHETHER KEY PRESSED IN AX133KEY_PRESSED PROC134 MOV DX, A8255135 MOV AL, 00H136 OUT DX, AL ;; LINE OUTPUT 0000137 138 MOV DX, C8255139 IN AL, DX ;; GET LINE STATUS140 AND AL, 0FH141 CMP AL, 0FH142 JE KP_NONE143 144 MOV AX, 1 ;; KEY PRESSED145 RET146KP_NONE:147 MOV AX, 0148 RET149KEY_PRESSED ENDP150 151;; SET AL TO VAL & MOVE POS152NUM_SET PROC153 PUSH AX154 MOV VAL, AL155 MOV AL, VAL_POS156 ADD AL, VAL_STEP157 158 CMP VAL_STEP, 0 ;; REGULAR STATUS: STEP != 0159 JNE NS_REG160 CMP VAL_POS, 5161 JE NS_LMOST162 MOV VAL_STEP, 1 ;; POS == 0, RIGHT MOST163 JMP NS_FIN164NS_LMOST: ;; POS == 5, LEFT MOST165 MOV VAL_STEP, -1166 JMP NS_FIN167 168NS_REG:169 CMP AL, 5170 JE NS_SET0171 CMP AL, 0172 JE NS_SET0173 JMP NS_FIN174NS_SET0:175 MOV VAL_STEP, 0176NS_FIN:177 MOV VAL_SHOW, 1178 MOV VAL_POS, AL179 POP AX180 RET181NUM_SET ENDP182 183;; DISPLAY VAL AT VAL_POS184NUM_DISPLAY PROC185 ;MOV AL, VAL_SHOW186 CMP VAL_SHOW, 0187 JE ND_SKIP188 189 MOV AH, VAL190 MOV AL, VAL_POS191 CALL PUT192 CALL DELAY193ND_SKIP:194 RET195NUM_DISPLAY ENDP196 197;; NUM: AH198;; POS: AL199PUT PROC200 PUSH AX201 202 ;; SELECT POS203 LEA BX, SEQ204 PUSH AX205 MOV AH, 0206 MOV SI, AX207 208 ;; OUTPUT POS209 MOV DX, A8255210 MOV AL, [BX+SI]211 OUT DX, AL212 POP AX213 214 ;; SELECT NUM215 LEA BX, TBL216 MOV AL, AH217 MOV AH, 0218 MOV SI, AX219 220 ;; OUTPUT DATA221 MOV DX, B8255222 MOV AL, [BX+SI]223 OUT DX, AL224 225 POP AX226 RET227PUT ENDP228 229DELAY PROC230 MOV CX, 0FFH231 LOOP $232 RET233DELAY ENDP234 235CODE ENDS236END START