You are on page 1of 30

8255 IC

8051 has limited number of I/O ports. One solution is to add parallel interface chip(s).
8255 is a Programmable Peripheral Interface PPI. Add it to 8051 to expand number of
parallel ports. 8051 I/O port does not have handshaking capability. 8255 can add
handshaking capability to 8051.

Programmable Peripheral Interface (PPI)


o Has 3 8_bit ports A, B and C
o Port C can be used as two 4 bit ports CL and Ch
o Two address lines A0, A1 and a Chip select CS
o 8255 can be configured by writing a control-word in CR register

PIN configuration

D0 - D7 These are the data input/output lines for


the device. All information read from and written
to the 8255 occurs via these 8 data lines. CS (Chip
Select Input). If this line is a logical 0, the
microprocessor can read and write to the 8255.
RD (Read Input) Whenever this input line is a
logical 0 and the RD input is a logical 0, the 8255
data outputs are enabled onto the system data bus.
WR (Write Input) Whenever this input line is a
logical 0 and the CS input is a logical 0, data is
written to the 8255 from the system data bus
A0 - A1 (Address Inputs) The logical combination
of these two input lines determines which internal
register of the 8255 data is written to or read from.
RESET The 8255 is placed into its reset state if
this input line is a logical 1. All peripheral ports
are set to the input mode.
PA0 - PA7, PB0 - PB7, PC0 - PC7 These signal
lines are used as 8-bit I/O ports. They can be
connected to peripheral devices. The 8255 has
three 8 bit I/O ports and each one can be
connected to the physical lines of an external
device. These lines are labeled PA0-PA7, PB0-
PB7, and PC0-PC7. The groups of the signals are
divided into three different I/O ports labeled port A (PA), port B (PB), and port C (PC).

NagRaz 1
8255 Operating Modes

Mode 0 : Simple I/O


Any of A, B, CL and CH can be
programmed as input or output

Mode 1: I/O with Handshake


A and B can be used for I/O
C provides the handshake signals

Mode 2: Bi-directional with handshake


A is bi-directional with C providing
handshake signals
B is simple I/O (mode-0) or handshake I/O (mode-1)

BSR (Bit Set Reset) Mode


Only C is available for bit mode access
Allows single bit manipulation for control applications

Mode 0
Provides simple input and output operations for each of the three ports. No
“handshaking” is required, data is simply written to or read from a specified port. Two 8-
bit ports and two 4-bit ports. Any port can be input or output. Outputs are latched.
Inputs are not latched

NagRaz 2
NagRaz 3
8051 Microcontroller Architecture

NagRaz 4
Instructions by opcode

0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f
0x00 NOP AJMP LJMP RR INC INC INC INC INC INC INC INC INC INC INC INC
0x10 JBC ACALL LCALL RRC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC
0x20 JB AJMP RET RL ADD ADD ADD ADD ADD ADD ADD ADD ADD ADD ADD ADD
0x30 JNB ACALL RETI RLC ADDC ADDC ADDC ADDC ADDC ADDC ADDC ADDC ADDC ADDC ADDC ADDC
0x40 JC AJMP ORL ORL ORL ORL ORL ORL ORL ORL ORL ORL ORL ORL ORL ORL
0x50 JNC ACALL ANL ANL ANL ANL ANL ANL ANL ANL ANL ANL ANL ANL ANL ANL
0x60 JZ AJMP XRL XRL XRL XRL XRL XRL XRL XRL XRL XRL XRL XRL XRL XRL
0x70 JNZ ACALL ORL JMP MOV MOV MOV MOV MOV MOV MOV MOV MOV MOV MOV MOV
0x80 SJMP AJMP ANL MOVC DIV MOV MOV MOV MOV MOV MOV MOV MOV MOV MOV MOV
0x90 MOV ACALL MOV MOVC SUBB SUBB SUBB SUBB SUBB SUBB SUBB SUBB SUBB SUBB SUBB SUBB
0xa0 ORL AJMP MOV INC MUL ? MOV MOV MOV MOV MOV MOV MOV MOV MOV MOV
0xb0 ANL ACALL CPL CPL CJNE CJNE CJNE CJNE CJNE CJNE CJNE CJNE CJNE CJNE CJNE CJNE
0xc0 PUSH AJMP CLR CLR SWAP XCH XCH XCH XCH XCH XCH XCH XCH XCH XCH XCH
0xd0 POP ACALL SETB SETB DA DJNZ XCHD XCHD DJNZ DJNZ DJNZ DJNZ DJNZ DJNZ DJNZ DJNZ
0xe0 MOVX AJMP MOVX MOVX CLR MOV MOV MOV MOV MOV MOV MOV MOV MOV MOV MOV
0xf0 MOVX ACALL MOVX MOVX CPL MOV MOV MOV MOV MOV MOV MOV MOV MOV MOV MOV

