Você está na página 1de 88

EXP NO: 1

D A T
:

AIM:

8086 PROGRAMMING
ADDITION & SUBTRACTION

To write an Assembly Language Program (ALP) for performing the Addition and
subtraction operation of 16-bit numbers.
APPARATUS REQUIRED:
SL.N
ITEM
O
1. Microprocessor kit
2. Power Supply

SPECIFICATION
8086 kit
+5 V dc

QUANTITY
1
1

ALGORITHM:
16-bit addition
i.
Initialize the MSBs of sum to 0
ii) Get the first number.
iii) Add the second number to the first number.
iv) If there is any carry, increment MSBs of sum by 1.
v.
Store LSBs of sum.
vi) Store MSBs of sum.
16-bit subtraction
Initialize the MSBs of difference to 0
ii) Get the first number
iii) Subtract the second number from the first number.
iv) If there is any borrow, increment MSBs of difference by 1.
v.
Store LSBs of difference
vi) Store MSBs of difference.
i.

FLOWCHART:

ADDITION
PROGRAM

COMMENTS

MOV CX, 0000H

Initialize counter CX

MOV AX,[1200]

Get the first data in AX reg

MOV BX, [1202]

Get the second data in BX reg

ADD AX,BX

Add the contents of both the regs AX &

JNC L1

Check for carry

INC CX
L1 : MOV [1206],CX

If carry exists, increment the CX


Store the carry

MOV [1204], AX

Store the sum

HLT

Stop the program

SUBTRACTION
PROGRAM

COMMENTS

MOV CX, 0000H

Initialize counter CX

MOV AX,[1200]

Get the first data in AX reg

MOV BX, [1202]

Get the second data in BX reg

SUB AX,BX

Subtract the contents of BX from AX

JNC L1

Check for borrow

INC CX
L1 : MOV [1206],CX

If borrow exists, increment the CX


Store the borrow

MOV [1204], AX

Store the difference

HLT

Stop the program

3
3

OUTPUT:
ADDITION

MEMORY
DATA

SUBTRACTION

MEMORY

DATA

RESULT:

Thus addition & subtraction of two byte numbers are performed and the result is
stored.

EXPT NO: 2

MULTIPLICATION & DIVISION

DATE:
AIM:

To write an Assembly Language Program (ALP) for performing the


multiplication and division operation of 16-bit numbers .
APPARATUS REQUIRED:
SL.N
ITEM
SPECIFICATION
O
1.
Microprocessor kit
8086
2.
Power Supply
+5 V dc
ALGORITHM:
Multiplication of 16-bit numbers:
i. Get the multiplier.

ii) Get the multiplicand


iii) Initialize the product to 0.
iv) Product= product + multiplicand
v. Decrement the multiplier by 1
vi) If multiplicand is not equal to 0,repeat from step (d) otherwise store the
product.
Division of 16-bit numbers.
i. Get the dividend

ii) Get the divisor


iii) Initialize the quotient to 0.
iv) Dividend = dividend divisor
v. If the divisor is greater, store the quotient. Go to step g.
vi) If dividend is greater, quotient = quotient + 1. Repeat from step (d)
vii)
Store the dividend value as remainder.

QUANTITY
1
1

FLOWCHART:

MULTIPLICATION
PROGRAM
MOV AX,[1200]
MOV BX, [1202]

COMMENTS
Get the first data
Get the second data

MUL BX

Multiply both

MOV [1206],AX

Store the lower order product

MOV AX,DX

Copy the higher order product to AX

MOV [1208],AX

Store the higher order product

HLT

Stop the program

DIVISION
PROGRAM
MOV AX,[1200]
MOV DX, [1202]

COMMENTS
Get the first data lower nibble
Get the first data higher nibble

MOV BX, [1204]

Get the second data

DIV BX

Divide the dividend by divisor

MOV [1206],AX

Store the lower order product

MOV AX,DX

Copy the higher order product to AX

MOV [1208],AX

Store the higher order product

HLT

Stop the program

7
7

OUTPUT:
MULTIPLICATION

MEMORY
DATA

DIVISON

MEMORY

DATA

RESULT:
Thus multiplication & division of two byte numbers are performed and the result is
stored.
8

EXPT NO: 3

ASCENDING & DESCENDING

DATE:
AIM:

To write an Assembly Language Program (ALP) to sort a given array in


Ascending and descending order.
APPARATUS REQUIRED:
SL.N
ITEM
O
1.
Microprocessor kit
2.
Power Supply

SPECIFICATION

QUANTITY

8086
+5 V dc

1
1

ALGORITHM:
Sorting in ascending order:
01 and C 2.
i. Load the array count in two registers C ii) Get the first two numbers.
iii) Compare the numbers and exchange if necessary so that the two numbers are
in ascending order.
iv) Decrement C
2.
v. Get the third number from the array and repeat the process until C 2 is 0.
vi) Decrement C1 and repeat the process until C 1 is 0.
Sorting in descending order:
01 and C 2.
i. Load the array count in two registers C ii) Get the first two numbers.
iii) Compare the numbers and exchange if necessary so that the two numbers are
in descending order.
iv) Decrement C2.
v. Get the third number from the array and repeat the process until C 2 is 0.
01 and repeat the process until C 1 is 0.
vi) Decrement C
9

FLOWCHART

10

