Cmrcet Department of E.C.E. Experiment No.: 1 16 Bit Arithmetic Operations For 8086

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 40

CMRCET DEPARTMENT OF E.C.E.

Experiment No.: 1
16 bit arithmetic operations for 8086.

Aim: Write an ALP in 8086 to perform 16 bit arithmetic operations.


Experiment 1(a):
Aim: Write an ALP in 8086 to perform 16 bit addition operations.
Apparatus:
C.P.U.
Keyboard
Masm software
Program:
;program to perform 16 bit addition
data segment
a dw 1111h
b dw 2222h
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
xor ax,ax
xor bx,bx
mov ax,a
mov bx,b
add ax,bx
int 03h
code ends
end start

RESULT:
I/P : AX:1111H O/P :AX:3333H
:BX:2222H :BX:2222H

MPMC Lab Manual 1 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.

Experiment 1(b):
Aim: Write an ALP in 8086 to perform 16 bit subtraction operations.
Apparatus:
C.P.U.
Keyboard
Masm software
Program:
;program to perform 16 bit subtraction
data segment
a dw 2222h
b dw 1111h
data ends
code segment
assume cs:code,ds:data
start:mov ax,data

MPMC Lab Manual 2 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.
mov ds,ax
xor ax,ax
xor bx,bx
mov ax,a
mov bx,b
sub ax,bx
int 03h
code ends
end start

RESULT:
I/P : AX:2222H O/P :AX:1111H
:BX:1111H :BX:1111H

MPMC Lab Manual 3 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.

Experiment 1(c):
Aim: Write an ALP in 8086 to perform 16 bit multiplication operations.
Apparatus:
C.P.U.
Keyboard
Masm software
Program:

;program to perform 16 bit multiplication


data segment
a dw 2211h
b dw 2001h
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
xor ax,ax
xor bx,bx
mov ax,a
mov bx,b
mul bx
int 03h
code ends
end start

RESULT:
I/P : AX:2211H O/P :AX:4211H
:BX:2001H :BX:2001H
:DX:0442H

MPMC Lab Manual 4 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.

Experiment 1(d):
Aim: Write an ALP in 8086 to perform 16 bit division operations.
Apparatus:
C.P.U.
Keyboard
Masm software
Program:

;program to perform 16 bit division


data segment
a dw 2211h
b dw 2001h
data ends
code segment

MPMC Lab Manual 5 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
xor ax,ax
xor bx,bx
mov ax,a
mov bx,b
div bx
int 03h
code ends
end start

RESULT:
I/P : AX:2211H O/P :AX:0001H
:BX:2001H :BX:2001H
:DX:0210H

MPMC Lab Manual 6 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.

Experiment 2
Sorting an array for 8086.
Aim: Write an ALP in 8086 to perform sorting an array.
Apparatus:
C.P.U.
Keyboard
Masm software

Program:

data segment
a dw 51h,20h,10h,07h
count equ 04h
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov dx,count-1
again0:
mov cx,dx
mov si,offset a
again1:
mov ax,[si]
cmp ax,[si+2]
jl pr1
xchg [si+2],ax
xchg [si],ax

pr1:
add si,02
loop again1
dec dx
jnz again0
int 03h
code ends
end start
output:
RESULT:

MPMC Lab Manual 7 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.
I/P: 53h,25h,19h,02h O/P: 02h,19h,25h,53h

Experiment 3
Searching for a number or character in a string for 8086.
Aim: Write an ALP in 8086 to search a given number in a sequence.
Apparatus:
C.P.U.
Keyboard
Masm software
Program:
assume cs:code,ds:data ,es:extra
data segment
string1 db 0ah,0dh,"enter a character:",0ah,0dh,"$"
stre db "found$"
strne db "not found$"
data ends
extra segment
string2 db "cmrcet$"
strlen dw ($-string2)
extra ends
code segment
start:mov ax,data