NagRaz 5
Alphabetical List of Instructions
ACALL - Absolute Call MOV - Move Memory

ADD, ADDC - Add Accumulator (With Carry) MOVC - Move Code Memory

AJMP - Absolute Jump MOVX - Move Extended Memory

ANL - Bitwise AND MUL - Multiply Accumulator by B

CJNE - Compare and Jump if Not Equal NOP - No Operation

CLR - Clear Register ORL - Bitwise OR

CPL - Complement Register POP - Pop Value From Stack

DA - Decimal Adjust PUSH - Push Value Onto Stack

DEC - Decrement Register RET - Return From Subroutine

DIV - Divide Accumulator by B RETI - Return From Interrupt

DJNZ - Decrement Register and Jump if Not Zero RL - Rotate Accumulator Left

INC - Increment Register RLC - Rotate Accumulator Left Through Carry

JB - Jump if Bit Set RR - Rotate Accumulator Right

JBC - Jump if Bit Set and Clear Bit RRC - Rotate Accumulator Right Through Carry

JC - Jump if Carry Set SETB - Set Bit

JMP - Jump to Address SJMP - Short Jump

JNB - Jump if Bit Not Set SUBB - Subtract From Accumulator With Borrow

JNC - Jump if Carry Not Set SWAP - Swap Accumulator Nibbles

JNZ - Jump if Accumulator Not Zero XCH - Exchange Bytes

JZ - Jump if Accumulator Zero XCHD - Exchange Digits

LCALL - Long Call XRL - Bitwise Exclusive OR

LJMP - Long Jump

NagRaz 6
Interfacing 8255 with 8051

P2.7(A15) A2
P2.6(A14) A1
P2.5(A13) A0

74138
3×8 decoder
8051 /CS

8255
ALE O0 A0
74373 O1 A1

P0.7-P0.0 D7-D0
O7
(AD7-AD0)
D7-D0
/RD /RD
/WR /WR

NagRaz 7
Program No: 01
Problem: Write a ALP to Display Characters on Multiplexed LED display.

NagRaz 8
Solution:
org 4100h
mov dptr,#0ff0fh
mov a,#80h
movx @dptr,a
mov r0,#0eeh
start: mov dptr,#look
mov r1,dpl
mov r2,dph
mov r3,#04h
cont: movx a,@dptr
mov dptr,#0ff0ch
movx @dptr,a
mov a,r0
rl a
mov r0,a
mov dptr,#0ff0dh
movx @dptr,a
lcall delay
inc r1
mov dpl,r1
mov dph,r2
djnz r3,cont
sjmp start
delay: mov r5,#01h
l3: mov r6,#0ffh
l2: djnz r6,l2
djnz r5,l3
ret
look: db 08h,00h,46h,40h

NagRaz 9
Program No: 02
Problem: Write ALP to generate Square wave using Oscilloscope

Solution:

org 4100
mov dptr,#0ff0fh
mov a,#80h
movx @dptr,a
mov a,#0ffh
return: mov dptr,#0ff0ch
movx @dptr,a
cpl a
mov r4,#0ffh
loop: djnz r4,loop
sjmp return

NagRaz 10
Program No: 03
Problem: Write ALP to Control Traffic at 4 road junction.

