数据采集与控制系统

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

IOY0 EQU 3000H ;8255
PA55 EQU IOY0+00H*4 ;8255的A口地址 ---->3000H
PB55 EQU IOY0+01H*4 ;8255的B口地址 ---->3004H
PC55 EQU IOY0+02H*4 ;8255的C口地址 ---->3008H
P55CTL EQU IOY0+03H*4 ;8255的控制寄存器地址 ---->300CH

IOY1 EQU 3040H ;8254
MY8254_COUNT0 EQU IOY1+00H*4 ;8254计数器0端口地址 ---->3040H
MY8254_COUNT1 EQU IOY1+01H*4 ;8254计数器1端口地址 ---->3044H
MY8254_COUNT2 EQU IOY1+02H*4 ;8254计数器2端口地址 ---->3048H
MY8254_MODE EQU IOY1+03H*4 ;8254控制寄存器端口地址 ---->304CH

IOY2 EQU 3080H ;ADC
ADCS EQU IOY2+00H*4 ;ADC0809的端口地址

I0Y3 EQU 30C0H


STACK1 SEGMENT STACK
DB 256 DUP (?)
STACK1 ENDS

DATA SEGMENT
ARRAY DB 10 DUP (0)
LED DB 3FH,06H,5BH,4FH,66H ;LED数码管的共阴极段码
DB 6DH,7DH,07H,7FH,6FH
VOL DB 3 DUP (0)
MAX DB 00H
MIN DB 00H
AVE DB 00H
DATA ENDS

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

MOV AL,10001000B ;8255控制字, A口B口C口低四位输出, C口高四位输入
MOV DX,P55CTL
OUT DX,AL ;置8255控制字

MOV AL,00H ;LED全灭
MOV DX,IOY3
OUT DX,AL

K7LISTEN:MOV DX,PC55
IN AL,DX
TEST AL,10000000B ;测试K7, 为0退出.
JZ QUIT

MOV CX,0AH ;采集10次数据存入数组ARRAY
MOV BX,OFFSET ARRAY

DACON: MOV DX,ADCS
OUT DX,AL

EOC: MOV DX,PC55 ;检测AD转换是否结束
IN AL,DX
TEST AL,00100000B ;测试PC5端是否为高电位, 高电位则转换结束
JZ EOC

MOV DX,ADCS ;取A/D转换结果
IN AL,DX
MOV [BX],AL ;结果存入数组ARRAY
INC BX ;数组指针向下移动
LOOP DACON

CALL AVERAGE ;求平均值

MOV DX,PC55
IN AL,DX
TEST AL,01000000B ;测试K6, 为0则是数据采集, 为1是数字电压表
JZ OPN1
CALL DV
JMP K7LISTEN
OPN1: CALL DACS ;数据采集控制系统
JMP K7LISTEN
QUIT: MOV AX,4C00H ;程序结束
INT 21H


AVERAGE PROC
XOR AX,AX
MOV BX,OFFSET ARRAY ;取数组地址
MOV AL,[BX]
MOV MAX,AL ;数据最大值, 最小值缓冲区 设置第一个数组元素为最大值和最小值
MOV MIN,AL

MOV DL,AL
MOV DH,00H
MOV CX,09H
LP1: INC BX
MOV AL,[BX]
CMP AL,MAX
JB BELOW
MOV MAX,AL
JMP SUM
BELOW: CMP MIN,AL
JB SUM
MOV MIN,AL
SUM: MOV AH,00H
ADD DX,AX
LOOP LP1

MOV AL,MAX
MOV AH,00H
SUB DX,AX
MOV AL,MIN
MOV AH,00H
SUB DX,AX
MOV AX,DX
MOV BL,08H
DIV BL
MOV AVE,AL
RET
AVERAGE ENDP

DACS PROC
MOV AL,AVE
CMP AL,33H ;33H*1
JNBE BELOW2
;LED数码管显示1
MOV AL,06H ;LED数码管显示1
MOV DX,PA55
OUT DX,AL
MOV AL,10000000B
MOV DX,PB55
OUT DX,AL

MOV CX,

08H
MOV DX,I0Y3
MOV AL,00000001B ;最右灯亮
LED1: OUT DX,AL
ROL AL,01H ;不带进位循环左移一位
CALL DELAYLONG ;延迟
LOOP LED1
JMP ENDLED

BELOW2: CMP AL,66H ;33H*2
JNBE BELOW3
MOV AL,5BH ;LED数码管显示2
MOV DX,PA55
OUT DX,AL
MOV AL,10000000B ;点亮一个数码管
MOV DX,PB55
OUT DX,AL

MOV CX,04H
MOV DX,IOY3
MOV AL,11000000B ;最左两灯亮
LIGHT2: OUT DX,AL
ROR AL,01H ;不带进位循环右移两位
ROR AL,01H
CALL DELAYLONG ;延迟
LOOP LIGHT2
JMP ENDLED

