0% found this document useful (0 votes)
5 views48 pages

Microprocessor Manual

The document is a laboratory manual for the Microprocessors and Microcontrollers course, detailing experiments based on the 8086 processor and 8051 microcontroller. It includes aims, apparatus required, algorithms, and assembly language programs for arithmetic operations, sorting, searching, and string manipulation. The manual is prepared by faculty members and verified by the Head of Department.

Uploaded by

ece hod
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views48 pages

Microprocessor Manual

The document is a laboratory manual for the Microprocessors and Microcontrollers course, detailing experiments based on the 8086 processor and 8051 microcontroller. It includes aims, apparatus required, algorithms, and assembly language programs for arithmetic operations, sorting, searching, and string manipulation. The manual is prepared by faculty members and verified by the Head of Department.

Uploaded by

ece hod
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 48

DEPARTMENT OF ELECTRONICS AND

COMMUNICATION ENGINEERING

REGULATION-2023

LABORATORY MANUAL

U23ECP51/MICROPROCESSORS AND MICROCONTROLLERS

LABORATORY

PREPARED BY VERIFIED BY

1.Ms.R.ABINAYA/AP Dr.P.RAJESWARI/HOD

2.Mrs.R.GAYATHRI/AP
LIST OF EXPERIMENTS

BASED ON 8086 PROCESSOR

1. Programs for 16 bit Arithmetic operations

2. Programs for Sorting and Searching

3. Programs for String manipulation operations.

4. Programs for Digital clock.

5. Interfacing ADC and DAC.

6. Interfacing and Programming Keyboard and Display.

7. Interfacing and Programming of Stepper Motor.

8. Finding number of and number of in a given 8-bit number using 8051

SIMULATION USING KEIL

9. Programming using Arithmetic, Logical instructions of 8051 Micro controller.

10. Programming and verifying Timer operation in 8051 Micro controller.


EX.NO:1 Programs for 16 bit Arithmetic operations

AIM:

To write an Assembly Language Program (ALP) for performing the Arithmetic operation of two-
byte numbers
APPARATUS REQUIRED:
S. No. Item Specification Quantity
01 Microprocessor Kit 8086 1
02 Power Supply +5 Vdc 1

ALGORITHM:
16- bit
Addition
 Initialize the MSBs of sum to 0
 Get the first number.
 Add the second number to the first number.
 If there is any carry, increment MSBs of sum by 1.
 Store LSBs of sum.
 Store MSBs of sum.
16- bit Subtraction
 Initialize the MSBs of difference to Zero
 Get the first number
 Subtract the second number from the first number.
 If there is any borrow, increment MSBs of difference by 1.
 Store LSBs of difference
 Store MSBs of difference.
16- bit Multiplication
 Get the multiplier.
 Get the multiplicand
 Initialize the product to 0.
 Product = product + multiplicand
 Decrement the multiplier by 1
 If multiplicand is not equal to 0, repeat from step (d) otherwise store the
product.
16- bit Division
 Get the dividend
 Get the divisor
 Initialize the quotient to 0.
 Dividend = dividend – divisor
 If the divisor is greater, store the quotient. Go to step g.
 If dividend is greater, quotient = quotient + 1. Repeat from step (d) Store the
dividend value as remainder.
PROGRAM
ADDITION
ADDRESS OPCODE MNEMONICS 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
JNC L1 Check for carry
INC CX If carry exists, increment the
L1 : MOV [1206],CX Store the carry
MOV [1204], AX Store the sum
HLT Stop the program

SUBTRACTION
ADDRESS OPCODE MNEMONICS 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 If borrow exists, increment the
CX
L1 : MOV [1206],CX Store the borrow
MOV [1204], AX Store the difference
HLT Stop the program
MULTIPLICATION
ADDRESS OPCODE MNEMONICS COMMENTS
MOV AX,[1200] Get the first data
MOV BX, [1202] Get the second data
MUL BX Multiply both
MOV [1206],AX Store the lower order product
Copy the higher order product
MOV AX,DX
to AX
MOV [1208],AX Store the higher order product
HLT Stop the program