NagRaz 11
Solution:
org 4100h
mov a,#80h
mov dptr,#0ff0fh
movx @dptr,a
start: mov r4,#04h
mov dptr,#look
mov r0,dph
mov r1,dpl
go: movx a,@dptr
mov dptr,#0ff0ch
movx @dptr,a
inc r1
mov dph,r0
mov dpl,r1
movx a,@dptr
mov dptr,#0ff0dh
movx @dptr,a
inc r1
mov dph,r0
mov dpl,r1
movx a,@dptr
mov dptr,#0ff0eh
movx @dptr,a
acall delay1
inc r1
mov dph,r0
mov dpl,r1
movx a,@dptr
mov dptr,#0ff0ch
movx @dptr,a
inc r1
mov dph,r0
mov dpl,r1
movx a,@dptr
mov dptr,#0ff0dh
movx @dptr,a
inc r1
mov dph,r0
mov dpl,r1
movx a,@dptr
mov dptr,#0ff0eh
movx @dptr,a
inc r1
mov dph,r0
mov dpl,r1

NagRaz 12
acall delay2
djnz r4,go
ljmp start
delay2: mov r5,#6fh
l1: mov r6,#0ffh
l2: mov r7,#0ffh
l3: djnz r7,l3
djnz r6,l2
djnz r5,l1
ret
delay1: mov r5,#0afh
l4: mov r6,#0ffh
l5: mov r7,#0ffh
l6: djnz r7,l6
djnz r6,l5
djnz r5,l4
ret
look: db 90h,20h,10h
db 88h,20h,10h
db 04h,20h,12h
db 04h,20h,11h
db 84h,20h,40h
db 84h,20h,20h
db 84h,80h,10h
db 84h,40h,10h

NagRaz 13
Program No: 04
Problem: Write ALP to Display String Using LCD Display.

LCD pin descriptions:

The LCD has 14 pins. The function of each pin is given in table.

Pin Symbol I/O Description


1 GND - Ground
2 Vcc - +5V power supply
3 VEE - Contrast control
4 RS I command/data register selection
5 R/W I write/read selection
6 E I/O Enable
7 DB0 I/O The 8-bit data bus
8 DB1 I/O The 8-bit data bus
9 DB2 I/O The 8-bit data bus
10 DB3 I/O The 8-bit data bus
11 DB4 I/O The 8-bit data bus
12 DB5 I/O The 8-bit data bus
13 DB6 I/O The 8-bit data bus
14 DB7 I/O The 8-bit data bus

Vcc, Vss, and VEE

While Vcc and Vss provide +5V and ground, respectively, VEE is used for controlling
LCD contrast.

RS - register select:

There are two very important registers inside the LCD. The RS pin is used for their
selection as follows. If RS = 0, the instruction command code register is selected, allowing the
user to send a command such as clear display, cursor at home, etc. If RS = 1 the data register is
selected, allowing the user to send data to be displayed on the LCD.

R/W - read/write:

R/W input allows the user to write information to the LCD or read information from it.
R/W = 1 when reading; R/W =0 when writing.

E - enable:

The enable pin is used by the LCD to latch information presented to its data pins. When
data is supplied to data pins, a high to low pulse must be applied to this pin in order for the LCD
to latch in the data present at the data pins. This pulse must be a minimum of 450 ns wide.

D0 – D7:

The 8 bit data pins, D0 – D7, are used to send information to the LCD or read the contents
of the LCD’s internal registers.

NagRaz 14
To display letters and numbers, we send ASCII codes for the letters A – Z, a – z, and
numbers 0 – 9 to these pins while making RS = 1.

There are also instructions command codes that can be sent to the LCD to clear the
display or force the cursor to the home position or blink the cursor. Table below lists the
instruction command codes.

Code (hex) Command to LCD Instruction Register


1 Clear display screen
2 Return home
4 Shift cursor to left
5 Shift display right
6 Shift cursor to right
7 Shift display left
8 Display off, Cursor off
A Display off, Cursor on
C Display on, cursor off
E Display on, cursor blinking
F Display on, cursor blinking
10 Shift cursor position to left
14 Shift cursor position to right
18 Shift the entire display to the left
1C Shift the entire display to the right
80 Force cursor to beginning of 1st line
C0 Force cursor to beginning of 2nd line
38 2 lines and 5x7 matrix

We also use RS = 0 to check the busy flag bit to see if the LCD is ready to receive
information. The busy flag is D7 and can be read when R/W =1 and RS = 0, as follows: if R/W
=1, RS =0. When D7 = 1(busy flag = 1), the LCD busy taking care of internal operations and will
not accept any new information. When D7 = 0, the LCD is ready to receive new information.
Note: It is recommended to check the busy flag before writing any data to the LCD.