MPMC Lab Manual 8 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.
mov ds,ax
mov ax,extra
mov es,ax
mov dx,offset string1
mov ah,09h
int 21h
mov ah,08h
int 21h
repne scasb
jz lable
mov dx,offset strne
mov ah,09h
int 21h
mov ah,4ch
int 03h
jmp exit
lable:mov dx,offset stre
mov ah,09h
int 21h
mov ah,4ch
int 03h
exit: int 03h
code ends
end start
RESULT:
i/p:
enter a character : C O/P:
Searching Character : c

MPMC Lab Manual 9 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.

Experiment 4
String manipulations for 8086.
Aim: Write an ALP in 8086 to find length of given string which terminates with a special
character.
Apparatus:
C.P.U.
Keyboard
Masm software
Program:
data segment
arr db 'CMRCET#'
arr2 db '#'
data ends
assume cs:code, ds:data
code segment
start:
mov ax,data
mov ds,ax
xor cx,cx
mov si, offset arr
mov bl,arr2
up:mov al, [si]
cmp al,bl
jz go
inc si
inc cl
jmp up
go: int 03h
code ends
end start

RESULT:
I/P String: ‘length’ O/P String length: CL: 06h

MPMC Lab Manual 10 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.

MPMC Lab Manual 11 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.
Experiment 5
Digital clock design using 8086.
AIM: write an ALP in 8086 for displaying the system clock.
Apparatus:
C.P.U.
Keyboard
Masm software
PROGRAM:
ASSUME CS: CODE
CODE SEGMENT
EXTRN GET_TIME: NEAR
.MODEL SMALL
.STACK 100H
.DATA
TIME_BUF DB '00:00:00$'
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS, AX
LEA BX, TIME_BUF
CALL GET_TIME
LEA DX, TIME_BUF
MOV AH, 09H
INT 21H
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
Code ends

RESULT: Program for displaying the system clock performed using masm software.

MPMC Lab Manual 12 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.

Experiment 6
Interfacing ADC and DAC to 8086
AIM: write an ALP in 8086 for displaying the system clock.
Apparatus:
C.P.U.
Keyboard
Masm software.
6.a) ANALOG TO DIGITAL CONVERTER INTERFACING USING INTEL 8255
; DAC FOR ADC INTERFACE
; Connect the interface over J4 of the trainer
; This program illustrates the use of counter method for A/D conversion
; The program can be executed in Standalone or Serial Mode
; Execute the program from 2000H

OUTPUT 2500AD
ORG 2000H
MOV AX,00H ;INITIALISE SEGMENT REGISTERS
MOV CS,AX
MOV ES,AX

MOV SP,3000H ;INITIALISE STACK POINTER


CALL FAR 0FE00:0031H ;NEWLINE
MOV DX,0FFE6H ;INITIALISE 8255 AS FOLLOWS
MOV AL,81H ;PORT A = OUTPUT
OUT DX,AL ;PORT C = INPUT
JMP SHORT START
TEST: DB 0DH,20H,'CONVERTING... ', 00H
MES: DB 0AH,0DH,20H, 'DIGITAL VALUE = ',00H

START: MOV DX,0FFE4H ;wait for start of conversion(SOC)


IN AL,DX
CALL DELAY
CALL DELAY
AND AL,02H
JZ START
MOV AX,0FFH
PUSH AX
CONT: MOV DX,0FFE4H ;check for SOC
IN AL,DX
CALL DELAY
AND AL,02H
JNZ START ;If true start again
POP AX ;else continue
MOV DX,0FFE0H
INC AL ;increment count and

MPMC Lab Manual 13 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.
OUT DX,AL ;output to port
PUSH AX
PUSH DX
LEA DX,TEST ;display 'converting...'
MOV AX,DX
POP DX
CALL FAR 0FE00:0013H
CALL DELAY
MOV DX,0FFE4H ;read comparator output
IN AL,DX
AND AL,00000001B
JNZ CONT ;if PC0=1,continue else
LEA DX,MES ;conversion is over
MOV AX,DX
CALL FAR 0FE00:0013H ;display message
POP AX
CALL FAR 0FE00:0052H ;DISPLAY OUTPUT
CALL FAR 0FE00:0031H
JMP SHORT START

DELAY: MOV CX,8000H ;delay routine


HERE: LOOP HERE
RET
END

