Você está na página 1de 34

1

LAB MANUAL

MICROPROCESSOR AND MICROCONTROLLERS

NEHRU COLLEGE OF ENGINEERING AND


RESEARCH CENTRE, PAMPADY
2

LIST OF EXPERIMENTS FOR MICROPROCESSOR AND


MICROCONTROLLER LAB

CYCLE 1

1 FAMILIARIAZATION OF microprocessor 8086 TRAINER


2 16 Bit BCD Addition
3 Count the occurrence of a number
4 Sorting In Ascending Order
5 GCD of two 16 bit data
6 Factorial Of A Number
7 Generation Of Prime Numbers
8 Familiarization of 8255
9 Interfacing 8086 with STEPPER MOTOR module
10 Interfacing 8086 with ADC module
11 Interfacing 8086 with DAC module

CYCLE 2
12 SUM of N Series Numbers using 8051
13 Data Transfer using 8051
14 Search for largest number using 8051
15 Print ODD or EVEN using 8051
16 BCD To HEX Conversion using 8051
17 Square wave generation using 8051
18 Interfacing DAC with 8051
19 Interfacing of keyboard with 8051
20 Interfacing of LCD with 8051
21 Serial data communication with PC

Faculty in charge HOD


3

EXPERIMENT – 1

FAMILIARIZATION OF Trainer Kit

OBJECTICVE: To familiarize 8086 trainer kit

INTRODUCTION TO M86-02
M86-02 is a single board microprocessor trainer kit configured around the
Intel’s 16 bit microprocessor 8086 .The kit has been designed to operate in the
maximum mode. The kit communicates with the outside world through an IBM
PC compatible keyboard with 20X2 LCD display. The kit also has the capacity of
interacting with PC.
M86-02 is packed up with powerful monitor in 16K bytes of factory
programmed EPROMS and 16KB of read /writes memory. The total memory on
the board can be expanded to 256 Kbytes system has 72 programmable I/O
lines. The serial I/O communication is made possible through 8251.

SYSTEM CAPABILITIES:
1 Examine /modify the memory location.
2 Examine/modify any of internal register of 8086
3 Move a block of data /program from one location to another location
4 Fill a particular memory area with a constant
5 To execute the program in full clock speed
6 To execute program in single instruction execution

OPERATING COMMANDS

A - Assemble
D - Display/modify the RAM’s hexadecimal
F - Fill data in to the RAM
G - Proceed to the address for execution
I - Interrupt
M - Moving data
P - Print
T - Trace program
U - Unassembled

Result and Discussion:

Conclusion
4

EXPERIMENT – 2
16 BIT BCD ADDITION

OBJECTICVE:
To write an assembly language program to add two 16 bit BCD numbers

ALGORITHM
1. Load the address of data in SI register.
2. Clear CL register for account for carry
3. Load the first data in AX register and the second data I BX register.
4. Perform binary addition of low byte of data to get the sum in AL
register.
5. Adjust the sum of low bytes to BCD.
6. Save the sum of low bytes in DL register.
7. Get the high byte of first data in AL register.
8. Add the high byte of second data and previous carry to AL register
Now the sum of high bytes will be in AL register
9. Adjust the sum of high bytes to BCD
10. Save the sum of high bytes in DH register
11. Check for carry .If carry flag is set then go to the next step, otherwise
go to step 13
12. Increment CL register
13. Save the sum (DX register) in memory
14. Save the carry (CL register) in memory.
15. Stop.

PROGRAM

ADDRESS LABEL OPCODE MNEMONICS COMMENT

Set SI register as
BE3000 MOV SI,3000
pointer
B100 MOV CL,00 Clear CL register
Get first data in AX
8B04 MOV AX,[SI]
register
Load the second
8B 5C 02 MOV BX, [SI+2]
data I BX register
get the sum of low
02 C3 ADD AL, BL byte of data in AL

Adjust the sum of low


27 DAA bytes to BCD.

8A D0 MOV DL,AL Save the sum of low


bytes in DL register.
5

register.,

MOV the high byte