NagRaz 15
We can write program for LCD in two ways.

1. Sending commands and data to LCD’s with a time delay.


2. Sending commands and data to LCD’s with checking busy flag.

1. Program to display "ELECTROFRIENDS" in LCD without checking busy flag.

MOV A, #38H ; initialization LCD 2lines, 5x7 matrix.


ACALL COMMAND ; call command subroutine.
ACALL DELAY ; call delay subroutine.
MOV A,#0EH ; display on, cursor on
ACALL COMMAND
ACALL DELAY
MOV A,#01H ; Clear LCD
ACALL COMMAND
NagRaz 16
ACALL DELAY
MOV A,#06H ; shift cursor right
ACALL COMMAND
ACALL DELAY
MOV A,#80H ; cursor at beginning of 1st line
ACALL COMMAND
ACALL DELAY
MOV A,#'E' ; display letter E
ACALL DATA
ACALL DELAY
MOV A,#'L' ; display letter L
ACALL DATA
ACALL DELAY
MOV A,#'E' ; display letter E
ACALL DATA
ACALL DELAY
MOV A,#'C' ; display letter C
ACALL DATA
ACALL DELAY
MOV A,#'T' ; display letter T
ACALL DATA
ACALL DELAY
MOV A,#'R' ; display letter R
ACALL DATA
ACALL DELAY
MOV A,#'O' ; display letter O
ACALL DATA
ACALL DELAY
MOV A,#'F' ; display letter F
ACALL DATA
ACALL DELAY
MOV A,#'R' ; display letter R
ACALL DATA
ACALL DELAY
MOV A,#'I' ; display letter I
ACALL DATA
ACALL DELAY
MOV A,#'E' ; display letter E
ACALL DATA
ACALL DELAY
MOV A,#'N' ; display letter N
ACALL DATA
ACALL DELAY
MOV A,#'D' ; display letter D
ACALL DATA
ACALL DELAY
MOV A,#'S' ; display letter S
ACALL DATA
ACALL DELAY

HERE: JMP HERE

COMMAND: MOV P1,A ; Send command to LCD


CLR P3.4 ; RS=0 for command
NagRaz 17
CLR P3.5 ; R/W=0 for write
SETB P3.3 ; E=1 for high pulse
CLR P3.3 ; E=0 for H-to-L pulse
RET

DATA: MOV P1, A ; Write data to LCD


SETB P3.4 ; RS=1 for data
CLR P3.5 ; R/W=0 for write
SETB P3.3 ; E=1 for high pulse
CLR P3.3 ; E=0 for H-to-L pulse
RET

DELAY: MOV R2, #50


D1: MOV R3, #0FFH
D2: DJNZ R3, D2
DJNZ R2, D1
RET

2. Program to display "ELECTROFRIENDS" in LCD with checking busy flag.

MOV A, #38H ; initialization LCD 2lines, 5x7 matrix.


ACALL COMMAND ; call command subroutine.
MOV A,#0EH ; display on, cursor on
ACALL COMMAND
MOV A,#01H ; Clear LCD
ACALL COMMAND
MOV A,#06H ; shift cursor right
ACALL COMMAND
MOV A,#80H ; cursor at beginning of 1st line
ACALL COMMAND
MOV A,#'E' ; display letter E
ACALL DATA
MOV A,#'L' ; display letter L
ACALL DATA
MOV A,#'E' ; display letter E
ACALL DATA
MOV A,#'C' ; display letter C
ACALL DATA
MOV A,#'T' ; display letter T
ACALL DATA
MOV A,#'R' ; display letter R
ACALL DATA
MOV A,#'O' ; display letter O
ACALL DATA
MOV A,#'F' ; display letter F
ACALL DATA
MOV A,#'R' ; display letter R
ACALL DATA
MOV A,#'I' ; display letter I
ACALL DATA
MOV A,#'E' ; display letter E
ACALL DATA
MOV A,#'N' ; display letter N

NagRaz 18
ACALL DATA
MOV A,#'D' ; display letter D
ACALL DATA
MOV A,#'S' ; display letter S
ACALL DATA