ASCENDING
MOV SI,1200H
MOV CL,[SI]
L4 : MOV SI,1200H
MOV DL,[SI]
INC SI
MOV AL,[SI]
L3 : INC SI
MOV BL,[SI]
CMP AL,BL
JNB L1
DEC SI
MOV [SI],AL
MOV AL,BL
JMP L2
L1 : DEC SI
MOV [SI],BL
L2 : INC SI
DEC DL
JNZ L3
MOV [SI],AL
DEC CL
JNZ L4
HLT
DESCENDING
PROGRAM

Initialize memory location for array size


Number of comparisons in CL
Initialize memory location for array size
Get the count in DL
Go to next memory location
Get the first data in AL
Go to next memory location
Get the second data in BL
Compare two datas
If AL < BL go to L1
Else, Decrement the memory location
Store the smallest data
Get the next data AL
Jump to L2
Decrement the memory location
Store the greatest data in memory location
Go to next memory location
Decrement the count
Jump to L3, if the count is not reached zero
Store data in memory location
Decrement the count
Jump to L4, if the count is not reached zero
Stop
COMMENTS

MOV SI,1200H
MOV CL,[SI]
L4 : MOV SI,1200H
MOV DL,[SI]
INC SI
MOV AL,[SI]
L3 : INC SI
MOV BL,[SI]
CMP AL,BL

Initialize memory location for array size


Number of comparisons in CL
Initialize memory location for array size
Get the count in DL
Go to next memory location
Get the first data in AL
Go to next memory location
Get the second data in BL
Compare two datas
11

JB L1
DEC SI

If AL > BL go to L1
Else, Decrement the memory location

MOV [SI],AL
MOV AL,BL
JMP L2
L1 : DEC SI
MOV [SI],BL
L2 : INC SI
DEC DL
JNZ L3
MOV [SI],AL
DEC CL
JNZ L4
HLT

Store the largest data


Get the next data AL
Jump to L2
Decrement the memory location
Store the smallest data in memory location
Go to next memory location
Decrement the count
Jump to L3, if the count is not reached zero
Store data in memory location
Decrement the count
Jump to L4, if the count is not reached zero
Stop
ASCENDING

MEMORY
DATA

DESCENDING

MEMORY

DATA

RESULT:
Thus given array of numbers are sorted in ascending & descending order
12

EX NO:4
AIM:

To write an Assembly Language Program (ALP) to find the largest and


smallest number in a given array.
APPARATUS REQUIRED:
SL.N
ITEM
O
1.
Microprocessor kit
2.
Power Supply

SPECIFICATION
8086
+5 V dc

QUANTITY
1
1

ALGORITHM:
(i) Finding largest number:
a. Load the array count in a register C
c. Compare the numbers and exchange if the number is small.
d. Get the third number from the array and repeat the process until C
(ii) Finding smallest number:
e. Load the array count in a register C1.
f. Get the first two numbers.
h. Get the third number from the array and repeat the process until C1 is 0.

13

b
g. C

om
par
e
the

FLOWCHART:

14

LARGEST
PROGRAM
MOV SI,1200H
MOV CL,[SI]
INC SI
MOV AL,[SI]
DEC CL
L2 : INC SI
CMP AL,[SI]
JNB L1
MOV AL,[SI]
L1 : DEC CL
JNZ L2
MOV DI,1300H
MOV [DI],AL
HLT
SMALLEST
PROGRAM

COMMENTS
Initialize array size
Initialize the count
Go to next memory location
Move the first data in AL
Reduce the count
Move the SI pointer to next data
Compare two datas
If AL > [SI] then go to L1 ( no swap)
Else move the large number to AL
Decrement the count
If count is not zero go to L2
Initialize DI with 1300H
Else store the biggest number in 1300 location
Stop
COMMENTS

MOV SI,1200H
MOV CL,[SI]
INC SI
MOV AL,[SI]
DEC CL
L2 : INC SI
CMP AL,[SI]
JB L1
MOV AL,[SI]
L1 : DEC CL
JNZ L2
MOV DI,1300H
MOV [DI],AL
HLT

Initialize array size


Initialize the count
Go to next memory location
Move the first data in AL
Reduce the count
Move the SI pointer to next data
Compare two datas
If AL < [SI] then go to L1 ( no swap)
Else move the large number to AL
Decrement the count
If count is not zero go to L2
Initialize DI with 1300H
Else store the biggest number in 1300 location
Stop

15

1
LARGEST

MEMORY
DATA

SMALLEST

MEMORY

DATA

RESULT:
Thus largest and smallest number is found in a given array.

16

8086 PROGRAMMING

EXPT NO: 5 DATE:

APPARATUS REQUIRED:
SL.N
ITEM
O
1.
Microprocessor kit
2.
Power Supply

SPECIFICATION
8086
+5 V dc

ALGORITHM:

Initialize the data segment .(DS)


Initialize the extra data segment .(ES)
Initialize the start of string in the DS. (SI)
Initialize the start of string in the ES. (DI)
Move the length of the string(FF) in CX
register.
f.
Move the byte from DS TO ES, till
CX=0.
a.
b.
c.
d.
e.

17

QUANTITY
1
1

FLOWCHART:

18

COPYING A STRING
PROGRAM
MOV SI,1200H

Initialize starting address

MOV DI,1300H

Initialize destination address

MOV CX,0006H

Initialize array size

CLD

Clear direction flag

REP MOVSB

Copy the contents of source into destination until


count reaches zero
Stop

HLT

COMMENTS

INPUT
MEMORY
DATA

OU
TP
UT

MEMORY

DATA

RESULT:

Thus a string of a particular length is moved from source segment to


destination segment.
19

EXPT NO: 6
SEARCHING A STRING
DATE:
AIM:

To scan for a given byte in the string and find the relative address of the byte
from the starting location of the string.
ALGORITHM:

Initialize the extra segment .(ES)


Initialize the start of string in the ES. (DI)
Move the number of elements in the string in CX
register.
d.
Move the byte to be searched in the AL register.
e.
Scan for the byte in ES. If the byte is found ZF=0, move the
address pointed by ES:DI
to BX.
a.
b.
c.

19

20

FLOWCHART

21

MOV DI,1300H

Initialize destination address

MOV SI, 1400H

Initialize starting address

MOV CX, 0006H

Initialize array size

CLD

Clear direction flag

MOV AL, 08H

Store the string to be searched

REPNE SCASB

Scan until the string is found

DEC DI

Decrement the destination address

MOV BL,[DI]

Store the contents into BL reg

MOV [SI],BL

Store content of BL in source address

HLT

Stop

OUTPUT:
INPUT

MEMORY
OUT
PUT

DATA

MEMORY LOCATION

DATA

RESULT:
Thus a given byte or word in a string of a particular length in the extra
segment(destination) is found .
EXNO: 7

22
8086 PROGRAMMING FIND AND REPLACE

DATE:
AIM:

To find a character in the string and replace it with another character.


ALGORITHM:

a. Initialize the extra segment .(E S)


b. Initialize the start of string in the ES. (DI)
c. Move the number of elements in the string in CX

register.
d. Move the byte to be searched in the AL register.
e. Store the ASCII code of the character that has to replace the scanned
byte in BL register.
f. Scan for the byte in ES. If the byte is not found, ZF?1 and repeat
scanning.
g. If the byte is found, ZF=1.Move the content of BL register to
ES:DI.

21

23

FLOWCHART:

24

FIND AND REPLACE A CHARACTER IN THE STRING


PROGRAM
MOV DI,1300H
MOV SI,1400H
MOV CX, 0006H

COMMENTS
Initialize destination address
Initialize starting address
Initialize array size

CLD

Clear direction flag

MOV AL, 08H

Store the string to be searched

MOV BH,30H

Store the string to be replaced

REPNE SCASB

Scan until the string is found

DEC DI

Decrement the destination address

MOV BL,[DI]

Store the contents into BL reg

MOV [SI],BL

Store content of BL in source address

MOV [DI],BH

Replace the string

HLT

Stop
INPUT

MEMORY
DATA

DATA
OU
TP
UT

RESULT:

MEMORY

Thus a given byte or word in a string of a particular length in the extra


segment(destination)is found and is replaced with another character.
EXNO: 8
DATE:
AIM:

25
8086 INTERFACING
INTERFACING ANALOG TO DIGITAL CONVERTER

To write an assembly language program to convert an analog signal into a


digital signal using an ADC interfacing.
APPARATUS REQUIRED:
SL.NO

1.
2.
3.

ITEM SPECIFICATION
Microprocessor kit
Power Supply
ADC Interface board

QUANTITY
8086
+5 V dc,+12 V dc
-

1
1
1

THEORY:

An ADC usually has two additional control lines: the SOC input to tell the
ADC when to start the conversion and the EOC output to announce when the
conversion is complete. The following program initiates the conversion
process, checks the EOC pin of ADC 0809 as to whether the conversion is over
and then inputs the data to the processor. It also instructs the processor to store
the converted digital data at RAM location.
ALGORITHM:

(i)

Select the channel and latch the


address.
(ii)
Send the start conversion pulse.
(iii) Read EOC signal.
(iv) If EOC = 1 continue else go to step
(iii)
(v) Read the digital output.
(vi) Store it in a memory location.

26

FLOW CHART:

27

PROGRAM TABLE

PROGRAM

COMMENTS

MOV AL,00
OUT 0D0H,AL

Load accumulator with value for ALE high


Send through output port

Send
through
output p

MOV AL,00
MOV AL,00

Introduce delay

MOV AL,00
MOV AL,00

Store the value to make SOC low the accumulator

OUT 0D0H,AL
L1 : IN AL, 0D8H
AND AL,01

Read the EOC signal from port & check for end of
conversion

CMP AL,01
JNZ L1

from por

If the conversion is not yet completed, read EOC signal


Read data from port

IN AL,0C0H
ANALOG
VOLTAGE

DIGITAL DATA ON LED


DISPLAY

HEX CODE IN MEMORY


LOCATION

RESULT:

Thus the ADC was interfaced with 8086 and the given analog inputs were
converted into its digital equivalent.

EXNO: 9
DATE:
AIM:

28
8086 INTERFACING
INTERFACING DIGITAL TO ANALOG CONVERTER

To write an assembly language program for digital to analog conversion


To convert digital inputs into analog outputs & To generate
different waveforms.
1.
2.

APPARATUS REQUIRED:
SL.NO

1.
2.

ITEM SPECIFICATION
Microprocessor kit
Power Supply

3.
DAC Interface board

QUANTITY
8086 Vi Microsystems
+5 V, dc,+12 V dc
-

1
1
1

THEORY:

Since DAC 0800 is an 8 bit DAC and the output voltage variation is between 5v
and +5v. The output voltage varies in steps of 10/256 = 0.04
(approximately). The digital data input and the corresponding output voltages are
presented in the table. Outputting digital data 00 and FF at regular intervals, to
DAC2, results in a square wave of amplitude 5v.Output digital data from 00 to FF
in constant steps of 01 to DAC2. Repeat this sequence again and again. As a
result a saw-tooth wave will be generated at DAC2 output. Output digital
data from 00 to FF in constant steps of 01 to DAC2. Output digital data from FF to
00 in constant steps of 01 to DAC2. Repeat this sequence again and again. As a
result a triangular wave will be generated at DAC2 output.
ALGORITHM:

