而且最好不要急,给个ADC0809转换加LED显示的代码看看吧,千万不要急。
; The last experiment of Computer Interface and Assemble Language code
; Original based on the experiment book page 158
; I add some comment and fix the errors which are evident wrong
; But I can't guarantte there is no bugs on the following code, Use at your own risk!
;
; Eric Guo <ericguo@eastday.com>
DATA SEGMENT
MESS DB 'VERY GOOD!', 0AH, 0DH, '$'
; TABLE is fix for all right
TABLE DB 3FH, 06H, 5BH, 4FH, 66H, 6DH, 7DH, 07H, 7FH, 6FH, 77H, 7CH, 39H, 5EH, 79H, 71H
T1 DB 0
T2 DB 0
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
; Save old interrupt procedure
START: MOV AX, 350AH
INT 21H
PUSH ES
PUSH BX
; Install new interrupt procedure to deal ADC0809 EOC signal
MOV DX, CS
MOV DS, DX
MOV DX, OFFSET INTPROC
MOV AX, 250AH
INT 21H
; Initial Data Segment
MOV DX, DATA
MOV DS, DX
; ready to display 300 times digital value
MOV CX, 12CH
; set OCW1 to mask some interrupt see Textbook page 309
MOV DX, 21H
IN AL, DX
AND AL, 0FBH
OUT DX, AL
STI
; Until code LOOP NEXT, the code is intant to do Convert Analog, Display value on LED, etc.
NEXT: PUSH CX
; Start the ADC0809 convert
MOV DX, ADC_PORT
OUT DX, AL
HLT
STI
; use 1000==CX to display LED enough time
MOV CX, 1000
; seek table to get the LED display code on T2
L1: MOV AL, T2 ; LED #1 will display high 4 bit value
MOV AH, 01H ; Select LED #1 which is left most is hardware (not in register!)
LEA BX, TABLE
XLAT ; will save the LED display code to AL
; will display in LED #1 for lower 4 bit
MOV DX, LED_DIS
OUT DX, AL
; display number in LED #1
MOV AL, AH
MOV DX, LED_POS
OUT DX, AL
; switch off LED
MOV DX, LED_POS
MOV AL, 00H
OUT DX, AL
; seek table to get the LED dispaly code on T1
MOV AL, T1 ; LED #2 will display low 4 bit value
LEA BX, TABLE
XLAT
; will display in LED #2 for high 4 bit
MOV DX, LED_DIS
OUT DX, AL
; display number in LED #2
SHL AH, 1 ; Display next digit
MOV AL, AH
MOV DX, LED_POS
OUT DX, AL
; switch off LED
MOV DX, LED_POS
MOV AL, 00H
OUT DX, AL
LOOP L1
; Loop to display
POP CX
LOOP NEXT
; Display one string in CRT
MOV AH, 09H
MOV DX, OFFSET MESS
INT 21H
; Recovery the 8259a OCW1
MOV DX, 21H
IN AL, DX
OR AL, 04H
OUT DX, AL
; Recovery the ole interrupt procedure
POP DX
POP DS
MOV AX, 250AH
INT 21H
; Quit to DOS
MOV AH, 4CH
INT 21H
INTPROC PROC
; get convert value to AL
MOV DX, ADC_PORT
IN AL, DX
; save low 4 bit to T1
MOV AH, AL
AND AL, 0FH
MOV T1, AL
; save high 4 bit to T2
MOV CL, 04H
ROR AH, CL
MOV AL, AH
AND AL, 0FH
MOV T2, AL
; display value in CRT
MOV AL, T1
CALL AVERT
MOV AL, T2
CALL AVERT
MOV AL, 20H
CALL AVERT
; end interrupt in normal EOI, see Textbook page 309
MOV DX, 20H
MOV AL, 20H
OUT DX, AL
STI
IRET
INTPROC ENDP
; AVERT will display one number or char (which ASCII code > 15) in the CRT
AVERT PROC
CMP AL, 10H
JNC L2
CMP AL, 0AH
JC L3
ADD AL, 07H
L3: ADD AL, 30H
L2: MOV DL, AL
MOV AH, 02H ;Display one char, see Textbook page 158
INT 21H
RET
AVERT ENDP
CODE ENDS
END START
END