org 100h jmp main msg1 db "Analog Input Line 1-8? $" msg2 db " ",10,13,"$" Analog db 0 main: mov dx, offset msg1 ;print 1st message mov ah, 9 int 21h mov ah,1 ;wait for input (echo) int 21h sub al,01h ;make it 0-7 instead of 1-8 sub al,30h ;convert value returned to hex (assuming 0-9 ;key was pressed) mov Analog,al call crlf mov dx, offset msg2 ;print 2nd message mov ah, 9 int 21h call crlf l1: mov dx,2a2h ;Start Conversion mov al,Analog out dx,al in al,dx ;read value call hex_disp ;display in hex call graph ;display graph call crlf ;crlf call time_delay ;delay 1/3 of a sec mov al,0ffh ;reset A/D out dx,al mov ah,0bh ;exit if a key has been pressed int 21h ;otherwise loop cmp al,0ffh jnz l1 ret ;************************************************************* hex_table db '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' hex_disp: push ax push bx push cx mov cl,al shr al,4 lea bx,hex_table mov ah,0 add bx,ax mov al,[bx] mov ah,0eh int 10h mov al,cl and al,0000_1111b lea bx,hex_table mov ah,0 add bx,ax mov al,[bx] mov ah,0eh int 10h pop cx pop bx pop ax ret ;************************************************************* crlf: push ax mov al,10 mov ah,0eh int 10h mov al,13 mov ah,0eh int 10h pop ax ret ;************************************************************* graph: push ax push bx mov bl,al mov al,75 mul bl mov bl,255 div bl mov bl,al cmp al,00 jz g_l2 g_L1: mov al,32 mov ah,0eh int 10h dec bl jnz g_L1 g_L2: mov al,'*' mov ah,0eh int 10h pop bx pop ax ret ;************************************************************* ;Name: TIME_DELAY ; ;Author: Dan Kohn ; ;Date: 10/30/2005 ; ;Revised: 10/31/2005 ; PUSHA does not work on Toshiba XT Compatable ; laptop. Replaced with individual push and pops. ; ;Function: Wait for aprox 0.3 seconds then return to the ; calling code ; ;On Call: NONE ; ;On Return: All Registers Restored time_delay: push ax ;put all reg on stack for restore push bx push cx push dx mov ah,00 ;get system time int 1ah ;(CX:DX = number of clock ;ticks since midnigh) ;[18.20648 ticks = 1 sec) add dx,0005h ;add ticks (~0.3 sec) mov bx,dx ;store for compare t_loop: mov ah,00 ;loop until system time > Last int 1ah ;time + 0.3 sec cmp bx,dx jg t_loop pop dx ;restore all registers pop cx pop bx pop ax RET