8255芯片使用程序

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

IOY0 EQU 3000H
IOY1 EQU 3040H
IOY2 EQU 3080H
ADC_0 EQU IOY0+00H*4
ADC_1 EQU IOY0+01H*4
DACS EQU IOY1
PA55 EQU IOY2+00H*4
PB55 EQU IOY2+01H*4
PC55 EQU IOY2+02H*4
PCTL EQU IOY2+03H*4


DATA SEGMENT ;数据段定义
NUM0 DB ?
NUM1 DB ?
MES0 DB 'PRESS 1 TO START!', 0DH, 0AH

DB 'PRESS 2 TO QUIT !',0DH, 0AH, 0DH, 0AH, '$'
MES1 DB 'IN1 OUTPUT DATA =0.00$'
TAB DB 3FH, 06H, 5BH, 4FH, 66H, 6DH, 7DH, 07H, 7FH, 6FH, 77H, 7CH, 39H, 5EH, 79H, 71H
BUFF1 DB 3 DUP(?)
BUFF2 DB 3 DUP(?)
DATA ENDS


STACK1 SEGMENT PARA STACK
DB 256 DUP(?)
STACK1 ENDS


CODE SEGMENT
ASSUME CS:CODE,SS:STACK1,DS:DATA
START: MOV AX,DATA
MOV DS,AX


L0: LEA DX,MES0 ;显示菜单
MOV AH,9
INT 21H
LOP1: MOV DL,0FFH ;等待键盘输入
MOV AH,6
INT 21H
JZ LOP1
CMP AL,'1'
JZ INIT
CMP AL,'2'
JZ EXIT
JMP LOP1

EXIT: MOV AX,4C00H
INT 21H
INIT: MOV DX,OFFSET MES1 ;显示输
MOV AH,09H ;出提示
INT 21H ;信息
AD: MOV DX,PCTL ; 设置8255工
; 作方式字
MOV AL,90H
OUT DX,AL
MOV AL,00H
MOV DX,ADC_0 ;启动IN0
OUT DX,AL
MOV DX,PA55
WAIT0: IN AL,DX ;检测EOC
TEST AL,01H
JZ WAIT0
MOV DX,ADC_0
IN AL,DX
MOV NUM0,AL

CMP AL,80H ;与2.5V比较
JB L1
MOV AL,0FFH
JMP L2
L1: MOV AL,00H
L2: MOV DX,DACS
OUT DX,AL
MOV AL,01H
MOV DX,ADC_1 ;启动IN1
OUT DX,AL
MOV DX,PA55
WAIT1: IN AL,DX ;检测EOC
TEST AL,01H
JZ WAIT1
MOV DX,ADC_1 ;采样值保存
IN AL,DX
MOV NUM1,AL


CALL LEDPRO ;模量转换
CALL CRTPRO
CALL CRT ;屏幕显示
CALL DISP ;数码管显示

MOV DL,0FFH
MOV AH,6
INT 21H
CMP AL,'2'
JNZ AD
JMP L0



LEDPRO PROC ;数码管数据处理
PUSH DX
PUSH AX
MOV DI,OFFSET BUFF1
MOV AL,NUM0
MOV AH,00H


MOV BL,10H
DIV BL
MOV [DI],AL ;高位
INC DI

MOV AL,AH
MOV [DI],AL;低位
POP AX
POP DX
RET
LEDPRO ENDP

CRTPRO PROC
PUSH DX
PUSH AX
MOV AL,NUM1
MOV DI,OFFSET BUFF2
MOV AH,00H
MOV BL,33H
DIV BL
MOV [DI],AL ;个位
INC DI

MOV AL,AH
MOV AH,00H
MOV BL,0AH
MUL BL
MOV BL,33H
DIV BL
MOV [DI],AL
;十分位
INC DI

MOV AL,AH
MOV AH,00H
MOV BL,0AH
MUL BL
MOV BL,33H
DIV BL
CMP AH,19H
JAE L3
DEC AL
L3: INC AL
MOV [DI],AL ;百分位
POP AX
POP DX
RET
CRTPRO ENDP
DISP PROC
PUSH DS
PUSH AX
MOV CL,1
MOV SI,OFFSET BUFF1
DIS1: MOV AL,[SI]
LEA BX,TAB
XLAT
MOV DX,PB55
OUT DX,AL

MOV DX,PC55
MOV AL,CL
OUT DX,AL
CALL DELAY
INC SI
ROL CL,1
CMP CL,08H
JNZ DIS1
POP AX
POP DS
RET
DISP ENDP

CRT PROC
PUSH AX
PUSH DX
PUSH CX
MOV AH,2
MOV DL,08H
INT 21H
INT 21H
INT 21H
INT 21H
MOV DI,OFFSET BUFF2
MOV AL,[DI]
ADD AL,3

0H
MOV DL,AL
INT 21H
MOV DL,2EH
INT 21H
INC DI
MOV AL,[DI]
ADD AL,30H
MOV DL,AL
INT 21H
INC DI
MOV AL,[DI]
ADD AL,30H
MOV DL,AL
INT 21H
POP CX
POP DX
POP AX
RET
CRT ENDP
DELAY PROC
PUSH CX
MOV CX,0FFFFH
LOOP $
POP CX
RET
DELAY ENDP

CODE ENDS
END START


相关文档
最新文档