MPMC Lab Manual 14 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.

6. b) DIGITAL TO ANALOG CONVERTER INTERFACING USING INTEL 8255


PROGRAM:
Assume the interface is connected over J4 of trainer
; This program generates a Square or Triangular wave at Xout or Yout
; The program can be executed in Stand alone or Serial mode
; Execute the program from memory location 2000H

OUTPUT 2500AD
ORG 2000H
MOV AX,0000H
MOV CS,AX
MOV ES,AX
MOV DX,0FFE6H ;Initialise all 8255
MOV AL,80H ;ports as O/P ports
OUT DX,AL
CALL FAR 0FE00:01EDH ;newline routine
JMP SHORT START ;display message string

MES: DB 0AH, 0DH, 'DUAL DAC INTERFACE '


DB 0AH, 0DH, 'S - SQUARE WAVE'
DB 0AH, 0DH, 'T - TRIAGLUAR WAVE', 0H

START: LEA DX,MES ;display message on LCD


MOV AX,DX ;or console
CALL FAR 0FE00:0013H
GETKEY: CALL FAR 0FE00:00A9H ;wait fo user entry
CMP AL,53H ;if S,jump to square
JE SQUARE ;wave routine
CMP AL,54H ;if T, jump to triangle
JE TRIANGLE ;wave routine
JMP SHORT GETKEY ;wait for valid key

;Triangular wave generation routine

TRIANGLE: CALL FAR 0FE00:0031H


RPT1: MOV CX,0FFH ;set count
MOV AL,00H ;start from 0
UP: INC AL ;increment data for
MOV DX,0FFE0H ;+ive going slope and
OUT DX,AL ;output at port A & B
MOV DX,0FFE2H
OUT DX,AL
LOOP UP
MOV CX,0FFH ;set count
MOV AX,CX ;start from FFh

MPMC Lab Manual 15 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.
DOWN: DEC AL ;decrement data for
MOV DX,0FFE0H ;-ive going slope at
OUT DX,AL ;port A & B
MOV DX,0FFE2H
OUT DX,AL
LOOP DOWN
JMP SHORT RPT1 ;repeat continuously

SQUARE: CALL FAR 0FE00:0031H


RPT2: MOV AL,0FFH ;O/P FFh at ports
MOV DX,0FFE0H
OUT DX,AL
MOV DX,0FFE2H
OUT DX,AL
MOV CX,FFH ;delay
DLY1: LOOP DLY1
MOV AL,00H ;O/P 0 at ports
MOV DX,0FFE0H
OUT DX,AL
MOV DX,0FFE2H
OUT DX,AL
MOV CX,FFH
DLY2: LOOP DLY2 ;delay
JMP SHORT RPT2 ;repeat continuously

END

RESULTS:
INPUT:
DUAL DAC INTERFACE
S - SQUARE WAVE
T - TRIAGLUAR WAVE
-T
OUTPUT:

t1 =t3 t=t1 +t2


t2=t4
Fig: Triangular Wave Form

MPMC Lab Manual 16 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.

Experiment 7
Parallel Communication between two microprocessors kits using 8255
AIM: write an ALP in 8086 for displaying the system clock.
Apparatus:
C.P.U.
Keyboard
Masm software.

Program
TRANSMITTER:
output 2500ad
org 3000h
mov dx,0ffe6h
mov al,80h
out dx,al
mov al,55h
mov dx,0ffe0h
out dx,al
int 03h

RECIVER:
output 2500ad
org 3000h
mov dx,0ffe6h
mov al,80h
out dx,al
mov dx,0ffe0h
in al,dx
int 03h

Result:

tx: rx:

G 4000 G 4000
AX=0055 AX=0955

MPMC Lab Manual 17 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.