Measurement of analog voltage:


(i) Send the digital value of DAC.
(ii) Read the corresponding analog value of its output.
Waveform generation:
Square Waveform:
(i)
Send low value (00) to the DAC.
(ii)
Introduce suitable delay.
(iii)
Send high value to DAC.
(iv)
Introduce delay.
(v)
Repeat the above procedure.

29

Saw-tooth waveform:
(i)
Load low value (00) to accumulator.
(ii)
Send this value to DAC.
(iii) Increment the accumulator.
(iv)
Repeat step (ii) and (iii) until accumulator value reaches FF.
(vi)
Repeat the above procedure from step 1.
Triangular waveform:
(i)
Load the low value (00) in accumulator.
(ii)
Send this accumulator content to DAC.
(iii)
Increment the accumulator.
(iv) Repeat step 2 and 3 until the accumulator reaches FF, decrement the
accumulator and send the accumulator contents to DAC.
(v) Decrementing and sending the accumulator contents to DAC.
(vi) The above procedure is repeated from step (i)

30

FLOWCHART:

31

PROGRAM

COMMENTS
Load digital value 00 in accumulator
Send through output port
Stop

MOV AL,7FH
OUT C0,AL
HLT
DIGITAL DATA

ANALOG VOLTAGE

PROGRAM TABLE: Square Wave


PROGRAM

COMMENTS

PROGRAM TABLE: Saw tooth Wave


PROGRAM
L2 : MOV AL,00H
L1 : OUT C0,AL
INC AL
JNZ L1
JMP L2

COMMENTS
Load 00 in accumulator
Send through output port
Increment contents of accumulator
Send through output port until it reaches FF
Go to starting location
27

32

PROGRAM TABLE: Triangular Wave


PROGRAM
L3 : MOV AL,00H
L1 : OUT C0,AL
INC AL
JNZ L1
MOV AL,0FFH
L2 : OUT C0,AL
DEC AL
JNZ L2
JMP L3

COMMENTS
Load 00 in accumulator
Send through output port
Increment contents of accumulator
Send through output port until it reaches FF
Load FF in accumulator
Send through output port
Decrement contents of accumulator
Send through output port until it reaches 00
Go to starting location

WAVEFORM GENERATION:
WAVEFORMS

AMPLITUDE

Square Waveform
Saw-tooth waveform
Triangular waveform
MODEL GRAPH:
Square Waveform

33

TIMEPERIOD

Saw-tooth waveform

Triangular waveform

RESULT:

Thus the DAC was interfaced with 8085 and different waveforms have been
generated.

EXNO: 10
DATE:

34
STEPPER MOTOR INTERFACING

AIM:

To write an assembly language program in 8086 to rotate the motor at different


speeds.
APPARATUS REQUIRED:
SL.NO

ITEM SPECIFICATION
QUANTITY
Microprocessor kit80861
Power Supply+5 V, dc,+12 V dc
1
Stepper Motor Interface board- 1
Stepper Motor
THEORY:

1.
2.
3.
4.

A motor in which the rotor is able to assume only discrete stationary angular
position is a stepper motor. The rotary motion occurs in a stepwise manner
from one equilibrium position to the next. Two-phase scheme: Any two
adjacent stator windings are energized. There are two magnetic fields active in
quadrature and none of the rotor pole faces can be in direct alignment with the
stator poles. A partial but symmetric alignment of the rotor poles is of course
possible.
ALGORITHM:

For running stepper motor clockwise and anticlockwise directions


(i) Get the first data from the lookup table.
(ii) Initialize the counter and move data into accumulator.
(iii) Drive the stepper motor circuitry and introduce delay
(iv) Decrement the counter is not zero repeat from step(iii) (v) Repeat the
above procedure both for backward and forward directions.
SWITCHING SEQUENCE OF STEPPER MOTOR:
MEMORY
A1
A2
B1
LOCATION
4500
01 0 0
4501
00 1 0
4502
10 1 1
4503
01 0 1

B2
CODE
0
1
0
0

HEX
09 H
05 H
06 H
0A H

35

FLOWCHART:

36

PROGRAM TABLE
PROGRAM

COMMENTS

START : MOV DI, 1200H


MOV CX, 0004H

Initialize memory location to store the array of


number
Initialize array size
LOOP 1 : MOV AL,[DI] Copy the first data in AL
OUT 0C0,AL
Send it through port address
MOV DX, 1010H
L1 : DEC DX
JNZ L1
INC DI

Introduce delay
Go to next memory location

LOOP LOOP1
JMP START
1200 : 09,05,06,0A

Loop until all the datas have been sent


Go to start location for continuous rotation
Array of datas

RESULT:

Thus the assembly language program for rotating stepper motor in both clockwise and
anticlockwise directions is written and verified.

EXNO: 11
DATE:
AIM:

37
INTERFACING PROGRAMMABLE KEYBOARD AND
DISPLAY CONTROLLER- 8279

To display the rolling message HELP US in the display.

APPARATUS REQUIRED:

8086 Microprocessor kit, Power supply, Interfacing board.


ALGORITHM:

Display of rolling message HELP US


1.
Initialize the counter
2.
Set 8279 for 8 digit character display, right entry
3.
Set 8279 for clearing the display
4.
Write the command to display
5.
Load the character into accumulator and display it
6.
Introduce the delay
7.
Repeat from step 1.
1. Display Mode Setup: Control word-10 H
00
0