DIVISION
ADDRESS OPCODE MNEMONICS COMMENTS
MOV AX,[1200] Get the first data
MOV DX, [1202] Get the second data
DIV BX Divide the dividend by divisor
MOV [1206],AX Store the lower order product
Copy the higher order product
MOV AX,DX
to AX
MOV [1208],AX Store the higher order product
HLT Stop the program

OUTPUT:
ADDITION

MEMORY

DATA

SUBTRACTION
MEMORY

DATA

MULTIPLICATION
MEMORY

DATA
DIVISION
MEMORY

DATA

RESULT:
Thus Arithmetic operations of two byte numbers are performed and the result
is stored.
EX.NO:2a Programs for Sorting and Searching
SORTING
AIM
To write an Assembly Language Program (ALP) to sort a given array in
ascending and descending order.
APPARATUS REQUIRED:

S.No Item Specification Quantity

1. Microprocessor kit 8086 1


2. Power Supply +5 V dc 1

ALGORITHM:
(i) Sorting in ascending order:

 Load the array count in two registers C1 and C2.


 Get the first two numbers.
 Compare the numbers and exchange if necessary so that the two numbers are in
ascending order.
 Decrement C2.
 Get the third number from the array and repeat the process until C2 is 0.
 Decrement C1 and repeat the process until C1 is 0.

(ii) Sorting in descending order:


 Load the array count in two registers C1 and C2.
 Get the first two numbers.
 Compare the numbers and exchange if necessary so that the two numbers are in
descending order.
 Decrement C2.
 Get the third number from the array and repeat the process until C2 is 0.
 Decrement C1 and repeat the process until C1 is 0.
PROGRAM
ASCENDING
ADDRESS OPCODES MNEMONICS COMMENTS
MOV SI,1200H Initialize memory location for
array size
MOV CL,[SI] Number of comparisons in CL
L4 : MOV SI,1200H Initialize memory location for
array size
MOV DL,[SI] Get the count in DL
INC SI Go to next memory location
MOV AL,[SI] Get the first data in AL
L3 : INC SI Go to next memory location
MOV BL,[SI] Get the second data in BL
CMP AL,BL Compare two data’s
JNB L1 If AL < BL go to L1
DEC SI Else, Decrement the memory
location
MOV [SI],AL Store the smallest data
MOV AL,BL Get the next data AL
JMP L2 Jump to L2
L1 : DEC SI Decrement the memory
location
MOV [SI],BL Store the greatest data in
memory location
L2 : INC SI Go to next memory location
DEC DL Decrement the count
JNZ L3 Jump to L3, if the count is not
reached zero
MOV [SI],AL Store data in memory location
DEC CL Decrement the count
JNZ L4 Jump to L4, if the count is not
reached zero
HLT Stop
DESCENDING
ADDRESS OPCODES MNEMONICS COMMENTS
MOV SI,1200H Initialize memory location for
array size
MOV CL,[SI] Number of comparisons in CL
L4 : MOV SI,1200H Initialize memory location for
array size
MOV DL,[SI] Get the count in DL
INC SI Go to next memory location
MOV AL,[SI] Get the first data in AL
L3 : INC SI Go to next memory location
MOV BL,[SI] Get the second data in BL
CMP AL,BL Compare two data’s
JB L1 If AL > BL go to L1
DEC SI Else, Decrement the memory
location
MOV [SI],AL Store the largest data
MOV AL,BL Get the next data AL
JMP L2 Jump to L2
L1 : DEC SI Decrement the memory
location
MOV [SI],BL Store the smallest data in
memory location
L2 : INC SI Go to next memory location
DEC DL Decrement the count
JNZ L3 Jump to L3, if the count is not
reached zero
MOV [SI],AL Store data in memory location
DEC CL Decrement the count
JNZ L4 Jump to L4, if the count is not
reached zero
HLT Stop
OUTPUT: ASCENDING

INPUT OUTPUT
Memory Memory
Data Data

DESCENDING

INPUT OUTPUT
Memory Memory
Data Data

RESULT:

Thus given array of numbers are sorted in ascending & descending order.
EX.NO:2b SEARCHING
AIM:
To write an Assembly Language Program (ALP) to find the largest and
smallest number in a given array.
APPARATUS REQUIRED:

S.No Item Specification Quantity

1. Microprocessor kit 8086 1


2. Power Supply +5 V dc 1

ALGORITHM:
(i) Finding largest number:

 Load the array count in a register C1.

 Get the first two numbers.

 Compare the numbers and exchange if the number is small.

 Get the third number from the array and repeat the process until C1 is 0.

(ii) Finding smallest number:


 Load the array count in a register C1.

 Get the first two numbers.

 Compare the numbers and exchange if the number is large.

 Get the third number from the array and repeat the process until C1 is 0.
PROGRAM: LARGEST

ADDRESS OPCODES MNEMONICS COMMENTS


MOV SI,1200H Initialize array size
MOV CL,[SI] Initialize the count
INC SI Go to next memory location
MOV AL,[SI] Move the first data in AL
DEC CL Reduce the count
L2 : INC SI Move the SI pointer to next data
CMP AL,[SI] Compare two data’s
JNB L1 If AL > [SI] then go to L1 ( no swap)
MOV AL,[SI] Else move the large number to AL
L1 : DEC CL Decrement the count
JNZ L2 If count is not zero go to L2
MOV DI,1300H Initialize DI with 1300H
MOV [DI],AL Else store the biggest number in 1300
location
HLT Stop

SMALLEST
ADDRESS OPCODES MNEMONICS COMMENTS
MOV SI,1200H Initialize array size
MOV CL,[SI] Initialize the count
INC SI Go to next memory location
MOV AL,[SI] Move the first data in AL
DEC CL Reduce the count
L2 : INC SI Move the SI pointer to next
data
CMP AL,[SI] Compare two data’s
JB L1 If AL < [SI] then go to L1 ( no
swap)
MOV AL,[SI] Else move the large number
to AL
L1 : DEC CL Decrement the count
JNZ L2 If count is not zero go to L2
MOV DI,1300H Initialize DI with 1300H
MOV [DI],AL Else store the biggest
number in 1300 location
HLT Stop

OUTPUT:
LARGEST
INPUT OUTPUT
Memory Memory

SMALLEST

INPUT OUTPUT
Memory Memory

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

EX.NO:3a Programs for String manipulation operations.


LENGTH OF THE STRING
AIM:
To move a string of length FF from source to destination.

APPARATUS REQUIRED:
S. No. Item Specification Quantity
01 Microprocessor Kit 8086 1
02 Power Supply +5 Vdc 1

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.
 Move the byte from DS TO ES, till CX=0.

PROGRAM

ADDRESS OPCODES MNEMONICS COMMENTS

MOV SI,1200H Initialize destination address

MOV DI,1300H Initialize starting address

MOV CX,0006H Initialize array size


CLD Clear direction flag

REP MOVSB Copy the contents of source


into destination until count
reaches zero
HLT
Stop

OUTPUT

INPUT

MEMORY

DATA

OUTPUT

MEMORY

DATA
RESULT:

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


to destination segment
EX.NO:3b SEARCHING A STRING
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.

APPARATUS REQUIRED:
S. No. Item Specification Quantity
01 Microprocessor Kit 8086 1
02 Power Supply +5 Vdc 1

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.
 Move the byte to be searched in the AL register.
 Scan for the byte in ES. If the byte is found ZF=0, move the address pointed by ES:
DI to BX.

PROGRAM
ADDRESS OPCODES MNEMONICS COMMENTS
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
MEMORY
DATA

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

EX.NO:3c FIND AND REPLACE


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

APPARATUS REQUIRED:
S. No. Item Specification Quantity
01 Microprocessor Kit 8086 1
02 Power Supply +5 Vdc 1

ALGORITHM:

 Initialize the extra segment .(E S)


 Initialize the start of string in the ES. (DI)
 Move the number of elements in the string in CX register.
 Move the byte to be searched in the AL register.
 Store the ASCII code of the character that has to replace the scanned byte in BL