Experiment 8
Serial Communication between two microprocessors kits using 8251
AIM: write an ALP in 8086 for displaying the system clock.
Apparatus:
C.P.U.
Keyboard
Masm software.
PROGRAM: TRANSMITTER END
output 2500ad
org 2000h
MOV AL,36
MOV DX,0086
OUT DX,AL
MOV DX,0080
MOV Ax,0Ah
OUT DX,AL
MOV AL,00
OUT DX,AL
MOV SP,3000
MOV DX,0092
OUT DX,AL
OUT DX,AL
OUT DX,AL
OUT DX,AL
CALL DELAY
MOV AL,40
OUT DX,AL
CALL DELAY
MOV AL,CEh
OUT DX,AL
CALL DELAY
MOV AL,27
OUT DX,AL
CALL DELAY
MOV SI,3100
L1:MOV DX,0092
IN AL,DX
AND AL,81
CMP AL,81
JNE L1
MOV AL,[SI]
INC SI
CMP AL,00
JE L3
MOV DX,0090

MPMC Lab Manual 18 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.
OUT DX,AL
JMP L1
L3:INT 03
DELAY:MOV CX,0002
A3: LOOP A3
RET
RECEIVER END
output 2500ad
org 2000h
MOV AL,36
MOV DX,0086
OUT DX,AL
MOV DX,0080
MOV Ax,0Ah
OUT DX,AL
MOV AL,00
OUT DX,AL
MOV SP,3000
MOV DX,0092
OUT DX,AL
OUT DX,AL
OUT DX,AL
OUT DX,AL
CALL DELAY
MOV AL,40
OUT DX,AL
CALL DELAY
MOV AL,CEh
OUT DX,AL
CALL DELAY
MOV AL,27
OUT DX,AL
CALL DELAY
MOV SI,2100
L1:MOV DX,0092
IN AL,DX
CMP AL,1B
JE L1
MOV DX,0090
IN AL,DX
AND AL,81
CMP BL,AL
JE L3
L2:MOV DX,0092
IN AL,DX
AND AL,81

MPMC Lab Manual 19 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.
CMP AL,81
JNE L2
MOV AL,BL
MOV DX,0090
OUT DX,AL
OUT DX,AL
MOV [SI],AL
INC SI
JMP L1
OUT DX,AL
INC SI
JMP L2
L3:INT 03
DELAY:MOV CX,0002
A3: LOOP A3
RET

MPMC Lab Manual 20 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.
Experiment 9
Interfacing stepper motor to 8086
AIM: write an ALP in 8086 for displaying the system clock.
Apparatus:
C.P.U.
Keyboard
Masm software.
Program:
Step clock wise:
output 2500ad
org 2000h
start:mov dx,0ffe6h
mov al,80h
out dx,al
mov dx,0ffe0h
mov al,11h
roc:out dx,al
rcr al,01h
call delay
jmp roc
delay:mov cx,800h
l1:loop l1
ret
end

RESULTS:Stepper Motor Clock Wise Rotation Is Observed

Step anti clockwise:


output 2500ad
org 2000h
start:mov dx,0ffe6h
mov al,80h
out dx,al
mov dx,0ffe0h
mov al,11h
roc:out dx,al
rcl al,01h
call delay
jmp roc
delay:mov cx,800h
l1:loop l1
ret
end

RESULTS:Stepper Motor Anti Clock Wise Rotation Is Observed

MPMC Lab Manual 21 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.

Experiment 10
Programming using arithmetic, logical and bit manipulation instructions of 8051.

Experiment 10(a):
Aim: Write an ALP in 8051 to perform arithmetic operation (addition)using 8051
assembly language programming.

C.P.U.
Keyboard
Keil software

Program:

org 0000h
mov a,#05h
mov b,#04h
add a,b
end

Result:
A = 0x09
B = 0x04
Sp = 0x07
Psw = 0x00
Experiment 10(b):
Aim: Write an ALP in 8051 to perform arithmetic operation (subtraction)using 8051
assembly language programming.

C.P.U.
Keyboard
Keil software

Program:

org 0000h
mov a,#05h
mov b,#04h
subb a,b
end

Result:
A = 0x01
B = 0x04
Sp = 0x07
Psw = 0x01

MPMC Lab Manual 22 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.

Experiment 10(c):
Aim: Write an ALP in 8051 to perform arithmetic operation (multiplication)using
8051 assembly language programming.

C.P.U.
Keyboard
Keil software

Program:

org 0000h
mov a,#05h
mov b,#04h
mul ab
end

Result:
A = 0x14
B = 0x00
Sp = 0x07
Psw = 0x00
Experiment 10(d):
Aim: Write an ALP in 8051 to perform arithmetic operation (division)using 8051
assembly language programming.

C.P.U.
Keyboard
Keil software
Program:

org 0000h
mov a,#08h
mov b,#04h
div ab
end

Result:
A = 0x02
B = 0x00
Sp = 0x07
Psw = 0x01

MPMC Lab Manual 23 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.

Experiment 10(e):
Aim: Write an ALP in 8051 to perform logical operation (AND)using 8051 assembly
language programming.

C.P.U.
Keyboard
Keil software
Program:

org 0000h
mov a,#08h
mov b,#04h
anl a,b
end

Result:
A = 0x00
B = 0x04
Sp = 0x07
Psw = 0x00

Experiment 10(f):
Aim: Write an ALP in 8051 to perform logical operation (OR)using 8051 assembly
language programming.

C.P.U.
Keyboard
Keil software
Program:

org 0000h
mov a,#08h
mov b,#04h
orl a,b
end
Result:
A = 0x0c
B = 0x04
Sp = 0x07
Psw = 0x00

MPMC Lab Manual 24 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.

Experiment 10(g):
Aim: Write an ALP in 8051 to perform logical operation (XOR)using 8051 assembly
language programming.

C.P.U.
Keyboard
Keil software
Program:

org 0000h
mov a,#08h
mov b,#04h
xrl a,b
end
Result:
A = 0x0c
B = 0x04
Sp = 0x07
Psw = 0x00

Experiment 10(h):
Aim: Write an ALP in 8051 to perform logical operation (NOT)using 8051 assembly
language programming.

C.P.U.
Keyboard
Keil software
Program:

org 0000h
mov a,#08h
cpl a
end

Result:
A = 0xf7
B = 0x00
Sp = 0x07
Psw = 0x01

MPMC Lab Manual 25 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.

Experiment 11
Program and verify Timer/Counter in 8051.
Experiment 11(a):
Aim: Write an ALP in 8051 to blink LEDs connected to Port 1 with a delay generated by
using timer 0 in mode 1 using 8051 assembly language programming.

C.P.U.
Keyboard
Keil software

Program:

org 0000h
mov a,#00h
mov tmod,#01h
up: mov tl0,#00h
mov th0,#00h
cpl a
mov p1,a
setb tr0
wait: jnb tf0,wait
clr tr0
clr tf0
sjmp up
end

Result of Timer programming:

MPMC Lab Manual 26 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.

MPMC Lab Manual 27 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.
Experiment 11(b):
Aim: Write an ALP to number of students entering in a class using timer 0 mode1 using
8051 assembly language programming.

C.P.U.
Keyboard
Keil software
Program:

org 0000h
mov a,#00h
mov tmod,#05h
up: mov tl0,#00h
mov th0,#00h
setb tr0
cou: mov a,tl0
mov b,th0
mov p1,a
mov p2,b
jnb tf0,cou
clr tr0
clr tf0
sjmp up
end

Result of Counter Programming:

MPMC Lab Manual 28 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.

MPMC Lab Manual 29 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.
Experiment 12
Program and verify Interrupt handling in 8051.
Aim: Write an ALP to blink LEDs connected to Port 1 when an external interrupt 0 occur
otherwise all the LEDs should be in ON condition using 8051 assembly language
programming.

C.P.U.
Keyboard
Keil software
Program:

org 0000h
sjmp last

org 0003h
mov a,#55h
up: mov p1,a
cpl a
mov r0,#0ffh
d: djnz r0,d
sjmp up
reti
last: mov ie,#81h
l: mov a,#0ffh
mov p1,a
sjmp l
end

Result of Interrupt Programming:

MPMC Lab Manual 30 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.

MPMC Lab Manual 31 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.
Experiment 13
UART Operation in 8051.
Aim: Write an ALP to perform UART operation using 8051 assembly language
programming.