8A C4 MOV AL,AH of data to AL register

Get the sum of high


bytes will be in AL
12 C7 ADC AL,BH
register

Adjust the sum to


27 DAA BCD.

Save the sum of high


88 4C06 MOV DH,AL bytes in DH register

73 02 JNC AHEAD Check for carry flag


If carry flag is set
FE C1 INC CL then increment CL
by one
Store the sum in
AHEAD 895404 MOV [SI+4],DX
memory
Store the carry in
MOV [SI+6],CL
memory
Stop the program
CC INT03

Result and Discussion:

Conclusion:
6

EXPERIMENT -3

COUNT OCCURANCE OF A NUMBER

OBJECTICVE :

To write an assembly language program to count the occurrance of a given


number.

ALGORITHM

1. Start
2. Get SI and DI registers as pointers for source and destination
3. Get the CL and BL registers are cleared.
4. Move the contents of SI to CL and increment the SI once.
5. Move the contents of SI to AL
6. Increment the SI reg.
7. Check whether the contents of SI and AL are same or not, if yes goto step
8
else goto step 9
8. Increment BL reg
9. Return to step 6 until SI is incremented the number of times equal to the
size
of the array. Repeat step 9.
10. Move the contents of BL to the destination reg DI
11. Stop.

PROGRAM:

ADDRESS LABEL OPCODE MNEMONICS COMMENT

BE 0010 MOV SI,1000 Set SI as pointer


Set DI as pointer for
BF 0020 MOV DI,2000
result
B500 MOV CL,00 Clear CL register
Clear BL register
B300 MOV BL,00
Move the contents of
8A0C MOV CL,[SI]
SI to BL
46 INC SI Increment the SI reg
Compare the
8A04 MOV AL,[SI]
contents of SI and AL
46 Increment the SI reg
LII INC SI
3804 CMP [SI],AL Compare the
7

contents of ALand SI
If not equal ,jump to
7502 JNE LI
LI
Increment BL
FEC3 INC BL
register.
Continue with loop
LI E2F7 LOOP LII
LII
Move the contents of
881D MOV [DI],BL
BL to DI register
CC INT 03 Stop the program

Result and Discussion

Conclusion:
8

EXPERIMENT - 4

(a) SORTING AN ARRAY IN ASCENDING ORDER

OBJECTICVE
:
To write an assembly language program to sort an array of data in ascending
order.

ALGORITHM
1. Load the starting address of the array in SI register.
2. Set CL register as count forN-1 repetition
3. Initialize array pointer
4. Set CH register as count for N-1 comparisons
5. Increment array pointer
6. Compare the next element of array with AL
7. Check the carry flag, If carry flag is set then go to step 12 otherwise
go to next step.
8. Exchange the content of memory pointed by SI and AL register
9. Decrement the count for comparison (CH register)
10. Check zero flag, If zero flag is reset then go to step6, otherwise go to
next step
11. Decrement the count for repetition (CL register)
12. Check zero flag, If zero flag is reset then go to step3, otherwise go to
next step
13. Stop the program

PROGRAM:

ADDRESS LABEL OPCODE MNEMONICS COMMENT

Set SI register as
BE 00 70 MOV SI,0700
pointer
8A 0C MOV CL,[SI] Set CL as count
Decrement the count
FE C9 DEC CL
Set SI register as
REP BE 00 70 MOV SI,0700
pointer
Set CH register as
counter for N-1
8A 2C MOV CH , [SI]
comparisons

Decrement the count


of N-1 comparisons
FE CD DEC CH
9

Increment the pointer


46 INC SI
Get the element of
STORE 8A 04 MOV AL,[SI] array in CL register

Increment the pointer


46 INC SI
Compare with next
3A 04 CMP AL,[SI] element of array in
memory
If AL is less than
72 05 JC AHEAD memory then go to
AHEAD
If AL is not less than
memory then
86 04 XCHG AL,[SI] exchange the content
of memory and AL
register
Decrement the
4E DEC SI
pointer
8A 04 MOV [SI] , AL
46 INC SI
Decrement the count
AHEAD FE CD DEC CH
for comparisons
Repeat the
75 F0 JNZ STORE comparisons until CH
is zero
Decrement the count
FE C9 DEC CL
for repeatations
Repeat the N-
75 E4 JNZ REP 1comparisons until
CL is zero
Stop the program
CC INT03

