Summary: ESA interfacing modules have been used in all the interfacing experiments
INTERFACING EXPERIMENTS
Keyboard Interface
24 keys are arranged in a 3x8 matrix fashion. The row lines are driven by pc0,pc1,pc2. The column lines are read through port A. When no key is pressed, all the return lines are low. The rows are driven high one after another in sequence. When a row is driven high, pressing a key in that row causes the corresponding return lines to be read as high. Then it scans for the column for which the key is pressed. The row and column position can be used to encode the key.
PA0 PA1 PA2 PA3 PA4 PA5 PA6 PA7
| 000 | 011 | 022 | 03 3 | 044 | 05 5 | 06 6 | 077 |
| 08 8 | 099 | 0A | 0B | 0C- | 0D× | 0E | 0F |
| 10AC | 11CE | 12CHK | 13= | 14MC | 15MR | 16M- | 17M+ |
1. Program to scan the keyboard for key closure and store the code of the key pressed in a memory location/display on the screen
.model small
.data
res db ?
.code
mov ax,@data
mov ds,ax
mov dx,123h
mov al,90h
out dx,al
start:mov ah,00h
mov cx,03h
mov bl,01h
repeat:mov al,bl
mov dx,122h
out dx,al
mov dx,120h
in al,dx
cmp al,00h
jnz key
add ah,08h
rol bl,01h
loop repeat
jmp start
key:ror al,01h
jc store
inc ah
jmp key
;hex to ASCII conversion
;to dispaly the code of the key pressed on the screen
store: mov res,ah
mov dl,ah
mov cl,04h
and dl,0f0h
ror dl,cl
cmp dl,0ah
jc d11
add dl,07h
d11: add dl,30h
mov ah,02h
int 21h
mov dl,res
and dl,0fh
cmp dl,0ah
jc d2
add dl,07h
d2: add dl,30h
mov ah,02h
int 21h
mov ah,4ch
int 21h
end
Input:+
Output:0B
2.Program to scan the keyboard for key closure and store the code of the key pressed in a memory location/display on the screen display row no and column no on the screen
.model small
.data
res db ?
.code
mov ax,@data
mov ds,ax
mov dx,123h
mov al,90h
out dx,al
start:mov ah,00h
mov cx,03h
mov bl,01h
repeat:mov al,bl
mov dx,122h
out dx,al
mov dx,120h
in al,dx
cmp al,00h
jnz key
add ah,08h
rol bl,01h
loop repeat
jmp start
key: ror al,01h
jc store
inc ah
jmp key
store: mov res,ah
mov dl,res
call disp
mov dl," "
mov ah,02h
int 21h
mov ah,res
cmp ah,10h
jc loop1
sub ah,10h
jmp loop2
loop1: cmp ah,08h
jc loop2
sub ah,08h
loop2:inc ah
mov dl,ah
mov res,ah
call disp
mov dl, " "
mov ah,02h
int 21h
cmp bl,04h
jne down
dec bl
down: mov res,bl
mov dl,bl
call disp
jmp end1
disp proc
mov cl,04h
and dl,0f0h
ror dl,cl
cmp dl,0ah
jc d11
add dl,07h
d11: add dl,30h
mov ah,02h
int 21h
mov dl,res
and dl,0fh
cmp dl,0ah
jc d2
add dl,07h
d2: add dl,30h
mov ah,02h
int 21h
ret
disp endp
end1: mov ah,4ch
int 21h
end
Input:+
This interface provides 4 digit 7 seven segment display by the output of 4 cascaded SIPO shift registers. Data to be displayed is transmitted serially( bit by bit) to the interface over the port line PB0. Each bit is clocked into the shift registers by providing a common clock through port line PC0. Seven segment device used is common anode type. Hence low input must be given to each seven segment to glow and high to blank.
3.program to implement constant display on seven segment display
.model small
.data
code1 db 099h,0b0h,0a4h,0f9h
count db 0fh
.code
mov ax,@data
mov ds,ax
lea si, code1
mov al,80h
mov dx,123h
out dx,al
mov cx,04h
next1:mov bl,08h
mov al,[si]
next:rol al,01h
mov dx,121h
out dx,al
push ax
mov al,0ffh
mov dx,122h
out dx,al
mov al,00h
out dx,al
pop ax
dec bl
jnz next
inc si
loop next1
mov ah,4ch
int 21h
end
4.program to implement rolling display on seven segment display
.model small
.data
code1 db 099h,0b0h,0a4h,0f9h,0ffh,0ffh,0ffh,0ffh
count db 0fh
.code
mov ax,@data
mov ds,ax
mov al,80h
mov dx,123h
out dx,al
start:lea si,code1
call disp
dec count
jnz start
mov ah,4ch
int 21h
disp proc near
mov cx,08h
next1:mov bl,08h
mov al,[si]
next:rol al,01h
mov dx,121h
out dx,al
push ax
mov al,0ffh
mov dx,122h
out dx,al
mov al,00h
out dx,al
pop ax
dec bl
jnz next
inc si
push bx
call delay
pop bx
loop next1
ret
disp endp
delay proc near
mov bx,0fffh
outer:mov di,0ffffh
inner:dec di
jnz inner
dec bx
jnz outer
ret
delay endp
end
5.Program to control the speed of the stepper motor
.model small
.code
mov ax,@data
mov ds,ax
mov dx,123h
mov al,80h
out dx,al
mov dx,120h
mov al,88h
mov cx,0ffh
rotate: out dx,al
push cx
call delay
ror al,01h ;rol for anticlockwise
pop cx
loop rotate
mov ah,4ch
int 21h
delay proc
mov cx,60h ;cx=20h.. to vary the speed
outer: mov bx,0ffffh
inner: dec bx
jnz inner
loop outer
ret
delay endp
end
6.Program to implement half adder using logic controller
.model small
Sum db 0,1,1,2
.code
Mov ax,@data
Mov ds,ax
Mov dx,123h
Mov al,82h
Out dx,al
Mov dx,121h
Lea bx,sum
In al,dx
And al,03h
xlat
Mov dx,120h
Out dx,al
mov ah,4ch
Int 21h
End
Input: PB0, PB1
Output:PA0,PA
| Input | Output | ||
| PB1 | PB0 | PA1(c) | PA0(s) |
| 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 0 |
Note: In the above interfacing experiments, ESA(Electro System Associates) interfacing modules have been used.
7. Program to implement full adder using logic controller
.model small
Sum db 0,1,1,2,1,1,1,3
.code
Mov ax,@data
Mov ds,ax
Mov dx,123h
Mov al,82h
Out dx,al
Mov dx,121h
Lea bx,sum
In al,dx
And al,07h ;lower 3 bits of PB are used as inputs
xlat
Mov dx,120h
Out dx,al ;lower 2 bits of PA are used as outputs
mov ah,4ch
Int 21h
End
Details of the assembler directives used
These are nothing but the commands to the assembler. These are not instructions to the 8086 microprocessor. Directive directs the assembler, reserves the memory location or reserves and pre assigns the memory locations according to the direction. Directives are nothing but the pseudo mnemonics. Different directives are required to perform different tasks. Assembler directives enable us to control the way the program is assembled and listed. They do not generate any machine code for execution.
.MODEL directive: this directive helps in providing shortcuts while defining segments. To use this directive, we have to initialize the memory model before defining any segment. The format is ‘.model memory model’. The memory model can be SMALL, MEDIUM, COMPACT or LARGE. The small memory model is used if the program is less than 64kbytes.
.DATA: This is the simplified directive to define the data segment.
.CODE: This is the simplified directive to define the code segment.
The general format is
.CODE
All the executable codes must be placed in this segment.
DB directive: Define byte directive: The DB directive is used to define a variable or to set aside one or more storage locations of type byte in memory.
DW directive: Define word directive: The DD directive is used to define a variable of type double word or to reserve memory locations which can be accessed as type double word.
END directive: The END directive is put after the last statement of a program to tell that this is the End of the program module.
ENDP directive: This directive is used along with the name of the procedure to indicate the end of a procedure to the assembler. This directive together with the procedure directive, ‘PROC’ is used to ‘bracket’ a procedure.
PROC directive: The start of the procedure is indicated by the PROC directive. The general format is
PROC_NAME PROC[DIST]
Where dist is optional and can be either NEAR of FAR. The default value for dist is NEAR. For a procedure that is in the same segment as the calling program, we use the NEAR option.
.STACK directive: This is a simplified segment directive to define the stack segment.
The general format is
.STACK[size]
the default stack size is 1024 bytes.
.STACK 64 results in reserving 64 bytes fro the stack operations.