1、8255基本输入输出
能够在自行设计的接口开发板上,实现拨动开关控制LED的亮灭。
DATA SEGMENT
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV DX,0606H
MOV AL,10000010B
OUT DX,AL
NEXT:
MOV DX,0602H
IN AL,DX
MOV DX,0600H
OUT DX,AL
JMP NEXT
MOV AH,4CH
INT 21H
CODE ENDS
END START
2、数码管应用
能够在自行设计的接口开发板上,数码管显示0到7,实现拨动不同开关,数码管显示该开关位置值(1-8);若同时拨动两个以上开关,则数码管显示"E"
DATA SEGMENT
NUM DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,79H
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
MOV DX,0606H
MOV AL,10010000B
OUT DX,AL
LOOP2:
MOV DX,0600H
IN AL,DX
CMP AL,00000000B
MOV SI,OFFSET NUM
JZ NEXT
MOV BL,AL
SUB BL,1
AND BL,AL
CMP BL,00000000B
MOV SI,OFFSET NUM+9
JNZ NEXT
MOV SI,OFFSET NUM+1
LOOP1:
CMP AL,00000001B
JZ NEXT
SHR AL,1
INC SI
JMP LOOP1
NEXT:
MOV AL,[SI]
MOV DX,0602H
OUT DX,AL
JMP LOOP2
MOV AH,4CH
INT 21H
CODE ENDS
END START
IOY0 EQU 0600H ;片选IOY0对应的端口始地址
MY8255_A EQU IOY0+00H*2 ;8255的A口地址
MY8255_B EQU IOY0+01H*2 ;8255的B口地址
MY8255_C EQU IOY0+02H*2 ;8255的C口地址
MY8255_MODE EQU IOY0+03H*2 ;8255的控制寄存器地址
SSTACK SEGMENT STACK
DW 32 DUP(?)
SSTACK ENDS
DATA SEGMENT
NUMS DB 3FH,06H,5BH,4FH,66h,6dh,7dh,07h,7fh,6fh,79H
REAL DB 0,0,4,0,0,0
TARGET DB 0,0,0,0,0,0
WHICH DB 0
CLOCKER DB 0
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE
START: MOV DX, MY8255_MODE
MOV AL, 81H
OUT DX, AL
MOV BX, 8001H
MOV DX,MY8255_B
MOV AL,0H
OUT DX,AL
CTRL:
MOV SI,DATA
MOV DS,SI
MOV DX, MY8255_C
IN AL, DX
TEST AL,8H
JNZ DANG_4
TEST AL,4H
JNZ DANG_3
TEST AL,2H
JNZ DANG_2
TEST AL,1H
JNZ DANG_1
JMP DANG_0
DANG_0:
MOV AL,0
MOV DI,OFFSET TARGET
ADD DI,2H
MOV DS:[DI],AL
SAL AL,4
OUT DX,AL
JMP STARTP
DANG_1:
MOV AL,1
MOV DI,OFFSET TARGET
ADD DI,2H
MOV DS:[DI],AL
SAL AL,4
OUT DX,AL
JMP STARTP
DANG_2:
MOV AL,2
MOV DI,OFFSET TARGET
ADD DI,2H
MOV DS:[DI],AL
SAL AL,4
OUT DX,AL
JMP STARTP
DANG_3:
MOV AL,4
MOV DI,OFFSET TARGET
ADD DI,2H
MOV DS:[DI],AL
SAL AL,4
OUT DX,AL
JMP STARTP
DANG_4:
MOV AL,8
MOV DI,OFFSET TARGET
ADD DI,2H
MOV DS:[DI],AL
SAL AL,4
OUT DX,AL
STARTP:
MOV DI,OFFSET CLOCKER
MOV AX,DS:[DI]
CMP AX,0055H
JZ CTINC
INC AX
MOV DS:[DI],AX
CALL PRINTALL
;CALL DELAY
JMP CTRL
CTINC:
MOV AX,0
MOV DS:[DI],AX
CALL COMPARE
CMP AX,1H
JZ CTRDEC
CMP AX,2H
JZ CTRINC
JMP CTRL
CTRINC:
CALL INCREMENT
JMP CTRL
CTRDEC:
CALL DECREMENT
J_END:
JMP CTRL
;CALL
DELAY:
MOV CX, 00fFH
AA2:
LOOP AA2
RET
INCREMENT:;AL is current bit
MOV SI,DATA
MOV DS,SI
MOV AL,0
MOV AH,0
MOV DI,OFFSET REAL
ADD DI,AX
MOV AH,DS:[DI]
INC AH
MOV DS:[DI],AH ;increment lowest bit
TOHIGH:
;AH is the value of current bit
CMP AH,0AH
JNZ INCEND
MOV AH,0
MOV DS:[DI],AH ;set current bit 0
MOV BL,6
DEC BL
CMP AL,BL ;whether is the highest bit
JZ INCEND
INC AL
MOV BX,AX
MOV DI,OFFSET REAL
ADD DI,BX
MOV AH,DS:[DI]
INC AH
MOV DS:[DI],AH ;;make higher bit inc
JMP TOHIGH
INCEND:
RET
DECREMENT:
MOV SI,DATA
MOV DS,SI
MOV AL,0
MOV AH,0
MOV DI,OFFSET REAL
ADD DI,AX
MOV AH,DS:[DI]
DEC AH
MOV DS:[DI],AH ;increment lowest bit
TODLOW:
;AH is the value of current bit
CMP AH,00FFH
JNZ DECEND
MOV AH,9H
MOV DS:[DI],AH ;set current bit 9
MOV BL,6
DEC BL
CMP AL,BL ;whether is the highest bit
JZ DECEND
INC AL
MOV AH,0
MOV BX,AX
MOV DI,OFFSET REAL
ADD DI,BX
MOV AH,DS:[DI]
DEC AH
MOV DS:[DI],AH ;make higher bit inc
JMP TODLOW
DECEND:
RET
;AX 1 bigger 2 smaller 0 equall
COMPARE:
MOV SI,DATA
MOV DS,SI
MOV BX,05H
CMPSTART:
CMP BX,00FFFFH
JZ CMPEQUALLEND
MOV DI,OFFSET REAL
ADD DI,BX
MOV AL,DS:[DI]
MOV DI,OFFSET TARGET
ADD DI,BX
MOV AH,DS:[DI]
CMP AL,AH
JNLE CMPBIGEND
JNGE CMPSMALLEND
DEC BX
JMP CMPSTART
CMPBIGEND:
MOV AX,1H
RET
CMPSMALLEND:
MOV AX,2H
RET
CMPEQUALLEND:
MOV AX,0H
RET
PRINTALL:
MOV SI,DATA
MOV DS,SI
MOV BX,00H
MOV AL,11011111B
MOV DI,OFFSET WHICH
MOV DS:[DI],AL
PASTART:
CMP BX,3H
JZ PAEND
MOV DX,MY8255_B
MOV AL,11111111B
OUT DX,AL
MOV AH,0H
MOV DI,OFFSET REAL
ADD DI,BX
MOV AL,DS:[DI]
MOV SI,DATA
MOV DI,OFFSET NUMS
ADD DI,AX
MOV DS,SI
MOV AL,DS:[DI]
MOV DX,MY8255_A
OUT DX,AL
MOV DX,MY8255_B
MOV DI,OFFSET WHICH
MOV AL,DS:[DI]
OUT DX,AL
ROR AL,1
MOV DS:[DI],AL
INC BX
JMP PASTART
PAEND:
RET
CODE ENDS
END START