Result and Discussion:

Conclusion:
10

EXPERIMENT – 5

GCD OF TWO 16 BIT DATA

OBJECTICVE :

To write an assembly language program to determine the GCD of two 16-bit


data..

ALGORITHM
1. Set BX as pointer for input data.
2. set DI as pointer for result
3. get one data in AX reg
4. get another data in CX reg
5. Compare the two data
6. Check zero flag. if zero flag is set then go to step 14,otherwise go to next
step.
7. Check carry flag .if zero is reset then go to step 9, otherwise go to next
step.
8. Exchange the content of AX and BX, so that the larger among the two is
dividend and smaller is the divisor.
9. clear the DX reg
10. Divide AX reg by CX reg.
11. Compare DX reg with 0000H.
12. Check zero flag .if zero flag is set then go to step 14, otherwise go to next
step.
13. Move the remainder to AX and go to step 5
14. Save the contents of CX register as GCD in memory.
15. Stop.

PROGRAM:

ADDRESS LABEL OPCODE MNEMONICS COMMENT

Set BX register as
BB 1100 MOV BX,1100
pointer
Set DI as pointer fo
BF 1200 MOV DI,1200
result
Get the first data in
8B 07 MOV AX, [BX]
AX
Get second data in
8B 4F 02 MOV CX, [BX+02]
CX
Compare the two
RPT 3B C2 CMP AX, CX
data
74 11 JE STORE If the two data are
11

equal, store cx as
GCD
If AX is greater tha
73 01 JNC SKIP CX, then go to sep
skip
If AX is less than
91 XCHG AX, CX CX,then exchange
AX and CX
SKIP BA 0000 MOV DX,0000
F7 F1 DIV CX
Check whether
83 FA 00 CMP DX,00
reminder is zero
If zero, then set CX
74 04 JE STORE
as GCD
If reminder is not
BB C2 MOV AX, DX zero, move reminder
to AX
Repeat comparison
EB EB JMP RPT
and division
STORE 89 0D MOV [DI], CX Store CX as GCD
CC INT 03 Stop the program

Result and Discussion:

Conclusion:
12

EXPERIMENT - 6

(a) FACTORIAL OF 8 BIT DATA


OBJECTICVE
To write an assembly language program to determine the factorial of 8 bit
data

ALGORITHM
1. Set SI register as pointer for data.
2. Get the data in AL register and clear AH register to convert the data to 16
bit.
3. Clear BP register to keep initial value of second word of final product as
zero.
4. Compare AX register with 01
5. Check zero flag, If zero flag is set then go to step19, otherwise go to next
step
6. Set CX register as count forN-1 multiplications
7. Move AX and BX register ,so that the initial multiplier in BX is the given
data
8. Decrement the multiplier ,(BX)
9. Multiply AX and BX to get the product in AX and DX
10. Save the product1 in stack
11. Load the second word of previous product in BP to Ax
12. Multiply AX and BX to get the product2 in AX and DX
13. Get the upper word of product1 in DX
14. Add AX and DX to get the second word of final product in AX
15. Move AX to BP to save the the final product in BP
16. Get the first word of product in Ax
17. Decrement multiplication counter
18. If CX is not zero, then go step8,otherwise go to next step.
19. Store AX and BP in memory locations
20. Stop the program

PROGRAM:

ADDRESS LABEL OPCODE MNEMONICS COMMENT

Set SI register as
BE 00 70 MOV SI,0700
pointer
8A 04 MOV AL,[SI] Get data in AL
B4 00 MOV AH,00 Clear AH register
Initialize the upper
BD 00 00 MOV BP,0000
word of result as zero
Check whether data is
3D 0001 CMP AX, 0001 01
13

If data is 01,then store