DD

00
0

00
0

01
D

00- 8Bit character display left entry


1. - 16Bit character display left entry
2.
8Bit character display right entry
3.
16Bit character display right entry
KKK- Key Board Mode
000-2Key lockout.

38

00
D

00
K

00
K

0
K

2.Clear Display: Control word-DC H


1
1
0
1
1
0

1
CD

1
CD

1
CD

0
CA

CF
A0-3; B0-3 =FF

11
1-Enables Clear display
0-Contents of RAM will be displayed

1-FIFO Status is cleared


1-Clear all bits
(Combined effect of CD)

39

3.
1
1

Write Display: Control word-90H


0
0
1
0
0

AI

0 0

Selects one of the 16 rows of display.


Auto increment = 1, the row address selected will be incremented after each of read and
write operation of the display RAM.
FLOWCHART:

32

40

PROGRAM TABLE:

PROGRAM
START : MOV SI,1200H
MOV CX,000FH
MOV AL,10
OUT C2,AL
MOV AL,CC
OUT C2,AL
MOV AL,90
OUT C2,AL
L1 : MOV AL,[SI]
OUT C0,AL
CALL DELAY
INC SI
LOOP L1
JMP START
DELAY : MOV DX,0A0FFH
LOOP1 : DEC DX
JNZ LOOP1
RET

COMMENTS
Initialize array
Initialize array size
Store the control word for display mode
Send through output port
Store the control word to clear display
Send through output port
Store the control word to write display
Send through output port
Get the first data
Send through output port
Give delay
Go & get next data
Loop until all the datas have been taken
Go to starting location
Store 16bit count value
Decrement count value
Loop until count values becomes zero
Return to main program

LOOK-UP TABLE:
1200

98

68

7C

29

FF

C8
1204

FF

1C

41

OUTPUT:
E

7-SEGMENT
LED FORMAT

H
E
X
D
A
T
A

01
00
10
01
11
00
10
01

1200H
1201H
1202H
1203H
1204H
1205H
1206H
1207H

RESULT:

0
1
1
1
1
0
0
1

0
1
1
0
1
0
1
1

1
0
1
0
1
0
0
1

1
1
1
1
1
1
1
1

0
0
1
0
1
1
0
1

0
0
0
0
1
0
0
1

0
0
0
0
1
0
1
1

98
68
7C
C8
FF
1C
29
FF

Thus the rolling message HELP US is displayed using 8279 interface kit.

42
INTERFACING PROGRAMMABLE TIMER-8253

EXNO: 12
DATE:
A IM:

To study different modes of operation of programmable timer 8253.


THEORY:

The main features of the timer are,

Three independent 16-bit counters,


ii.
Input clock from DC to 2 MHz,
iii. Programmable counter modes,
iv. Count binary or BCD.
The control signals with which the 8253 interfaces with the CPU are CS,
RD, WR, A1, A2.The basic operations performed by 8253 are determined by
these control signals. It has six different modes of operation, viz, mode 0 to
mode 5.
i.

MODE 2 RATE GENERATOR

It is a simple divide - by N counter. The output will be low for one input
clock period. The period from one output pulse to the next equals the number
of input counts in the count register. If the count register is reloaded between
output pulses, the present period will not be affected, but the subsequent
period will reflect the new value.
MODE 3 SQUARE WAVE GENERATOR

It is similar to mode 2, except that the output will remain high until one half
for even number count, If the count is odd, the output will be high for
(count+1)/2 counts and low for (count-1)/2 counts
ALGORITHM:

Mode 21.
2.
3.
4.
5.

Initialize channel 0 in mode 2


Initialize the LSB of the count.
Initialize the MSB of the count.
Trigger the count.
Read the corresponding output in CRO.

43

34
Mode 3-

Initialize channel 0 in mode 3


Initialize the LSB of the count.
Initialize the MSB of the count.
Trigger the count
Read the corresponding output in CRO.

1.
2.
3.
4.
5.

PORT ADDRESS:
1.
CONTROL REGISTER
2. COUNTER OF CHANNEL 0
3. COUNTER OF CHANNEL 1
4. COUNTER OF CHANNEL 2
5. O/P PORT OF CHANNEL 0
6. O/P PORT OF CHANNEL 1
7. O/P PORT OF CHANNEL 2

CONTROL WORD FORMAT:


D7 D6 D5 D4 D3 D2 D1 D0
SC1
SC0
RL1 RL0
0
0
1

M2

M1

M0

BCD

00 1

Mode 2 = 34 H

00

01

SC1
SC0
CHANNEL SELECT
0
0
CHANNEL 0
0
1
CHANNEL 1
1
0
CHANNEL 2
1
1
----BCD --0 BINARY COUNTER
M2

M1

M0

MODE

Mode 3 = 36 H

0
0
1
1

RL1
0
1
0
1

RL0
READ/LOAD
LATCH
LSB
MSB
LSB FIRST, MSB NEXT
01 --BCD COUNTER

0
0
0
0
1
1

0
0
1

0
1
0
1
0
1

MODE 0
MODE 1
MODE 2

MODE 3

MODE 4

MODE 5

PORT PIN ARRANGEMENT

DEBOUNCE CIRCUIT CONNECTION

1 CLK 0
2 CLK 1
3 CLK 2

44

FLOW CHART:

45

04 OUT 0
05 OUT 1
06 OUT 2
07 GATE 0
08 GATE 1
09 GATE 2
10 GND

