loading...

8 x 3 keypad for key closure and display using ALP

The following ALP scans a 8×3 keypad for key closure and display on the screen. Also display row and column numbers of the key pressed.

assume cs:code,ds:data
DATA SEGMENT
msg1 db 'The col number is =’
col db ? 13,10,’$’
msg2 db 'The row number is =’
row db ? 13,10,’$’
msg db 'Enter any key’, 13,10,’$’
Data ends
CODE SEGMENT
Start:        mov ax,data
              mov ds,ax
              mov al,90h
              mov dx,0d883h
              out dx,al
              mov cl,01
              mov ah,09h
              lea dx,msg
              int 21h
repeat:       mov dx,0d882h
              mov al,01h
              out dx,al
              mov dx,0d880h
              in al,dx
              cmp al,00h
              jz next
              jnz fc
next:         mov dx,0d882h
              mov al,02h
              out dx,0d880h
              in al,dx
              cmp al,00h
              jnz sc
              mov dx,0d882h
              mov al,04h
              out dx,al
              mov dx,0d880h
              in al,dx
              cmp al,00h
              jnz tc
              jmp repeat
fc:           call delay
              mov bh,31h
              mov ch,30h
next1:        inc ch
              shr al,01h
              jc disp1
              jmp next1
sc:.          call delay
              mov bh,32h
              mov ch,30h
next2:        inc ch
              shr al,01h
              jc disp1
              jmp next2
tc:           call delay
              mov bh,33h
              mov ch,30h
next3:        inc ch
              shr al,01h
              jc disp1
              jmp next3
disp1:        mov col,ch
              mov dx,offset msg1
              mov ah,09h
              int ah,09h
              int 21h
              mov row,bh
              mov dx,offset msg2
              mov ah,09h
              int 21h
              dec cl
              cmp cl,00h
              je terminate
              jmp repeat
              call delay
terminate:    mov ah,4ch
              int 21h
delay proc
              push ax
              push cx
              mov cx,0200h
aga3 :        mov ax,0fffh
again2:       dec ax
              jnz again2
              loop aga3
              Pop cx
              pop ax
              ret 
              delay endp
              code ends
              end Start



The output of the above code is –

 
Output:
Enter any key
0
The col number is 1
The row number is 1

Also read: Smartphone Photography for Intermediates

0 4

Leave a Reply

Your email address will not be published.