7E 16 JNG STORE 01 as factorial

SetCX as counter for


number of
8B D8 MOV CX,AX
multiplications.

49 DEC CX Decrement the count


Set the data as
8B D8 MOV BX,AX
multiplier
Decrement the
REP 4B DEC BX
multiplier
Get the product1 in AX
F7 E3 MUL BX
and DX
Save the lower word of
50 PUSH AX
product1 in stack
Save the upper word of
52 PUSH DX
product1 in stack
8B C5 MOV AX,BP
Get the product1 in AX
F7 E3 MUL BX
and DX
Get the upper word of
5A POP DX
product1 in DX
Get the sum of upper
word product1 and
03 C2 ADD AX,DX
lower word of
product2
Set the sum as second
8B E8 MOV BP,AX
word of result
Set the lower word of
58 POP AX product 1 as first word
of result
Repeat multiplication
E2 EF LOOP Rep
until count is zero
Store the lower word of
STORE 89 44 01 MOV [SI+1],AX
result in memory
Store the upper word
89 6C 03 MOV [SI+3],BP
of result in memory
Stop the program
CC INT03

Result and Discussion:


Conclusion:
14

EXPERIMENT – 7

GENERATION OF PRIME NUMBERS

OBJECTICVE

To write an assembly language program to generate all possible prime


numbers less than the given data.

ALGORITHM
1. Set SI register as pointer for data.
2. Load the given data in CL register.
3. Set as pointer for the result.
4. Initialize the number to check as 01 in BL register.
5. Save 01 as first prime number.
6. Increment the result pointer(DI)
7. Increment the number to be checked(BL).
8. Load the initial divisor 02 in CL register.
9. Compare CL and BL registers.
10. Check zero flag. If zero flag is set then go to step 16, otherwise go to
next step.
11. Clear AH register and load the number to be checked in AlL register.
12. Divide AX by CL register.
13. Compare the reminder (AH) with zero.
14. Check zero flag. If zero flag is set then go to step 18, otherwise go to
next step
15. Increment the divisor and go to step 9
16. Save the prime number.
17. Increment the result pointer (DI).
18. Increment the number to be checked (BL).
19. Compare DL and BL registers
20. Check zero flag. If zero flag is reset then go to step 8, otherwise stop

PROGRAM:

ADDRESS LABEL OPCODE MNEMONICS COMMENT

Set SI register as
BE 00 70 MOV SI,0700 pointer for end data
N
Get data N in DL
8A 14 MOV DL,[SI]
register
Get DI as pointer
BF 12 00 MOV DI,1200 for storing prime
numbers
B3 01 MOV BL,01 Initialize the
15

number to 01
Save the first prime
88 1D MOV [DI],BL number

Increment the
47 INC DI address pointer

Increment BL
FE C3 INC BL
Set initial divisor as
GEN B1 02 MOV CL,02
02
If BL=CL,jump to
REP 3A D9 CMP BL,CL
store
Decrement the
74 0F JZ STORE
multiplier
B4 00 MOV AH,00 Clear AH register
Set the number to
8A C3 MOV AL,BL be checked as
dividend
F6 F1 52 DIV CL
Check whether the
80 FC 00 CMP AH,00
reminder is zero
If reminder is not
74,07 JZ NEXT zero, then
increment
FE C1 INC CL
The divisor and
EB ED JMP REP
jump to REP
Save the prime
STORE 88 1D MOV [DI],BL
number
Increment address
47 INC DI
pointer
Increment the
NEXT FE C3 INC BL number to be
checked
Check whether the
number to be
checked is not
3A DA CMP BL,DL
equal to N,then
continue generation
,otherwise stop
JNE GEN
INT 03

Result and Discussion

Conclusion:
16

EXPERIMENT – 8

FAMILIARISATION OF 8255

OBJECTIVE:
To familiarize 8255
ALGORITHM
1. Load AL with 80 to set the control word
2. Move the content of AL to control register
3. Load AL with 00
4. Load the content AL register to port A
5. Call Delay subroutine(step 8)
6. Increment AL
7. Jump to step 4
8. Load CX register with 6F
9. Decrement CX
10. Compare with zero ,if not equal jump to step 9 else next step
11. Return