C.P.U.
Keyboard
Keil software
Program:
org 0000h
mov tmod, #20h
mov scon,#50h
mov th1,#-3h
setb tr1
again: mov sbuf,#'m'
here: jnb ti, here
clr ti
mov p0,#'s'
sjmp again
end

Result:

MPMC Lab Manual 32 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.

MPMC Lab Manual 33 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.
Experiment 14
Communication between 8051 kit and PC.
Aim: Write an ALP for communication between 8051 microcontroller and PC.

Apparatus:

C.P.U.
Keyboard
Keil software

Program:
Transmitter:
PORT_A EQU E800H
PORT_B EQU E801H
PORT_C EQU E802H
CWR EQU E8003H
ORG 8000H
MOV DPTR,#CWR;INITIALISE 8255
MOV A,#80H;FOR MODE 0
MOVX,@DPTR,A;ALL PORTS AS OUTPUT PORTS
MOV DPTR,#PORT_A
MOV A,#44H
MOVX @DPTR,A
LCALL 0003H
END

RECIVER:
PORT_A EQU E800H
PORT_B EQU E801H
PORT_C EQU E802H
CWR EQU E8003H
ORG 8000H
MOV DPTR,#CWR;INITIALISE 8255
MOV A,#90H;FOR MODE 0
MOVX,@DPTR,A;ALL PORTS AS OUTPUT PORTS
MOV DPTR,#PORT_A
MOVX A,@DPTR
LCALL 0003H
END

Results:
Tx: a=44
Rx:a=44

MPMC Lab Manual 34 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.
Experiment 15
Interfacing LCD to 8051.
Aim: Write an ALP to interface LCD to 8051 microcontroller.

Apparatus:

C.P.U.
Keyboard
Keil software
PROGRAM:
CMD_PORT EQU 03H
PORT_A EQU 00H
PORT_B EQU 01H
GETKB EQU 142H
GETCH EQU 12A5H

ORG 8000H
ACALL INIT ;Call LCD initialize
;subroutine
MOV A,#80H ;Address for first line
CALL CMD ;display the message waiting
MOV DPTR,#DISP1 ;
MOV R3,#08H
CALL STRING
MOV A,#0C0H ;address for second line
CALL CMD ;display the message for key
MOV DPTR,#DISP2

MOV R3,#08H
CALL STRING

START: MOV R6,#80H ;check Serial or


MOV DPTR,#0E102H ;KB mode of operation
MOVX A,@DPTR
JB ACC.3,KBD
; CLR P3.4
CALL GETCH ;check any key pressed
SJMP DISP
KBD: CALL GETKB
DISP: PUSH A
MOV A,#01H ;Clear display and
CALL CMD ;bring the cursor to
;home position
MOV A,#80H ;Address for first line
CALL CMD
POP A

MPMC Lab Manual 35 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.
CALL DWR ;Display the key

DELAY2: MOV R3,#01H


L1: MOV R1,#0FFH
CALL DELAY
DJNZ R3,L1
MOV A,#0C0H
CALL CMD
MOV DPTR,#MESS
MOV R3,#08H
CALL STRING
MOV A,#02H
CALL CMD
JMP START

INIT: MOV A,#80H ;Configure PA,PB,PC as O/P PORTS


MOV P2,#0E8H
MOV R0,#03H
MOVX @R0,A
MOV R1,#1FH
CALL DELAY
MOV R3,#03H ;Send software reser 3 times
INIT1: MOV A,#38H ;to reset the display
CALL CMD
MOV R1,#3FH
CALL DELAY
DJNZ R3,INIT1
MOV A,#38H ;Function set 8BIT,1 LINE
CALL CMD ;5*7 font
MOV A,#0CH ;Display ON/OFF control
CALL CMD ;Disp ON,Cursor OFF,Blink OFF
MOV A,#01H ;Clear display
CALL CMD
RET

;Command write subroutine

CMD: MOV P2,#0E8H


MOV R0,#PORT_A
MOVX @R0,A
MOV A,#0FBH
MOV R0,#PORT_B
MOVX @R0,A
MOV A,#0F8H
MOV R0,#PORT_B
MOVX @R0,A