HERE: JMP HERE

COMMAND: CALL READY ; check whether LCD is ready


MOV P1,A ; Send command to LCD
CLR P3.4 ; RS=0 for command
CLR P3.5 ; R/W=0 for write
SETB P3.3 ; E=1 for high pulse
CLR P3.3 ; E=0 for H-to-L pulse
RET

DATA: CALL READY ; check whether LCD is ready


MOV P1,A ; Write data to LCD
SETB P3.4 ; RS=1 for data
CLR P3.5 ; R/W=0 for write
SETB P3.3 ; E=1 for high pulse
CLR P3.3 ; E=0 for H-to-L pulse
RET

READY: SETB P1.7 ; make P1.7 input port


CLR P3.4 ; RS=0
SETB P3.5 ; R/W=0 for read
UP: SETB P3.3 ; E=1 for high pulse
CLR P3.3 ; E=0 for H-to-L pulse
JB P1.7, UP ; stay until LCD is busy
RET

NagRaz 19
Solution: Blinking “GITAM” String

org 5000h
start: clr a
lcall bsychk
mov dptr,#0ff04h
mov a,#38h
movx @dptr,a
lcall bsychk
mov a,#01h
movx @dptr,a
lcall bsychk
mov a,#06h
movx @dptr,a
lcall bsychk
mov a,#0fh
movx @dptr,a
lcall bsychk
mov a,#80h
movx @dptr,a
mov dptr,#lookup
mov r2,#10h
lcall delay
more: lcall bsychk
mov a,#01h
mov p2,#0ffh
movx @r0,a
movx a,@dptr
mov p2,#0ffh
movx @r1,a
inc dptr
djnz r2,more
lcall delay
ljmp start
bsychk: mov r1,#04h
mov r0,#08h
mov p2,#0ffh
mov a,#02h
movx @r0,a
bsy: mov p2,#0ffh
movx a,@r1
anl a,#80h
jnz bsy
mov p2,#0ffh
mov a,#00h
movx @r0,a
ret
delay: mov r3,#0ffh
l2: mov r4,#0ffh
l1: djnz r4,l1
djnz r3,l2
ret
lookup: db
47h,49h,54h,41h,4dh,20h,55h,4eh,49h,56h,45h,52h,53h,49h,54h,59h

NagRaz 20
Program No: 05
Problem: Write ALP to rotate stepper motor.

Solution:

org 4100h

mov a,#80h
mov dptr,#0ff0fh
movx @dptr,a
start:
clock: mov r0,#03h
mov dptr,#look1
mov r1,dpl
mov r2,dph
acall run
djnz r0,clock
acall delay

anti: mov r0,#03h


mov dptr,#look2
mov r1,dpl
mov r2,dph
acall run
djnz r0,anti
acall delay
ljmp start

NagRaz 21
run: mov r3,#0ch
go: movx a,@dptr
mov dptr,#0ff0ch
movx @dptr,a

mov r4,#01h
l3: mov r5,#11h
l2: mov r6,#0ffh
l1: djnz r6,l1
djnz r5,l2
djnz r4,l3

inc r1
mov dpl,r1
mov dph,r2
djnz r3,go
ret

delay: mov r4,#03h


k3: mov r5,#0ffh
k2: mov r6,#0ffh
k1: djnz r6,k1
djnz r5,k2
djnz r4,k3
ret

look1: db 09h,05h,06h,0ah,09h,05h,06h,0ah,09h,05h,06h,0ah
look2: db 0ah,06h,05h,09h,0ah,06h,05h,09h,0ah,06h,05h,09h

NagRaz 22
Program No: 06
Problem: Write ALP to Print Characters using dot matrix printer.

Solution:

To print single character:


org 5000h
mov a,#05h
mov dptr,#0ffd0h
movx @dptr,a
mov a,#58h
mov dptr,#0ffc8h
movx @dptr,a
mov a,#01h
mov dptr,#0ffd0h
movx @dptr,a
mov a,#0ah
mov dptr,#0ffc8h
movx @dptr,a

To print Multiple character using delay:

org 5000h
mov r0,#0eh
mov dptr,#look
rep: mov r1,dpl
mov r2,dph
mov a,#05h
mov dptr,#0ffd0h
movx @dptr,a
mov dpl,r1
mov dph,r2
movx a,@dptr
mov dptr,#0ffc8h
movx @dptr,a
mov a,#01h
mov dptr,#0ffd0h
movx @dptr,a
mov a,#0ah
mov dptr,#0ffc8h
movx @dptr,a
mov a,#01h
mov dptr,#0ffd0h
movx @dptr,a
mov a,#05h
mov dptr,#0ffd0h
movx @dptr,a
mov dpl,r1
mov dph,r2
inc dptr
mov r4,0fh
k1: djnz r4,k1
djnz r0,rep
look: db 47h,49h,54h,41h,4dh,20h,45h,53h,20h,4ch,41h,42h,0dh,0ah

NagRaz 23
Program No: 07
Problem: Write ALP to interfacing to HEX keyboard.
Solution:
org 4100h
keystart: mov dptr,#0ff0fh
mov a,#82h
movx @dptr,a
start: mov a,#00h
mov dptr,#0ff0ch
movx @dptr,a
mov dptr,#0ff0dh
movx a,@dptr
anl a,#0fh
cjne a,#0fh,cont
ljmp start
cont: lcall getdat
ljmp start
getdat: mov r2,#51h
mov r3,#00h
mov r4,#52h
mov r5,#00h
mov a,#0eh
lcall find1
mov a,#0dh
lcall find1
mov a,#0bh
lcall find1
mov a,#07h
lcall find1
ret
find1: mov dptr,#0ff0ch
movx @dptr,a
mov dptr,#0ff0dh
movx a,@dptr
anl a,#0fh
mov r6,a
mov r7,#04h
ffn2: mov dph,r4
mov dpl,r5
movx a,@dptr
mov dpl,r6
cjne a,dpl,ffn3
lcall storedat
ret
ffn3: inc r3
inc r5
djnz r7,ffn2
mov r4,#52h
mov r5,#00h
ret

NagRaz 24
storedat: lcall bsychk
mov dptr,#0ff04h
mov a,#38h
movx @dptr,a
lcall bsychk
mov a,#01h
movx @dptr,a
lcall bsychk
mov a,#06h
movx @dptr,a
lcall bsychk
mov a,#0fh
movx @dptr,a
lcall bsychk
mov a,#80h
movx @dptr,a
mov dph,r2
mov dpl,r3
lcall bsychk
mov a,#01h
mov p2,#0ffh
movx @r0,a
movx a,@dptr
mov p2,#0ffh
movx @r1,a
ret

bsychk: mov r1,#04h


mov r0,#08h
mov p2,#0ffh
mov a,#02h
movx @r0,a

bsy: mov p2,#0ffh


movx a,@r1
anl a,#80h
jnz bsy
mov p2,#0ffh
mov a,#00h
movx @r0,a
ret

org 5100h
db 30h,31h,32h,33h,34h,35h,36h,37h,38h,39h,41h,42h,43h,44h,45h,46h
org 5200h
db 0eh,0dh,0bh,07h

NagRaz 25
8051 Kit Programs

Program No: 01
Problem: Write ALP to Add two 16 bit numbers.
Solution:
org 4100h
clr c
mov a,#34h
addc a,#78h
mov dptr,#4200h
movx @dptr,a
inc dptr
mov a,#12h
addc a,#56h
movx @dptr,a
hlt: sjmp hlt

Program No: 02
Problem: Write ALP to add two multi byte numbers.
Solution:
org 4100h
mov r0,#45h
mov r1,#46h
mov r2,#47h
mov dpl,#00h
clr c
next: mov a,r0
mov dph, a
movx a,@dptr
mov r3,a
mov a,r1
mov dph, a
movx a,@dptr
addc a,r3
mov r4,a
mov a,r2
mov dph, a
mov a,r4
movx @dptr,a
inc dpl
djnz r5,next
jnc hlt
mov a,#01h
movx @dptr,a
hlt: sjmp hlt

NagRaz 26
Program No: 03
Problem: Write ALP to Subtract two 8 bit numbers.
Solution:
org 4100h
clr c
mov a,#59h
sub a,#50h
mov dptr,#4200h
movx @dptr,a
hlt: sjmp hlt