PROGRAM

ADDRESS LABEL OPCODE MNEMONICS COMMENT

MOV AL,80 Initialize 8255


Input the
OUT 76,AL control word to
control reg.
Clear AL
START MOV AL, 00
register
out that to
L1 OUT 70,AL output port A

CALL DELAY Call subroutine


INC AL Increment AL
JMP L1
DELAY MOV CX,6F
L2 DEC CX Decrement Cx
JNE L2
RET

Result and Discussion

Conclusion:
17

EXPERIMENT - 9

INTERFACING STEPPER MOTOR WITH 8086

OBJECTICVE: To rotate a stepper motor in anticlockwise direction

ALGORITHM

1. Load AL with 80 to set the control word


2. Move the content of AL to control register
3. Load AL with data FA and move that to Port A for rotation
4. Call the delay sub routine
5. Load AL with data F6 and move that to Port A for rotation
6. Call the delay sub routine
7. Load AL with data F5 and move that to Port A for rotation
8. Call the delay sub routine
9. Load AL with data F9 and move that to Port A for rotation
10. Call the delay sub routine
11. Jump to step 3

PROGRAM:

ADDRESS LABEL OPCODE MNEMONICS COMMENT

Input the control


B0 80 MOV AL,80 word

Out the control


E6 76 OUT 76,AL word to port

Load the first data


START B0 FA MOV AL, FA in AL

Move the data to


E6 70 OUT 70,AL output port

Call the delay sub


E8 04 22 CALL DELAY1 routine

Load the next data


B0 F6 MOV AL, F6 in AL
18

Move the data to


E6 70 OUT 70,AL output port

Call the delay sub


E8 04 22 CALL DELAY1 routine

Load the next data


B0 F5 MOV AL, F5 in AL

Move the data to


E6 70 OUT 70,AL output port

Call the delay sub


E8 04 22 CALL DELAY1 routine

Load the next data


B0 F9 MOV AL, F9 in AL

Move the data to


E6 70 OUT 70,AL output port

Call the delay sub


E8 04 22 CALL DELAY routine
Jump to the label
EB E2 JMP START start for repeat

Move count to CX
DELAY1 B9 00 08 MOV CX,800 register
Decrement count
LP1 49 DEC CX in CX

If not zero, then


75 FD JNZ LP1 jump to label LP1.

Stop the program


C3 RET

Result and Discussion:

Conclusion
19

EXPERIMENT - 10

INTERFACING D/A CONVERTER WITH 8086

OBJECTICVE:
To generate triangular waveform using DAC

ALGORITHM:
1. Initialize the control port
2, Input the control word to assign all ports as output ports
3. Initialize port A
6. Clear AL register and out that to output port A
7. Increment AL register and out to output port A
8. Compare AL with BL
9. IF zero flag is reset then go to step7 otherwise go to next step
10. Decrement AL register and out to output port
11. Compare AL with 00
12. IF zero flag is set then go to step 6otherwise go to step10

PROGRAM:

ADDRESS LABEL OPCODE MNEMONICS COMMENT

BA E6 FF MOV AL,80 Initialize 8255


Input the
E6 76 OUT 76,AL control word to
control reg.
Clear AL
START B0 FA MOV AL, 00
register
out that to
L1 E6 70 OUT 70,AL output port A

E8 04 22 INC AL
B0 F6 CMP AL,0FF
E6 70 JNE L1
L2 E8 04 22 DEC AL
B0 F5 OUT 70,AL
E6 70 CMP AL,00
E8 04 22 JNE L2
B0 F9 JMP START

Result and Discussion:


Conclusion
20

EXPERIMENT - 11

INTERFACING A/D CONVERTER WITH 8086

OBJECTICVE:
To interface analog to digital with 8086