MPMC Lab Manual 36 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.
MOV A,#0FCH
MOV R0,#PORT_B
MOVX @R0,A
MOV A,#0F8H
MOV R0,#PORT_B
MOVX @R0,A
MOV R1,#10H
CALL DELAY
RET

;Date write subroutine

DWR: MOV P2,#0E8H


MOV R0,#PORT_A
MOVX @R0,A
MOV A,#0FAH
MOV R0,#PORT_B
MOVX @R0,A
MOV A,#0F9H
MOV R0,#PORT_B
MOVX @R0,A
MOV A,#0FDH
MOV R0,#PORT_B
MOVX @R0,A
MOV A,#0F9H
MOV R0,#PORT_B
MOVX @R0,A
MOV R1,#10H
CALL DELAY
RET
;delay subroutine

DELAY: MOV R2,#02H


DLY:DJNZ R2,DLY
DJNZ R1,DLY
RET

Results:
Press any key in keyboard that key is display on LCD Display

MPMC Lab Manual 37 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.
Experiment 16
Interfacing Matrix/Keyboard to 8051.
Aim: Write an ALP to interface Keyboard (4X4 Matrix) to 8051 microcontroller.

Apparatus:

C.P.U.
Keyboard
Keil software

PROGRAM:
OUTPUT EQU 03FAH
PUTBYTE EQU 139EH
SEG EQU 0E8H

ORG 8000H
MOV DPTR,#MESG
LCALL OUTPUT
BACK: LCALL DILIT
LCALL KSCAN
MOV A,R4
MOV 71H,A
LCALL PUTBYTE
SJMP BACK
KSCAN: MOV P2,#SEG
MOV R0,#03H
MOV A,#92H
MOVX @R0,A

KSCN: MOV R3,02H


MOV R4,#10H
MOV R1,#04H

NXTGRP: MOV A,R1


MOV R0,#02H
MOVX @R0,A
RRC A
MOV R1,A
MOV R0,#00H
MOVX A,@R0
JNZ NXTKEY
MOV A,R4
SUBB A,#08H
MOV R4,A
DEC R3
MOV A,R3

MPMC Lab Manual 38 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.
DJNZ R3,NXTGRP
SJMP KSCN ;jump to KSCN

NXTKEY: RRC A ;Rotate Acc right through Carry flag


JNC NEXT ;Jump if no carry to next
RET

NEXT: XCH A,R4 ;Exchange Acc with R4 data


ADD A,#01H ; add 01h to acc
XCH A,R4 ;exchange acc with r4 data
SJMP NXTKEY ;jump to NXTKEY

DILIT: MOV DPTR,#BACKSP


LCALL OUTPUT
RET

MESG: DB 'KEY PRESSED= ',00H


BACKSP: DB 08H,08H,00H

DLY: MOV R6,#ffH


DLY1: MOV R7,#FFH
DJNZ R7,$
DJNZ R6,DLY1
RET

LCDCMD: MOV B,A


CALL DLY
PUSH B
PUSH DPH
PUSH DPL
MOV DPTR,#0E100H
MOV A,#0DH
MOVX @DPTR,A
MOV R6,#7FH
S0: DJNZ R6,S0
MOV DPTR,#0E103H
MOV A,#04H
MOVX @DPTR,A
MOV DPTR,#0E101H
MOV A,B
MOVX @DPTR,A
INC DPTR
INC DPTR
MOV A,#00
MOVX @DPTR,A
MOV R6,#7FH

MPMC Lab Manual 39 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.
CMRCET DEPARTMENT OF E.C.E.
S1: DJNZ R6,S1
POP DPL
POP DPH
POP B
RET

Results:
Input:
Press key: 01
Output :01

If press any key in keyboard kit it shows various values


Like: press
1=01
2=02
3=03
4=04
5=05
6=06
7=07
8=08
9=09
0=0
‘=’=a
‘+’=b
‘-‘=c
*=d
Mc=e
Mr=f

MPMC Lab Manual 40 III – II, ECE,Year: 2014-15


Asst. Prof., GNIT, ECE., 2013-2014.

You might also like