register.
 Scan for the byte in ES. If the byte is not found, ZF≠1 and repeat scanning.
 If the byte is found, ZF=1.Move the content of BL register to ES: DI.

PROGRAM
ADDRESS OPCODES MNEMONICS COMMENTS
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
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

OUTPUT
INPUT
MEMORY
DATA
OUTPUT
MEMORY
DATA

RESULT:
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.

EX.NO:4 Programs for Digital clock


AIM:
To display the digital clock specifically by displaying the hours, minutes and
seconds using 8086 kits.

APPARATUS REQUIRED:

S.No Item Specification


1 Microprocessor kit 8086
2 Power Supply 5V

PRELIMINARY SETTINGS

Org 1000h
Store time value in memory location
1500 -Seconds
1501- Minutes
1502- Hours

ALGORITHM:

 Take the microprocessor kit.


 Display the digital clock by displaying the hours, minutes and seconds.
 Execute the program.
 Get the output.

PROGRAM:
ADDRESS OPCODES LABEL MNEMONICS
START CALL CONVERT

CALL DISPLAY

DELAY MOV AL,0B0H

OUT 16H,AL

MOV CL,07H

S2 MOV AL,88H

OUT 14H,AL

MOV AL,80H

OUT 14H,AL

S1 MOV AL,80H

OUT 16H,AL

NOP
NOP

NOP

NOP

IN AL,14H

MOV DL,AL

IN AL,14H

OR AL,DL

JNZ S1

DEC CL

JNZ S2

MOV S1,1500H

MOV AL,[SI]

INC AL

MOV [SI],AL

CMP AL,3CH

JNZ START

MOV AL,00H

MOV [SI],AL
INC SI

MOV [SI],AL

INC AL

MOV [SI],AL

CMP AL,3CH

JNZ START

MOV AL,0

MOV [SI],AL

INC SI

MOV [AL],SI

INC AL

MOV [SI],AL

CMP AL,18H

JNZ START

MOV AL,0

MOV [SI],AL

JMP START

DISPLAY MOV AH,06H

MOV DX,1600H

MOV CH,01H

MOV CL,0H

INT 5

RET

CONVERT MOV SI,1500H

MOV BX,1608H

MOV AL,24H

MOV [BX],AL

SECONDS

MOV AL,[SI]

MOV AH,0
MOV DH,0AH

DIV DH

ADD AH,30H

DEC BX

MOV [BX],AH

DEC BX

ADD AL,30H

MOV [BX],AL

DEC BX

MOV AL,3AH

MOV [BX],AL

DEC BX

MINUTES

INC SI

MOV AL,[SI]

MOV AH,0

MOV DH,0AH

DIV DH

ADD AH,30H

MOV [BX],AH

DEC BX

ADD AL,30H

MOV [BX],AL

DEC BX

MOV AL.3AH

MOV [BX],AL

DEC BX

HOURS

INC SI

MOV AL,[SI]
MOV AH,0

MOV DH,0AH

DIV DH

ADD AH,30H

MOV [BX],AL

DEC BX

ADD AL,30H

MOV [BX],AL

RET

GETC

IN AL,02H

AND AL,0FFH

CMP AL,0F0H

JNE GETC

RESULT

Thus the digital clock program has been written and executed using 8086
microprocessor kit and the output of digital clock was displayed as [hours: minutes:
seconds] successfully.

EX.NO:5a Interfacing ADC and DAC.


Interfacing ADC
AIM:
To write an assembly language program to convert an analog signal into a digital
signal using an ADC interfacing.
APPARATUS REQUIRED:

S.No Item Specification Quantity


1 Microprocessor kit 8086 1
2 Power Supply +5Vdc, +12Vdc 1

3 ADC Interface board - 1

ALGORITHM:
 Select the channel and latch the address.
 Send the start conversion pulse.
 Read EOC signal.
 If EOC = 1 continue else go to step (iii)
 Read the digital output.
 Store it in a memory location.

PROGRAM:

ADDRESS LABEL MNEMONICS COMMENTS

MOV AL,00 Load accumulator with value for ALE high

OUT 0C8H,AL Send through output port

MOV AL,08 Load accumulator with value for ALE low