ADC 0809 A/D card is an 8 bit analog to digital converter with 8 channel
multiplexer and microprocessor compatible control logic. The data line of ADC
809 D0 to D7 is connected to portA as input port .SOC is connected to PC0 as
output port. EOC is connected to PC1=4 as input port and ALE is connected to
PC1 as output port. All 8 inputs of 0-5V ADC-809 analog with external clock,
external EOC, external SOC signals are brought to 26 pin connector
.
ALGORITHM:

1. Load the control word into AL register


2, Input the control word to control register
3. load Al with 00 and move that data to port c for resetting port.
4. Load Al with 03 and move to port C to activate SOC and ALE
5. again load 00 to AL to make SOC low
6. Read port C and AND the data in AL with 10 to check the end of converse\ion
7. If result is zero jump to step 6, otherwise next step
8. Load AL with 04 to enable OE pin and move the data to port C
9. Read the data in port A to AL register
10. stop the program.

PROGRAM:

COMMENT
ADDRESS LABEL OPCODE MNEMONICS

Set Control
B0 98 MOV AL ,98
Word
Input control
word to control
E6 76 OUT 76, AL
register

Select channel
START B0 00 MOV AL, 00

E6 74 OUT 74,AL
21

MOV AL, 00 load Al with 00


B0 00
move that data
E6 74 OUT 74,AL
to port c for
resetting
Give SOCport.
and
B0 03 MOV AL, 03
ALE high

E6 74 OUT 74,AL

MOV AL, 00 Give SOC low


B0 00

E6 74 OUT 74,AL
Read EOC
EOC E4 74 IN AL ,74
Check EOC
24 10 AND AL,10

74 FA JZ EOC
MOV AL, 04 Set OE high
B0 04

E6 74 OUT 74,AL
IN AL,70 Read data
E4 70
Stop
CC INT 03

Result and Discussion:

Conclusion:

EXPERIMENT – 12
22

SUM of N Series NUMBERS using 8051

OBJECTICVE:
To add a series of N numbers by using 8051 trainer

ALGORITHM:
1. Initialize the memory location.
2. Move contents from memory location to accumulator.
3. Copy the content of accumulator to register B
4. Increment accumulator
5. Multiply the content of registers A &B
6. Move the data 02 to register B
7. Divide the accumulator by the content of register B
8. Stop the program

PROGRAM:

ADDRESS LABEL OPCODE MNEMONICS COMMENT

Initialize the
MOV DPTR,#4000 memory location
Move contents from
memory location to
MOVX A, @ DPTR
accumulator.

Copy the content of


MOV B,A
A to B
Increment A
INC A

MUL AB Multiply A and B


MOV B,#02 Copy 02 to B
DIV AB Divide A by B

STOP SJMP STOP

Result and Discussion:


Conclusion
EXPERIMENT – 13
23

SEARCH LARGEST NUMBER IN AN ARRAY

OBJECTICVE:

To search largest number in the given array

ALGORITHM:

1. Initialize the memory location


2. Move contents from memory location to accumulator
3. Copy the content of memory location to register R0
4. Decrement the content of R0
5. Increment the memory location
6. Copy the content of memory location to accumulator
7. Copy the content of accumulator to register R4
8. Increment the memory location
9. Copy the content of memory location to accumulator
10. Copy the content of accumulator to register R2
11. Clear Carry Flag
12. Subtract the value of R4 from accumulator
13. Check for Carry
14. Copy the content of R2 to accumulator
15. Copy the content of accumulator to register R4
16. Decrement the content of R0 and compare with zero
17. Point to new address location for output
18. Copy the content of R4 to accumulator
19. Copy the content of accumulator to data pointer
20. Stop the program

PROGRAM

ADDRESS LABEL OPCODE MNEMONICS COMMENT

MOV DPTR,#4000 Initialize data pointer


copy the content of
MOVX A,@DPTR data pointer to
accumulator

MOV R0,A copy the content of


data pointer to register
24

R0
Decrement the
content of R0
DEC R0

INC DPTR increment data pointer

copy the content of


MOVX A,@DPTR data pointer to
accumulator
Copy the content of
accumulator to
MOV R4,A register R4

