1.假如我输入数字 3 它的整个运作流程?
感谢!
2.如何根据此程序,编写一个以0位加号判断输入的四位数是否正确
例如(1023 ;1+2=3 结果正确
1035 ;结果错误)
2要包括截图。。
很是感谢!
STACK SEGMENT STACK
DW 64 DUP(?)
STACK ENDS
DATA SEGMENT
TABLE DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV SI,3000H
MOV AL,00H
MOV [SI],AL
MOV [SI+1],AL
MOV [SI+2],AL
MOV [SI+3],AL
MOV DI,3003H
MOV AL,81H
OUT 63H,AL
BEGIN: CALL DIS
CALL CLEAR
CALL CCSCAN
JNZ INK1
JMP BEGIN
INK1: CALL DIS
CALL DALLY
CALL DALLY
CALL CLEAR
CALL CCSCAN
JNZ INK2
JMP BEGIN
INK2: MOV CH,0FEH
MOV CL,00H
COLUM:MOV AL,CH
OUT 60H,AL
IN AL,62H
TEST AL,01H
JNZ LONE
MOV AL,00H
JMP KCODE
LONE: TEST AL,02H
JNZ NEXT
MOV AL,04H
KCODE:ADD AL,CL
CALL PUTBUF
PUSH AX
KON:CALL DIS
CALL CLEAR
CALL CCSCAN
JNZ KON
POP AX
NEXT:INC CL
MOV AL,CH
TEST AL,08H
JZ KERR
ROL AL,1
MOV CH,AL
JMP COLUM
KERR: JMP BEGIN
CCSCAN: MOV AL,00H
OUT 60H,AL
IN AL,62H
NOT AL
AND AL,03H
RET
CLEAR: MOV AL,00H
OUT 61H,AL
RET
DIS: PUSH AX
MOV SI,3000H
MOV DL,0F7H
MOV AL,DL
AGAIN:OUT 60H ,AL
MOV AL,[SI]
MOV BX,OFFSET TABLE
AND AX,00FFH
ADD BX,AX
MOV AL,[BX]
OUT 61H,AL
CALL DALLY
INC SI
MOV AL,DL
TEST AL,01H
JZ OUT1
ROR AL,1
MOV DL,AL
JMP AGAIN
OUT1:POP AX
RET
DALLY: PUSH CX
MOV CX,0010H
T1: MOV AX, 0010H
T2: DEC AX
JNZ T2
LOOP T1
POP CX
RET
PUTBUF:MOV SI,DI
MOV[SI],AL
DEC DI
CMP DI,2FFFH
JNZ GOBACK
MOV DI,3003H
GOBACK:RET
CODE ENDS
END START
1.键盘输入:
一般8255PA口做键盘输入线,PB口作扫描线。可以组成64点阵列,
把按键接在不同的点上,将得到不同的键码,
简单点的话,采用8×2的阵列,共可按16个键。
显示部分
通常由8279控制,由7407驱动8位数码管显示。
- TABLE DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H
这个是LED的7段码,0,1,2,3,4,5,6,7
一个别人调试好的8255程序、希望对你有所帮助。
祝你好运~~
- 8255扫描键盘、显示程序
- 利用8255可编程并行口做一个扫描键盘实验,
- 把按键输入的键码,显示在由8279控制的七段数码管上。
- 8255PA口做键盘输入线,PB口作扫描线。
- D8255 EQU 8506H ;8255状态/数据口地址
- D8255A EQU 8500H ;8255 PA口地址
- D8255B EQU 8502H ;8255 PB口地址
- Z8279 EQU 8701H ;8279状态口地址
- D8279 EQU 8700H ;8279数据口地址
- DISPTR EQU 08H ;当前显示位置
- KEYVAL EQU 09H ;读到的键码
- ORG 0000H
- LJMP START
- ORG 0040H
- MAIN:
- MOV SP,#60H
- LCALL DELAY ;延时
- MOV DISPTR,#30H ;显示缓冲区头指针
- MOV DPTR,#D8255
- MOV A,#90H ;置8255状态
- ;方式0,PB,PC口输出,PA口输入
- MOVX @DPTR,A
- MOV DPTR,#Z8279 ;置8279命令字
- MOV A,#0D3H
- MOVX @DPTR,A ;清LED显示
- MOV A,#00H
- MOVX @DPTR,A
- MOV A,#38H
- MOVX @DPTR,A
- MOV A,#0D1H
- KB_DIS:
- LCALL RD_KB ;读键盘
- MOV A,#0FFH
- CJNE A,KEYVAL,DISBUF ;判读到键
- SJMP KB_DIS ;没有则继续读键
- DISBUF:
- LCALL DISP ;把键移入显存
- LCALL DELAY ;延时消抖
- LCALL DELAY
- SJMP KB_DIS
- DISP: ;显存依次前移
- MOV R1,#31H ;在最后加入新键值
- MOVE:
- MOV A,@R1
- DEC R1
- MOV @R1,A
- INC R1
- INC R1
- CJNE R1,#38H,MOVE
- MOV 37H,KEYVAL
- MOV KEYVAL,#0FFH
- MOV DPTR,#Z8279
- MOV A,#90H
- MOVX @DPTR,A
- MOV R0,#08H
- MOV R1,#30H
- MOV DPTR,#D8279
- LP: MOV A,@R1
- MOVX @DPTR,A
- INC R1
- DJNZ R0,LP
- RET
- RD_KB: ;键盘扫描
- MOV A,#02H ;扫描第一行
- MOV DPTR,#D8255B
- MOVX @DPTR,A
- MOV DPTR,#D8255A
- MOVX A,@DPTR
- MOV R1,#00H
- CJNE A,#0FFH,KEYCAL ;判键是否按下
- MOV A,#01H ;扫描第二行
- MOV DPTR,#D8255B
- MOVX @DPTR,A
- MOV DPTR,#D8255A
- MOVX A,@DPTR
- MOV R1,#08H
- CJNE A,#0FFH,KEYCAL
- SJMP NOKEY ;无键按下
- KEYCAL: ;计算键码
- MOV R0,#08H
- SHIFT:
- RRC A
- JNC CALC
- INC R1
- DJNZ R0,SHIFT
- CALC: ;换算显示码
- MOV DPTR,#DL_DAT
- MOV A,R1
- MOVC A,@A+DPTR
- MOV KEYVAL,A
- RET
- NOKEY: MOV KEYVAL,#0FFH ;返回无键标志
- RET
- DELAY: MOV R0,#0H ;延时子程序
- DELAY1: MOV R1,#0H
- DJNZ R1,$
- DJNZ R0,DELAY1
- RET
- DL_DAT: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H ;0,1,2,3,4,5,6,7
- DB 7FH,6FH,77H,7CH,39H,5EH,79H,71H ;8,9,A,B,C,D,E,F
- END
参考:
http://zhidao.baidu.com/question/54173658.html?fr=qrl
http://www.wm15.cn/Article/shiyan/200708/669.html