OUT 0C8H,AL Send through output port

Store the value to make SOC high in the


MOV AL,01
accumulator

OUT 0D0H,AL Send through output port

MOV AL,00

MOV AL,00 Introduce delay

MOV AL,00

Store the value to make SOC low the


MOV AL,00
accumulator

OUT 0D0H,AL Send through output port

L1 IN AL, 0D8H Read the EOC signal from port & check for
AND AL,01 end of conversion
CMP AL,01

JNZ L1 If the conversion is not yet completed, read


EOC signal from port again

IN AL,0C0H Read data from port

MOV BX,1100 Initialize the memory location to store data

MOV [BX],AL Store the data

HLT Stop

RESULT:
Thus the ADC was interfaced with 8086 and the given analog inputs were
converted into its digital equivalent.
EX.NO:5b INTERFACING DIGITAL – TO – ANALOG CONVERTER

AIM:

1. To write an assembly language program for digital to analog conversion


2. To convert digital inputs into analog outputs & To generate different waveforms
APPARATUS REQUIRED:

S.No Item Specification Quantity


1 Microprocessor kit 8086 1
2 Power Supply +5Vdc, +12Vdc 1

3 DAC Interface board - 1

ALGORITHM:
1. Measurement of analog voltage:
 Send the digital value of DAC.
 Read the corresponding analog value of its output.
2. 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.
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.
(v) 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)

PROGRAM:

MEASUREMENT OF ANALOG VOLTAGE:

ADDRESS LABEL MNEMONICS COMMENTS

MOV AL,7FH Load digital value 00 in accumulator

OUT C0,AL Send through output port

HLT Stop

SQUARE WAVE

ADDRESS LABEL MNEMONICS COMMENTS

L2 MOV AL,00H Load 00 in accumulator

OUT C0,AL Send through output port

CALL L1 Give a delay

MOV AL,FFH Load FF in accumulator

OUT C0,AL Send through output port

CALL L1 Give a delay

JMP L2 Go to starting location

L1 MOV CX,05FFH Load count value in CX register

L3 LOOP L3 Decrement until it reaches zero

RET Return to main program

SAW TOOTH WAVE


ADDRESS LABEL MNEMONICS COMMENTS

L2 MOV AL,00H Load 00 in accumulator

L1 OUT C0,AL Send through output port

INC AL Increment contents of accumulator

Send through output port until it


JNZ L1
reaches FF

JMP L2 Go to starting location

TRIANGULAR WAVE

ADDRESS LABEL MNEMONICS COMMENTS


L3 MOV AL,00H Load 00 in accumulator

L1 OUT C0,AL Send through output port

INC AL Increment contents of accumulator


Send through output port until it
JNZ L1
reaches FF
MOV AL,0FFH Load FF in accumulator

L2 OUT C0,AL Send through output port

DEC AL Decrement contents of accumulator


Send through output port until it
JNZ L2
reaches 00
JNZ L3 Go to starting location

OUTPUT:
MEASUREMENT OF ANALOG VOLTAGE:

DIGITAL DATA ANALOG VOLTAGE

WAVEFORM GENERATION:
WAVEFORMS AMPLITUDE TIMEPERIOD

Square Waveform

Saw tooth Waveform

Triangular Waveform

MODEL GRAPH:

Result:
Thus the DAC was interfaced with 8086 and different waveforms have been
generated.
EX.NO:6 Interfacing and Programming Keyboard and Display.
AIM:
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 “
 Initialize the counter
 Set 8279 for 8 digit character display, right entry
 Set 8279 for clearing the display
 Write the command to display
 Load the character into accumulator and display it
 Introduce the delay
 Repeat from step 1.
PROGRAM:

ADDRESS LABEL MNEMONICS COMMENTS

START MOV SI,1200H Initialize array

MOV CX,000FH Initialize array size


Store the control word for
MOV AL,10
display mode
OUT C2,AL Send through output port
Store the control word to
MOV AL,CC
clear display
OUT C2,AL Send through output port
Store the control word to
MOV AL,90
write display
OUT C2,AL Send through output port