LOOP1: increment data pointer


INC DPTR

copy the content of


data pointer to
MOVX A,@DPTR accumulator

Copy the content of


accumulator to
MOV R2,A register R2

Clear carry flag


CLR C
Subtract the value of
R4 from the
SUBB A,R4 accumulator

Check for carry,if


carry,jump to the label
LOOP2, otherwise
JC LOOP2 next step

Copy the content ofR2


MOV A,R2 to accumulator

Copy the content of


accumulator to
MOV R4,A register R4

DJNZ R0,LOOP1 Decrement the


content of R0 and
compare with zero. if
25

LOOP2: not zero, jump to label


LOOP1,otherwise next
step

Point DPTR to another


location for output
MOV DPTR, #4500

Copy the content ofR4


to accumulator
MOV A,R4

copy the content of


accumulator to data
pointer
MOVX @ DPTR,A

STOP Stop the program


SJMP STOP

Result and Discussion:

Conclusion

EXPERIMENT -14

DATA TRANSFER
26

OBJECTIVE:

To transfer a set of data to another location

ALGORITHM

1. Initialize the memory location


2. Copy the data to register R4
3. Copy the second data to register Ro
4. Copy the content of memory location to accumulator
5. Copy the content of accumulator to register R0
6. Increment R0
7. Increment memory location
8. Decrement the count jump if not zero, go to step 4
9. Point DPTR to new address location
10. Move the first data to register R3
11. Move the second data to register R0
12. Copy the content of register R0 to accumulator
13. Increment Ro
14. Increment DPTR
15. Decrement the count and jump if not zero,go to step 12
16. Stop

PROGRAM

ADDRESS LABEL OPCODE MNEMONICS COMMENT


MOV DPTR,#4000 Initialize the memory
location
MOV R4,#0A Load 0A to register R4

MOV R0,#40 Load 40 to register R0

LOOP1 MOVX A,@DPTR Copy the content of DPTR


to accumulator
MOV @R0,A Copy the value of
accumulator to R0
INC R0 Increment R0

INC DPTR Increment DPTR


27

DJNZ R4,LOOP1 Decrement the content of


R4 and compare with
zero,if not zero jump to
loop1,otherwise next step
MOV DPTR,#4300 Point DPTR to new
address location
MOV R3,#0A Load 0A to register R3

MOV R0,#40 Load 40 to register R0

MOV A,@R0 Copy the content of R0 to


LOOP2 accumulator
MOVX @DPTR,A Move the content of
accumulator to DPTR
INC R0 Increment R0

INC DPTR Increment DPTR

DJNZ R3,LOOP2 Decrement the content of


R4 and compare with zero
,if not zero jump to
loop2,otherwise next step
STOP SJMP STOP Stop the program

Result and Discussion:

Conclusion

EXPERIMENT-15

PRINT ODD OR EVEN


28

OBJECTIVE:
To print the given number is odd or even
ALGORITHM
1. Call the subroutine 0AC1(subroutine for reading address)
2. Increment DPTR
3. Copy the content of DPTR to A
4. OR the content of register A with data FE
5. Compare the content of A with data FE,if it is equal jump to step 8
otherwise next step
6. Copy the content of label MSG2 to DPTR
7. Jump to step 9
8. Copy the content of label MSG1 to DPTR
9. Call the subroutine 0A3C(subroutine for display)
10. Stop the program

PROGRAM

ADDRESS LABEL OPCODE MNEMONICS COMMENT


START LCALL 0AC1 Call the subroutine
0AC1
INC DPTR Increment DPTR

MOVX A ,@DPTR Copy the content of


DPTR to A
ORL A,#0FE OR the content of
register A with data FE
CJNE A,#0FE,ODD Compare the content
of A with data FE
MOV Copy the content of
DPTR,#MSG2 label MSG2 to DPTR

SJMP DISP
Display even or odd
ODD MOV DPTR Copy the content of
#MSG1 label MSG1 to DPTR
DISP LCALL 0A3C Subroutine for display

HERE SJMP HERE Stop