MODE 2 RATE GENERATOR:


PROGRAM
MOV AL, 34H
OUT 0BH
MOV AL, 0AH
OUT 08H
MOV AL, 00H
OUT 08H
HLT

COMMENTS
Store the control word in accumulator
Send through output port
Copy lower order count value in accumulator
Send through output port
Copy higher order count value in accumulator
Send through output port
Stop

MODE 3 SQUARE WAVE GENERATOR:


PROGRAM
MOV AL, 36H
OUT 0BH
MOV AL, 0AH
OUT 08H
MOV AL, 00H
OUT 08H
HLT

COMMENTS
Store the control word in accumulator
Send through output port
Copy lower order count value in accumulator
Send through output port
Copy higher order count value in accumulator
Send through output port
Stop
6
46

MODEL GRAPH:
RATE GENERATOR

SQUARE WAVE GENERATOR

RESULT:
Thus an ALP for rate generator and square wave generator are written and
executed.

47

EXNO: 13
DATE:

INTERFACING USART 8251

AIM:

To study interfacing technique of 8251 (USART) with microprocessor 8086


and an 8086 ALP to transmit and receive data between two serial ports with RS232
cable.
APPARATUS REQUIRED:

8086 kit (2 Nos), RS232 cable.


THEORY:

The 8251 is used as a peripheral device for serial communication and is


programmed by the CPU to operate using virtually any serial data transmission
technique. The USART accepts data characters from the CPU in parallel format and
then converts them into a continuous serial data stream for transmission.
Simultaneously, it can receive serial data streams and convert them into parallel data
characters for the CPU. The CPU can read the status of the USART at any time. These
include data transmission errors and control signals. The control signals define the
complete functional definition of the 8251. Control words should be written into the
control register of 8251.These control words are split into two formats: 1) Mode
instruction word & 2) Command instruction word. Status word format is used to
examine the error during functional operation.

1...transmit enable
1...data terminal ready 1... receive enable
1... send break character
1.... reset error flags (pe,oe,fe)
1..... request to send (rts)
1...... internal reset
1....... enter hunt mode (enable search for sync characters)

48

01 ransmitter ready
receiver ready 1.. transmitter
empty 1... parity error (pe)
1.... overrun error (oe)
1..... framing error (fe), async only
1.

1...... sync detect, sync only


1....... data set ready (dsr)

ALGORITHM:

1. Initialize 8253 and 8251 to check the transmission and reception of a character
2.
Initialize8253 to give an output of 150Khz at channel 0 which will give a

9600 baud rate of 8251.


3. The command word and mode word is written to the 8251 to set up for
subsequent operations
4. The status word is read from the 8251 on completion of a serial I/O
49

operation, or when the host CPU is checking the status of the device before
starting the next I/O operation.
FLOW CHART:

50

PROGRAM: TRANSMITTER END


PROGRAM
COMMENTS
MOV AL,36
Initialize 8253 in mode 3 square wave generator
OUT CE,AL
Send through port address
MOV AL,10
Initialize AL with lower value of count (clock frequency 150KHz)
OUT C8,AL
Send through port address
MOV AL,00
Initialize AL with higher value of count
OUT C8,AL
Send through port address
MOV AL,4E
Set mode for 8251(8bit data, No parity, baud rate factor 16x & 1 stop bit)
OUT C2,AL
Send through port address
MOV AL,37
Set command instruction(enables transmit enable & receive enable bits)
OUT C2,AL
Send through port address
L1:IN AL,C2
Read status word
AND AL,04
Check whether transmitter ready
JZ L1
If not wait until transmitter becomes ready
MOV AL,41
Set the data as 41
OUT C0,AL
Send through port address
INT 2
Restart the system
RECEIVER END
PROGRAM
COMMENTS
MOV AL,36
Initialize 8253 in mode 3 square wave generator
OUT CE,AL
Send through port address
MOV AL,10
Initialize AL with lower value of count (clock frequency 150KHz)
OUT C8,AL
Send through port address
MOV AL,00
Initialize AL with higher value of count
OUT C8,AL
Send through port address
MOV AL,4E
Set mode for 8251(8bit data, No parity, baud rate factor 16x & 1 stop bit)
OUT C2,AL
Send through port address
MOV AL,37
Set command instruction(enables transmit enable & receive enable bits)
OUT C2,AL
Send through port address
L1:IN AL,C2
Read status word
MOV BX,1500
Initialize BX register with memory location to store the data
MOV [BX],AL
Store the data in the memory location
INT 2
Restart the system
RESULT:

Thus ALP for serial data communication using USART 8251 is written and the
equivalent ASCII 41 for character A is been transmitted & received.
51
INTERFACING PPI 8255

EXNO: 14
DATE:
AIM:

To write ALP by interfacing 8255 with 8086 in mode 0, mode 1 and


mode 2.

APPARATUS REQUIRED:

8086 kit, 8255 interface kit.

ALGORITHM:
Mode 0

1.
2.
3.
4.
5.

Initialize accumulator to hold control word


store control word in control word register
Read data port A.
Store data from port A in memory
Place contents in port B.

Mode 1 & Mode 2

1.
2.
3.
4.
5.
6.
7.
8.

Initialize accumulator to hold control word (for port A)


Store control word in control word register
Initialize accumulator to hold control word (for port B)
Place contents in control word register.
Disable all maskable interrupts, enable RST 5.5
send interrupt mask for RST 6.5 & 7.5
Enable interrupt flag
Read data from port A, place contents in port B.

52