L1 MOV AL,[SI] Get the first data

OUT C0,AL Send through output port

CALL DELAY Give delay

INC SI Go & get next data


Loop until all the data’s have
LOOP L1
been taken
JMP START Go to starting location

DELAY MOV DX,0A0FFH Store 16bit count value

L2 DEC DX Decrement count value

JNZ LOOP1 Loop until count values


becomes zero
RET Return to main program

RESULT:

Thus the output for the interfacing programmable keyboard & display
controller 8279 was executed successfully.
EX.NO:7 Interfacing and Programming of Stepper Motor.
AIM:
To write an assembly language program in 8086 to rotate the motor at different speeds.

APPARATUS REQUIRED:

S.No Item Specification Quantity


1. Microprocessor kit 8086 1
2. Power Supply +5 V, dc,+12 V dc 1
3. Stepper Motor Interface board - 1
4. Stepper Motor - 1

ALGORITHM:

 For running stepper motor clockwise and anticlockwise directions


 Get the first data from the lookup table.
 Initialize the counter and move data into accumulator.
 Drive the stepper motor circuitry and introduce delay
 Decrement the counter is not zero repeat from step(iii)
 Repeat the above procedure both for backward and forward directions.

SWITCHING SEQUENCE OF STEPPER MOTOR:

MEMORY LOCATION A1 A2 B1 B2 HEX CODE

4500 1 0 0 0 09 H

4501 0 1 0 1 05 H

4502 0 1 1 0 06 H

4503 1 0 1 0 0A H

PROGRAM:
ADDRESS OPCODES MNEMONICS COMMENTS
START : MOV DI, 1200H Initialize memory location to
store the array of number
MOV CX, 0004H 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 Introduce delay


JNZ L1

INC DI Go to next memory location

LOOP LOOP1 Loop until all the data’s have


been sent
JMP START Go to start location for
continuous rotation
1200 : 09,05,06,0A
Array of data

RESULT:
Thus the assembly language program for rotating stepper motor in both clockwise
and anticlockwise directions is written and verified.
EX.NO:8 Finding number of and number of in a given 8-bit number using 8051

AIM:
To write an assembly language program in 8051 to count the number of ones(1a) and

zeros(0s) in an 8 bit binary number

APPARATUS REQUIRED:

S.No Item Specification Quantity


1. Microcontroller kit 8051 1
2. Power Supply +5 V, dc,+12 V dc 1

ALGORITHM:

 Start the program


 Load the 8 bit number into register R0.
 Initialize two counters:
o R1 0 (to count number of 1s)
o R2 0(to count number of 0s)
 Copy the value of R0 into the accumulator A.
 Set loop counter R2 0(for 8 bit processing)
 Repeat the following step 8 times (use a loop):
o Rotate the accumulator left using RLC A.
o If carry is set (c=1)
o Else (c=0)
o Decrement loop counter r3 and repeat until r3=0
 After loop ends:
o R1 will contain the number of 1s
o R2 will contain the number of 0s
 Stop the program using HLT.
PROGRAM:

ADDRESS OPCODES LABEL MNEMONICS COMMENTS


OUTPUT
START MOV R0,#5AH Load 8 bit number
INPUT : into R0
MEMORY: MOV R1,#00H Initialize 1s counter

DATA in R1
MOV R2,#00H Initialize 0s counter
OUTPUT:
in R2
NUMBER OF 1s: MOV A,R0 Move number to
NUMBER OF 0s: accumulator A
MOV R3,#08H Set loop counter in
R3
LOOP RLC A Rotate accumulator
left through carry
JC ONE If carry=1,jump to
label one
INC R2 Else increment 0s
counter
SJMP NEXT
Skip one ,go to next
ONE INC R1 Increment 1s
counter
NEXT DJNZ R3,LOOP Decrement R3 and
jump to loop if not
zero
HLT
End of program
RESULT:

Thus the assembly language program in 8051 to count the number of ones(1a) and

zeros(0s) in an 8 bit binary number is written and verified.


SIMULATION PROCEDURE

 Start the Keil software. Go to the Project > New Project then choose a