29

MSG1
4E,55,4D,42,45,52,20,49,53,20,4F,44,44,20,20,20,20,20,20,20

MSG 2
4E,55,4d,42,45,52,20,49,53,20,45,56,45,4E,20,20,20,20,20,20

Result and Discussion:

Conclusion
30

EXPERIMENT – 16

BCD TO HEXADECIMAL CONVERSION

ALGORITHM

1 Initialize the memory location


2 Copy the data to register A
3 Copy the data to register R5
4 And the content of accumulator with data 0F0
5 Rotate the data towards right 4 times for interchanging nibbles.
6 Copy the content of accumulator to register R1
7 Copy the content of R5 to accumulator
8 And the content of accumulator with data 0F
9 Copy the content of accumulator to register R2
10 Copy the content of register R1 to accumulator
11 Copy the data 0A to register B.
12 Multiply accumulator with B to get the value of 10 th position
13 Add accumulator with register R2
14 Increment DPTR
15 Copy the content of accumulator to DPTR
16 Stop

PROGRAM

ADDRESS LABEL OPCODE MNEMONICS COMMENT


MOV DPTR,#4000 Initialize the memory
location
MOVX A,@DPTR Copy the content of
DPTR to accumulator
MOV R5,A Copy the content of A
to R5
ANL A,#0F0 And the data in A with
F0
Rotate right the data in
RRA
A
RRA

RRA

RRA
MOV R1,A Copy the content of
accumulator to register
31

R1

MOV A,R5

ANL A,#0F
Copy the content of
MOV R2,A accumulator to register
R2
Add accumulator with
MOV A,R1
register R2
Copy the data 0A to
MOV F0,#0A register B.

Multiply accumulator
MUL AB with B to get the value
of 10th position
Add accumulator with
ADD A,R2
register R2
INC PTR Increment DPTR

MOVX @PTR,A

STOP SJMP STOP

Result and Discussion:

Conclusion
32

EXPERIMENT-17
SQUARE WAVE GENERATION USING 8051

OBJECTIVE:

To generate a square wave using 8051

ALGORITHM

1. Complement port 1
2. Call delay subroutine
3. Jump to step 1
4. Copy the data 0F9 to register R2
5. Decrement the data until become zero
6. Return

PROGRAM

ADDRESS LABEL OPCODE MNEMONICS COMMENT

REPT Complement
CPL P1.0
Port 1
LCALL DELAY Call delay
SJMP REPT Jump to label
Copy 0F9 to
MOV R2,#0F9
register R2
L1 DJNZ R2,L1 Decrement R2
RET

Result and Discussion:

Conclusion
33

EXPERIMENT - 18

INTERFACING D/A CONVERTER WITH 8051

OBJECTICVE:
To generate sine wave using DAC in 8051

ALGORITHM:

1. Initialize the control port


2. Input the control word to assign all ports as output ports
3. Load DPTR with a external memory location
4. Load R1 register with number of samples to be taken
5. Load that data to accumulator
6. Load the first sample to register A
7. Point DPTR to the address of Port C
8. Load the content of Register A to Port C
9. Point DPTR to the external memory location
10. Decrement R1 and if not zero, then jump to step 5
11. If zero, then jump to step 4

PROGRAM:

ADDRESS LABEL OPCODE MNEMONICS COMMENT

Initialize the control


MOV DPTR, #0FF03
port
MOV A, #80 Input the control word
MOVX @DPTR,A
Load DPTR with a
MOV DPTR,#4000 external memory
location
Load R1 register with
rep MOV R1, #3C
number of samples
. Load that data to
nxt MOV A, R1
accumulator
MOVC A, Load the first sample
@A+DPTR to register A
34

MOV DPTR,#0FF00 Point DPTR to the


address of Port C

MOV @DPTR,A Load the content of


Register A to Port C

MOV DPTR,#4000
DJNZ R1, nxt Decrement R1 and if not
zero, then jump to step 5

SJMP rep If zero, then jump to step 4

Result and Discussion:

Conclusion

Você também pode gostar