FLOWCHART:

53

MODE 0
PROGRAM
MOV AL,90H
OUT C6,AL
IN AL,C0
OUT C2,AL
HLT

COMMENTS
Set the control word
Send it to control port
Get the contents of port A in AL
Send the contents of port B to port address
Stop

MODE 1
PROGRAM
MOV AL,0B0H
OUT C6,AL
MOV AL,09H
OUT C6,AL
MOV AL,13H
OUT 30,AL
MOV AL,0AH
OUT 32,AL
MOV AL,0FH
OUT 32,AL
MOV AL,00H
OUT 32,AL
STI
HLT
ISR:
IN AL,C0
OUT C2,AL
HLT

MODE 2
PROGRAM
MOV AL,0C0H
OUT C6,AL
MOV AL,09H
OUT C6,AL
MOV AL,13H
OUT 30,AL
MOV AL,0AH
OUT 32,AL

COMMENTS
Set the control word for mode 1
Send it to control port
Control for BSR mode
Send it to control port
Interrupt generation
Through 8259
Using IR2 interrupt(lower order count)
Higher order count
Set trap flag
Stop
Subroutine
Read from Port A
Send it to Port B
Stop
COMMENTS
Set the control word for mode 2
Send it to control port
Control for BSR mode
Send it to control port
Interrupt generation
Through 8259

54

MOV AL,0FH
OUT 32,AL
MOV AL,00H
OUT 32,AL
STI
HLT
ISR:
IN AL,C0
OUT C2,AL
HLT
BSR mode

Using IR2 interrupt(lower order count)


Higher order count
Set trap flag
Stop
Subroutine
Read from Port A
Send it to Port B
Stop

Bit set/reset, applicable to PC only. One bit is S/R at a time. Control word:
D7

D5

D4

D3

(0=BSR)
X
Bit select: (Taking Don't care's as 0)

D6

B2

B2

Control word (Set)

00

B1

00
10
00
00
01
01
11
01

D2
B1

D1

B0

D0
S/R (1=S,0=R)

B0

PC bit

0000 0001 = 01h

Control word (reset)


0000 0000 = 00h

0000 0011 = 03h

0000 0010 = 02h

0000 0101 = 05h

0000 0100 = 04h

0000 0111 = 07h

0000 0110 = 06h

0000 1001 = 09h

0000 1000 = 08h

0000 1011 = 0Bh

0000 1010 = 0Ah

0000 1101 = 0Dh

0000 1100 = 0Ch

0000 1111 = 0Fh

0000 1110 = 0Eh

I/O mode
D7

01

D6
(1=I/O)

D5

D4

GA mode select

D3

PA

D2
PCU

GB mode

D1

D0

PB

PCL

select

D6, D5: GA mode select:


o 00 = mode0 o
01 = mode1 o
1X = mode2
0 D4(PA), D3(PCU): 1=input 0=output
1 D2: GB mode select: 0=mode0, 1=mode1
2 D1(PB), D0(PCL): 1=input 0=output

Result:
Input

Mode 0
Mode 1
Mode 2
Output Input Output Input Output

The programs for interfacing 8255 with 8085 are executed & the output is
obtained for modes 0,1 & 2.
55
8051 PROGRAMMING
8 BIT ADDITION

EXNO: 15
DATE:
AIM
:

To write a program to add two 8-bit numbers using 8051 microcontroller.

ALGORITHM:

1.
2.
3.

Clear Program Status Word.


Select Register bank by giving proper values to RS1 & RS0 of PSW.
Load accumulator A with any desired 8-bit data.
w
i
t
h

5.
6.
7.

Add these two 8-bit numbers.


Store the result.
Stop the program.

56

FLOW CHART:

57

08 Bit Addition (Immediate Addressing)


ODE

C
O
M
M
E
N
T
S

4100
4101

CLR
MOV

C3
74,data1

A,# data1

4103
ADDC

A.

4105

# data 2

MOV
DPTR, #
4500H

24,data2
with

data2
90,45,00
memory

Initialize the
location
Store the result in

4108

4109

Clear CY Flag
Get the data1 in
Accumulator
Add the data1

L1

MOVX
SJMP

0@ DPTR, A F0
L1

80,FE

memory location
Stop the program

OUTPUT:
OUTPUT
MEMORY LOCATION
DATA
4500

RESULT:

Thus the 8051 ALP for addition of two 8 bit numbers is executed.

EXNO: 16

58
8051 PROGRAMMING 8 BIT SUBTRACTION

DATE:
AIM:

To perform subtraction of two 8 bit data and store the result in memory.

ALGORITHM:

a.
b.
c.
d.
e.
f.

Clear the carry flag.


Initialize the register for borrow.
Get the first operand into the accumulator.
Subtract the second operand from the accumulator.
If a borrow results increment the carry register.
Store the result in memory.

59

FLOWCHART:
-

60

08 Bit Subtraction (Immediate Addressing)


ADDRESS
OPERAND
4100

LABEL

MNEMONIC

COMMENTS

C3

Clear CY flag

CLR

A.

4101

MOV

4103

SUBB

data1

A.
4105

MOV

4108

MOVX

#
#

data2
DPTR, # 4500
memory

74.

data1 Store data1 in


accumulator
94,data2
Subtract
data2 from
90,45,00

Initialize F0
in memo

location
Store the difference

0@ DPTR, A
4109

L1

SJMP

L1

80,FE

OUTPUT:
OUTPUT

RESULT:

Thus the 8051 ALP for subtraction of two 8 bit numbers is executed

61