Program No: 04
Problem: Write ALP to multiply two 8 bit numbers with out using MUL instruction.
Solution:
org 4100h
mov r1,#04h
mov r2,#06h
mov r3,#00h
mov a,#00h
next: add a,r1
jnc pass
inc r3
pass: djnz r2,next
mov dptr,#4200h
movx @dptr,a
inc dptr
mov a,r3
movx @dptr,a
hlt: sjmp hlt

Program No: 05
Problem: Write ALP to divide two 8 bit numbers with out using DIV instruction.
Solution:
org 4100h
mov r0,#08h
mov r1,#04h
mov r2,#00h
mov a,r0
loop: cjne a,01h,loop1
inc r2
mov r3,#00h
jmp loop2
loop1: jc loop3
inc r2
subb a,r1
jmp loop
loop3: mov r3,a
loop2: sjmp loop2

NagRaz 27
Program No: 06
Problem: Write ALP to Split 8 bit numbers in to two Nibbles.
Solution:
org 4100h
mov dptr,#4500h
movx a,@dptr
mov b,a
anl a,#0fh
inc dptr
movx @dptr,a
mov a,b
swap a
anl a,#0fh
inc dptr
movx @dptr,a
hlt: sjmp hlt

Program No: 07
Problem: Write ALP to convert Packed BCD number in to two ASCII numbers.
Solution:
org 4100h
mov dptr,#4500h
movx a,@dptr
mov b,a
anl a,#0fh
add a,#30h
inc dptr
movx @dptr,a
mov a,b
swap a
anl a,#0fh
add a,#30h
inc dptr
movx @dptr,a
hlt: sjmp hlt

Program No: 08
Problem: Write ALP to convert BCD number in to HEX number.
Solution:
org 4100h
mov dptr,#4200
movx a,@dptr
mov b,#0ah
mul ab
mov b,a
inc dptr
movx a,@dptr
add a,b
inc dptr
movx @dptr,a
hlt: sjmp hlt

NagRaz 28
Program No: 09
Problem: Write ALP to convert HEX number into Decimal(BCD) number.
Solution:
org 4100h
mov dptr,#4200
movx a,@dptr
mov b,#64h
div ab
mov dptr,#4201
movx @dptr,a
mov a,b
mov b,#0ah
div ab
inc dptr
movx @dptr,a
inc dptr
mov a,b
movx @dptr,a
hlt: sjmp hlt

Program No: 10
Problem: Write ALP to sum of an array of HEX numbers.
Solution:
org 4100h
mov dptr,#4200h
movx a,@dptr
mov r0,a
mov b,#00h
mov r1,#00h
sum: clr c
inc dptr
movx a,@dptr
add a,b
mov b,a
jnc pass
inc r1
pass: djnz r0,sum
mov dptr,#4500h
mov a,r1
movx @dptr,a
inc dptr
mov a,b
movx @dptr,a
hlt: sjmp hlt

Program No: 11
Problem: Write ALP to sum of an array of BCD numbers.
Solution:
org 4100h
mov dptr,#4200h
movx a,@dptr
mov r0,a
mov b,#00h
mov r1,#00h
NagRaz 29
sum: clr c
inc dptr
movx a,@dptr
add a,b
da a
mov b,a
jnc pass
inc r1
pass: djnz r0,sum
mov dptr,#4500h
mov a,r1
movx @dptr,a
inc dptr
mov a,b
movx @dptr,a
hlt: sjmp hlt

Program No: 12
Problem: Write ALP to Sort an array of numbers.
Solution: org 4200h
mov r3,#04h
mov r4,#04h
mov dptr,#4200h
ptri: mov r5,dpl
mov r6,dph
movx a,@dptr
mov b,a
ptrj: inc dptr
movx a,@dptr
mov r0,a
clr c
subb a,b
check: jnc chknxt
exch: push dpl
push dph
mov dpl,r5
mov dph,r6
mov a,r0
movx @dptr,a
pop dph
pop dpl
mov a,b
movx @dptr,a
mov b,r0
chknxt: djnz r3,ptrj
dec r4
mov a,r4
mov r3,a
inc r4
mov dpl,r5
mov dph,r6
inc dptr
djnz r4,ptri
hlt: sjmp hlt

NagRaz 30

You might also like