BELOW3: CMP AL,99H ;33H*3
JNBE BELOW4

MOV AL,4FH ;LED数码管显示3
MOV DX,PA55
OUT DX,AL
MOV AL,10000000B ;点亮一个数码管
MOV DX,PB55
OUT DX,AL

MOV CX,08H
MOV DX,IOY3
MOV AL,00000001B ;点亮最右灯
LIGHT3: OUT DX,AL
SHL AL,01H ;逻辑左移一位, 最低位补0
ADD AL,00000001B ;最低位补一
CALL DELAYLONG ;延迟
LOOP LIGHT3
JMP ENDLED

BELOW4: CMP AL,0CCH ;33H*4
JNBE BELOW5

MOV AL,66H ;LED数码管显示4
MOV DX,PA55
OUT DX,AL
MOV AL,10000000B ;点亮一个数码管
MOV DX,PB55
OUT DX,AL

MOV CX,08H
MOV DX,IOY3
MOV AL,11111111B ;全亮
LIGHT4: OUT DX,AL
CALL DELAYLONG
SHR AL,01H
LOOP LIGHT4
JMP ENDLED


BELOW5: MOV AL,6DH ;LED数码管显示5
MOV DX,PA55
OUT DX,AL
MOV AL,10000000B ;点亮一个数码管
MOV DX,PB55
OUT DX,AL

MOV AL,00110110B ;计数器0, 先读/写低八位,再读/写高八位, 方式3
MOV DX,MY8254_MODE
OUT DX,AL
MOV AL,00H
MOV DX,MY8254_COUNT0
OUT DX,AL
MOV AL,48H
OUT DX,AL
MOV AL,01110110B ;计数器1, 先读/写低八位,再读/写高八位, 方式3
MOV DX,MY8254_MODE
OUT DX,AL
MOV AL,64H ;100分频(0064H)
MOV DX,3044H
OUT DX,AL
MOV AL,00H
OUT DX,AL

MOV AL,00000001B ;8255的C口0位置1, D15闪动
MOV DX,P55CTL
OUT DX,AL

LED5: MOV DX,I0Y3
MOV AL,AVE
OUT DX,AL
CALL DELAYLONG
CALL DELAYLONG
CALL DELAYLONG
MOV AL,00H
OUT DX,AL
CALL DELAYLONG
CALL DELAYLONG
CALL DELAYLONG

MOV DX,PC55
IN AL,DX
TEST AL,10000000B
JZ ENDLED
TEST AL,01000000B
JNZ ENDLED
;采集10次数据存入数组ARRAY
MOV CX,0AH
MOV BX,OFFSET ARRAY

;启动模数转换
ADCON1: MOV DX,ADCS
OUT DX,AL
;查询转换是否结束
EOC1: MOV DX,PC55
IN AL,DX
TEST AL,00100000B
JZ EOC1

MOV DX,ADCS
IN AL,DX
MOV [BX],AL
INC BX
LOOP ADCON1

CALL A

VERAGE ;求平均值
MOV AL,AVE
CMP AVE,0CCH
JNBE LED5
MOV AL,00H ;8255的C口0位置0, D15停止闪动
MOV DX,P55CTL
OUT DX,AL
ENDLED: MOV AL,00H
MOV DX,I0Y3
OUT DX,AL ;使LED灯全灭
RET
DACS ENDP

DV PROC
XOR AX,AX
MOV AL,AVE
MOV DL,33H
DIV DL
MOV VOL[0],AL

MOV AL,AH
MOV AH,00H
MOV DL,0AH
MUL DL
MOV DL,33H
DIV DL
MOV VOL[1],AL

MOV AL,AH
MOV AH,00H
MOV DL,0AH
MUL DL
MOV DL,33H
DIV DL ;商-->AL
MOV VOL[2],AL;小数点后第二位

MOV CX,0AH
MOV BX,OFFSET LED

AGAIN: MOV AL,VOL[0]
XLAT
OR AL,80H
MOV DX,PA55
OUT DX,AL
MOV AL,00100000B
MOV DX,PB55
OUT DX,AL
CALL DELAYSHORT

MOV AL,VOL[1]
XLAT
MOV DX,PA55
OUT DX,AL
MOV AL,01000000B
MOV DX,PB55
OUT DX,AL
CALL DELAYSHORT

MOV AL,VOL[2]
XLAT
MOV DX,PA55
OUT DX,AL
MOV AL,10000000B
MOV DX,PB55
OUT DX,AL
CALL DELAYSHORT

LOOP AGAIN
RET

DV ENDP

DELAYLONG PROC
PUSH CX
PUSH DX
MOV DX,04FFH
L1: MOV CX,0FFFFH
LOOP $
DEC DX
JNZ L1
POP DX
POP CX
RET
DELAYLONG ENDP

DELAYSHORT PROC
PUSH CX
MOV CX,0FFFFH
LOOP $
POP CX
RET
DELAYSHORT ENDP

CODE ENDS
END START

相关文档
最新文档