data1

Stop

EXNO: 17
AIM:

To perform division of two 8 bit data and store the result in memory.
ALGORITHM:

a.
b.
c.
d.

Get the multiplier in the accumulator.


Get the multiplicand in the B register.
Multiply A with B.
Store the product in memory.

62

FLOWCHART:

63

08 Bit Multiplication
ADDRESS
OPERAND
4100

LABEL
MOV

A ,#data1

4102 MOV B, #data2


4104
4106

75,data2
MUL
MOV

4109

MOVX

Store data2 in B reg


A,B
DPTR, #
4500H
0@ DPTR, A

INC
401A
410B
410D
410E

STOP

MNEMONIC

F5,F0
90,45,00

data1 Store data1 in


accumulator
Multiply both
Initialize memory
location
Store lower order

F0

DPTR

result
A3

MOV

A,B

MOV

0@ DPTR, A
SJMP

74.

COMMENTS

Go to next memory
location
E5,F0

STOP

80,FE

Stop

OUTPUT:
INPUT
MEMORY LOCATION
4500

OUTPUT
DATA

MEMORY LOCATION

DATA

4502

RESULT:

Thus the 8051 ALP for multiplication of two 8 bit numbers is executed

EXNO: 18

64
8051 PROGRAMMING 8 BIT DIVISION

DATE:
AIM:

To perform division of two 8 bit data and store the result in memory.
ALGORITHM:

Store hig
order
result
F
0

1.
2.
3.
4.

Get the Dividend in the accumulator.


Get the Divisor in the B register.
Divide A by B.
Store the Quotient and Remainder in memory.

65

FLOWCHART:

66

08 Bit Division
ADDRESS
OPERAND
4100
4102
4104
4015

LABEL
MOV

MOV B, # data2

4018

75,data2
DIV
MOV

MOVX

4109
410A
410C
410D

INC
MOV
MOV

HEX
CODE
74,data1
data1 in

MNEMONIC

A.

# data1

Store data2 in B reg


A,B
DPTR, # 4500H
Initialize memory
0@ DPTR, A
F0
DPTR

A3

A,B

E5,F0

0@ DPTR, A

F0

STOP

80,FE

COMMENTS
Store

84
90,45,00

next memory
location
Store quotient

STOP SJMP

OUTPUT:

4501 (divisor)

4503

DATA
(remainder)
(quotient)

RESULT:

Thus the 8051 ALP for division of two 8 bit numbers is executed

EXNO: 19

Divide
location

Store remainder Go to

Stop

INPUT OUTPUT
MEMORY LOCATION DATA MEMORY LOCATION
4502
4500 (dividend)

accumul
r

67
8051 PROGRAMMING
LOGICAL AND BIT MANIPULATION

DATE:
AIM:

To write an ALP to perform logical and bit manipulation operations using 8051

microcontroller.
APPARATUS REQUIRED:

8051 microcontroller kit


ALGORITHM:

1.
2.
3.
4.
5.
6.
7.
8.

Initialize content of accumulator as FFH


Set carry flag (cy = 1).
AND bit 7 of accumulator with cy and store PSW format.
OR bit 6 of PSW and store the PSW format.
Set bit 5 of SCON.
Clear bit 1 of SCON.
Move SCON.1 to carry register.
Stop the execution of program.

68

FLOWCHART:

69

PROGRAM TABLE:
A

LABEL

MNEMONICS
COMMENT

OPERAND

4100

0
9
0,
4
5,
0
MOV

Initialize m
e
m
o
r
y

DPTR,#4500
location
Get the data in

4103
74,
FF
4105

D3

4016

82,EF

MOV
SETB
ANL

A,#FF
C

accumulator
Set CY bit

AC

Perform AND with 7th


bit of accumulator

C.
C.7

4018E5,D0 MOV A,DOH


410A
F
0

Store the result

MOVX
INC

@DPTR,A
DPTR

ORL

C.

410B

A3

410C

72,AA

410E
4110

C2,D6 CLR PSW.6 Clear 6th bit of PSW


E5,D0
MOVX
A3
INC

E.2

4113
4114

D2,90

SETB

4116

C2,99

CLR

MOV
@DPTR,A
DPTR
SCON.5
SCON.1

Go to next location
OR CY bit with 2nd bit
if IE reg
A,DOH
Go to next location
Set 5th of SCON reg
Clear 1st bit of SCON
reg

4118E5,98 MOV A,98H


411A
411B

F0
A3

MOVX @DPTR,A

Store the result


INC

DPTR
70

411C

A2,99

MOV

411E

E5,D0

MOV

A,DOH

F0

MOVX

@DPTR,A

SJMP

L2

4120
4122

80,FE

L2

C,SCON.1

G
o
to
ne
xt
lo
ca
ti
on
C
o

py 1st bit of
SCON

reg
to

C
Y

flag

Store the result

Stop

OUTPUT:
MEMORY
LOCATION

SPECIAL FUNCTION REGISTER FORMAT

BEFORE
EXECUTION

AFTER
EXECUTION

4500H (PSW)
OV
-

CY
00H

AC

FO

RS1

RS0

88H

4501H (PSW)
OV
-

CY
40H

AC

FO

RS1

RS0

88H

4502H (SCON)
RI
4503H (PSW)
OV
-

SM0

SM1

SM2

REN

TB8

RB8

TI

20H

0FH
P

CY
FFH

AC

FO

RS1

RS0

RESULT:

Thus the bit manipulation operation is done in 8051 microcontroller.

71

09H

72

Você também pode gostar