location to store your program, and give a name and Save.
 Now in the next window select the device from different manufacturers. We are
selecting Microchip, and then by expanding we are selecting AT89C51 device
and click ok.
 Now go to the File in the menu and select New. It will open a new editor to write
code.
 Go to the save option and save the program file with .asm extension.
 Write the code for 8051 Microcontroller.

 Now from the left panel, select Source Group 1, and Add Existing Files to Group ‘Source
Group 1’. Then select the program (asm file) then add and close
 Now go to the Project > Build Target to build the project. If there is some error
the building will be failed, after correcting the errors it can be build.
Ex.no:11 Programming using Arithmetic, Logical instructions of 8051 Micro controller.
Aim
To write ALP for performing Arithmetic , Logical , Bit manipulation operations
in 8051
Apparatus required
Pc with keil µvision 5 simulation tool.
Program:
1. Arithematic operations
//arithmetic operations
mov a,#25h
mov b,#12h
add a,b
mov 40h,a
mov a,#25h
subb a,b
mov 41h,a
mov a,#25h
mul ab
mov 42h,a
mov 43h,b
mov a,#25h
mov b,#12h
div ab
mov 44h,a
mov 45h,b
mov a,#25h
inc a
mov 46h,a
dec a
mov 47h,a
end
2. Logical operations:
mov r0, #0fh
mov r1, #foh
mov r2, #66h
; And operation
mov a, #ffh
anl a, r0
mov 40h, a
; Or operation
mov a, #ffh
orl a, r1
mov 41h, a
; Xor operation
mov a, 03h
mov a, #ffh
xrl a, r2
mov 42h, a
lcall 0003h
end
; clear register A
mov a, #0fh
clr a
mov 40h, a
; swap nibbles of register A
mov a, #56h
swap a
mov 41h, a
; Complement the bit of register A
mov a, #66h
cpl a
mov 42h, a
; Rotate the register contents towards right
mov a, #63h
rr a
xrl a, r
mov 43h, a
; Rotate the register contents towards left
mov a, #43h
rl a
xrl a, r
mov 44h, a
lcall 0003h
end
3. Bit manipulation operations:
Program:
MOV24H,10H;Copy item from 10H to 24H
CPL24.2;Complement bit b2
MOVC,24.5;Copy b5 to C
MOV24.4,C;Move C to b4
MOVC,24.0;Make copy of b0 to C
ORLC,/1;OR C and complement of b1
SETB24.6;Set bit b6
CLR24.3;Reset bit b3
MOV30H,24H; Store the result at 30H
HALT: SJMP HALT
Address Value

...

10H AEH

11H

...

30H 72H

31H

Result:

Thus the Arithmetic ,Logical and bit manipulation operation is done in 8051
microcontroller using simulation.
Ex.no:12 Programming and verifying Timer operation in 8051 Micro controller

Aim

To write ALP for performing Timer operation in 8051

Apparatus required

Pc with keil µvision 5 simulation tool.

PROGRAM

CLR P1.0 ;INITIALIZE PORT PIN P1.0 AS OUTPUT

MOV TMOD,#01h ;PROGRAM TMOD REGISTER FOR MODE 1 OPERATION


OFTIMER0

AGAIN:

MOV TL0,#0Ch ;LOAD LOW BYTE OF COUNT IN TIMER 0 LOW ORDER COUNT
REGISTER

MOV TH0,#0FEh ;LOAD HIGH BYTE OF COUNT IN TIMER 0 HIGH ORDER COUNT
REGISTER

CPL P1.0 ;COMPLIMENT THE PORT PIN P1.0

SETB TR0 ;SET TIMER RUN FLAG,TO START TIMER

WAIT:

JNB TF0,WAIT ;WAIT FOR TIMER OVERFLOW

CLR TR0 ;CLEAR TIMER RUN FLAG, TO STOP TIMER

CLR TF0 ;CLEAR TIMER FLAG

SJMP AGAIN ;REPEAT GENERATION OF NEXT CYCLE

END
OUTPUT

Result:

Thus the Timer operation is done in 8051 microcontroller using simulation.

You might also like