程序源码:
;author:liuxianfei0810
A8255 EQU 40H
B8255 EQU 42H
C8255 EQU 44H
Q8255 EQU 46H
ADC0808 EQU 20H
;author:liuxianfei0810
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV DX,Q8255
MOV AL,90H
OUT DX,AL
;author:liuxianfei0810
MOV DX,C8255
MOV AL,0FFH
OUT DX,AL
;author:liuxianfei0810
MOV SI,OFFSET TEMPDATA
HERE:
MOV DX,ADC0808;启动AD转换
MOV AL,0
OUT DX,AL
MOV CX,5 ;数码管显示
MON:
MOV Al,[SI];取TEMPDATA
;out=5*vin_analog/256
;OUT=out*100
MOV AH,0
MOV BL,51
DIV BL
;MOV Bx,2
;MUL Bx;AX*BX 结果: DXAX
;mov bx,100;取百位数据
;div bx
;push dx;保存余数,即保存十位和个位数字
;author:liuxianfei0810
MOV BX,OFFSET SEGDATA
XLAT;以BX+AL的和作为偏移地址,从相应的数据段中取出一个字节到AL中
OR AL,80H
MOV DX,B8255
OUT DX,AL
MOV AL,11011111B;第四个即最左边数码管显示
MOV DX,C8255
OUT DX,AL;完成首位显示
CALL DELAY_1S
MOV AL,0FFH
OUT DX,AL
MOV AL,AH
MOV AH,0
MOV BL,5
DIV BL
;author:liuxianfei0810
;pop dx;取出保存的十位和个位数字
;mov ax,dx
;and ax,00ffh
;mov al,al
;mov bl,10;取十位数据
;div bl;al保存十位数字 ah保存个位数字
;author:liuxianfei0810
;mov al,al;用于显示十位数字
;MOV BX,OFFSET SEGDATA;用于显示十位数字
;XLAT
;MOV DX,B8255
;OUT DX,AL
;MOV AL,11011111B
;MOV DX,C8255
;OUT DX,AL;完成十位显示
;CALL DELAY_1S
;author:liuxianfei0810
;mov al,ah;用于显示个位数字
MOV BX,OFFSET SEGDATA
XLAT
MOV DX,B8255
OUT DX,AL
MOV AL,10111111B
MOV DX,C8255
OUT DX,AL;完成个位显示
CALL DELAY_1S
;author:liuxianfei0810
MOV AL,0FFH
OUT DX,AL
MOV AL,01111111B
OUT DX,AL
MOV AL,00011100B
MOV DX,B8255
OUT DX,AL;完成单位显示
CALL DELAY_1S
MOV DX,C8255
MOV AL,0FFH
OUT DX,AL
CALL DELAY_1S
LOOP MON
MOV DX,ADC0808;取ADC0808转换结果
;author:liuxianfei0810
IN AL,DX
MOV [SI],AL;存至TEMPDATA
JMP HERE
;author:liuxianfei0810
DELAY_1S PROC
PUSH BX
PUSH CX
MOV BX,1
LP2: MOV CX,10
LP1: LOOP LP1
DEC BX
JNZ LP2
POP CX
POP BX
RET
;author:liuxianfei0810
DELAY_1S ENDP
CODE ENDS
DATA SEGMENT
SEGDATA DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH
;,77H,7CH,39H,5EH,79H,71H
TEMPDATA DB 0
DATA ENDS
END START
(有关ADC0808芯片讲解见后文)