8051 Programs With Opcode
8051 Programs With Opcode
APPROVED BY
PREPARED BY
Prof. B. REVATHI
HOD/ECE
III YEAR
Preface
This laboratory manual is prepared by the Department of Electronics and communication
engineering for microprocessor and microcontroller lab (EC 2308). This lab manual can be used as
instructional book for students, staff and instructors to assist in performing and understanding the
experiments. This manual will be available in electronic form from Colleges official website, for
the betterment of students.
Acknowledgement
We would like to express our profound gratitude and deep regards to the support offered
by the Chairman Shri. A.Srinivasan. We also take this opportunity to express a deep sense of
gratitude to our Principal Dr.B.Karthikeyan,M.E, Ph.D, for his valuable information and
guidance, which helped us in completing this task through various stages. We extend our hearty
thanks to our head of the department Prof.B.Revathi M.E, (Ph.D), for her constant
encouragement and constructive comments.
Finally the valuable comments from fellow faculty and assistance provided by the
department are highly acknowledged.
ISSUE: 01 REVISION: 00
III YEAR
INDEX
S.No
1
2
3
TOPIC
PAGE
NO
Syllabus
Lab Course Handout
Experiments
5
6
13
3. Programs to sort the numbers in ascending and descending order using 8086 17
4. Programs to find largest and smallest numbers using 8086
21
25
28
31
34
40
43
47
51
55
59
62
64
66
68
19. Programs for digital clock and stop watch (using 8086)
70
72
ISSUE: 01 REVISION: 00
III YEAR
microcontroller
75
Kit & pc
ISSUE: 01 REVISION: 00
III YEAR
SYLLABUS
EC2308
1.
2.
3.
4.
5.
6.
10.
Description of Equipments
8086 Trainer
8051 Trainer
8255 Interfacing Card
8279 Interfacing Card
8259 Interfacing card
8251 Interfacing Card
ADC Interfacing card
DAC Interfacing Card
Stepper motor Interfacing card
DC motor Interfacing card
ISSUE: 01 REVISION: 00
Quantity
15
15
3
3
3
3
3
3
3
3
III YEAR
: EC 2308
Subject Title
Staff name
S.No
Topics to be covered
Learning objectives
Page
No*
No. of
hours
3 hrs
17
3hrs
25
3hrs
31
3hrs
40
3hrs
43
3hrs
51
3hrs
ISSUE: 01 REVISION: 00
III YEAR
51
3hrs
66
3hrs
10
68
3hrs
11
70
3hrs
12
75
3hrs
Evaluation
Components
Duration
Weightage
Observation
Continuous
20%
Record
Continuous
30%
Attendance
Continuous
30%
Model lab
3hr
20%
Timings for chamber consultation: Students should contact the Course Instructor in her/his
chamber during lunch break.
ISSUE: 01 REVISION: 00
III YEAR
STUDENTS GUIDELINES
There are 3 hours allocated to a laboratory session in Microprocessor and microcontroller lab.
It is a necessary part of the course at which attendance is compulsory.
Here are some guidelines to help you perform the Programs and to submit the reports:
1.
2.
3.
4.
5.
6.
STAFF SIGNATURE
ISSUE: 01 REVISION: 00
HOD
III YEAR
8086 PROGRAMMING
ADDITION & SUBTRACTION
AIM:
To write an Assembly Language Program (ALP) for performing the addition and subtraction
operation of two byte numbers.
APPARATUS REQUIRED:
8086 trainer kit
ALGORITHM:
(i) 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.
(ii) 16-bit subtraction
Initialize the MSBs of difference to 0
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.
ISSUE: 01 REVISION: 00
III YEAR
FLOW CHART
ADDITION
SUBTRACTION
START
START
SUBTRACT
SECOND OPERAND
FROM MEMORY
A=A+B
YES
IS THERE ANY
CY
IS THERE ANY
CARRY
YES
NO
COUNTER =
COUNTER + 1
COUNTER =
COUNTER + 1
STORE THE
DIFFERENCE
NO
STORE THE SUM
ISSUE: 01 REVISION: 00
10
III YEAR
ADDITION
PROGRAM
COMMENTS
Initialize counter CX
MOV AX,[1200]
ADD AX,BX
JNC L1
INC CX
L1 : MOV [1206],CX
MOV [1204], AX
HLT
SUBTRACTION
PROGRAM
COMMENTS
Initialize counter CX
MOV AX,[1200]
SUB AX,BX
JNC L1
INC CX
L1 : MOV [1206],CX
MOV [1204], AX
HLT
ISSUE: 01 REVISION: 00
11
III YEAR
RESULT:
Thus the program for 16-bit addition and subtraction was verified
VIVA QUESTIONS:
1. What is Microprocessor ?
It is a program controlled semiconductor device (IC}, which fetches, decode and executes
instructions.
2. What is assembly language?
The language in which the mnemonics (short -hand form of instructions) are used to write a
program is called assembly language. The manufacturers of microprocessor give the mnemonics
3. Define bit, byte and word.
A digit of the binary number or code is called bit. Also, the bit is the fundamental storage unit of
computer memory. The 8-bit (8-digit) binary number or code is called byte and 16-bit
binary number or code is called word. (Some microprocessor manufactures refer the basic data
size operated by the processor as word)
ISSUE: 01 REVISION: 00
12
III YEAR
8086 PROGRAMMING
MULTIPLICATION & DIVISION
AIM:
To write an Assembly Language Program (ALP) for performing the multiplication and division
operation of 16-bit numbers.
APPARATUS REQUIRED:
8086 TRAINER KIT
ALGORITHM:
(i)
(ii)
ISSUE: 01 REVISION: 00
13
III YEAR
FLOW CHART
MULTIPLICATION
DIVISION
Start
Start
QUOTIENT = 0
REGISTER=0
0
DIVIDEND =
DIVIDEND-DIVISOR
REGISTER = REGISTER
+ MULTIPLICAND
QUOTIENT = QUOTIENT+1
Multiplier=MUL
TIPLIER 1
IS
DIVIDEND
< DIVISOR
NO
NO
IS
MULTIPLIER
DIVISOR
YES
=0?
STORE QUOTIENT
YES
STORE REMAINDER
STORE THE RESULT
= DIVIDEND NOW
STOP
STOP
ISSUE: 01 REVISION: 00
14
III YEAR
MULTIPLICATION
PROGRAM
COMMENTS
MOV AX,[1200]
MUL BX
Multiply both
MOV [1206],AX
MOV AX,DX
MOV [1208],AX
HLT
DIVISION
PROGRAM
COMMENTS
MOV AX,[1200]
DIV BX
MOV [1206],AX
MOV AX,DX
MOV [1208],AX
HLT
RESULT:
Thus the program for 16-bit multiplication and division was verified
ISSUE: 01 REVISION: 00
15
III YEAR
VIVA QUESTIONS:
1. What is the function of microprocessor in a system?
The microprocessor is the master in the system, which controls all the activity of the system. It
issues address and control signals and fetches the instruction and data from memory. Then it
executes the instruction to take appropriate action.
.
2. Define mnemonics.
The short-hand form of describing the instructions are called mnemonics. The mnemonics are
given by the manufacturers of microprocessors and programmable devices.
3. What is the need for timing diagram?
The timing diagram provides information regarding the status of various signals, when a machine
cycle is executed. The knowledge of timing diagram is essential for system designer to select
matched peripheral devices like memories, latches, ports, etc., to form a
microprocessor system
ISSUE: 01 REVISION: 00
16
III YEAR
8086 PROGRAMMING
ASCENDING & DESCENDING
AIM:
(ii)
ISSUE: 01 REVISION: 00
17
III YEAR
ASCENDING
PROGRAM
COMMENTS
MOV SI,1200H
MOV CL,[SI]
Number of comparisons in CL
L4 : MOV SI,1200H
MOV DL,[SI]
INC SI
MOV AL,[SI]
L3 : INC SI
MOV BL,[SI]
CMP AL,BL
JNB L1
If AL < BL go to L1
DEC SI
MOV [SI],AL
MOV AL,BL
JMP L2
Jump to L2
L1 : DEC SI
MOV [SI],BL
L2 : INC SI
DEC DL
JNZ L3
MOV [SI],AL
DEC CL
JNZ L4
HLT
Stop
DESCENDING
PROGRAM
COMMENTS
MOV SI,1200H
MOV CL,[SI]
Number of comparisons in CL
L4 : MOV SI,1200H
MOV DL,[SI]
ISSUE: 01 REVISION: 00
18
MOV AL,[SI]
L3 : INC SI
MOV BL,[SI]
CMP AL,BL
JB L1
If AL > BL go to L1
DEC SI
MOV [SI],AL
MOV AL,BL
JMP L2
Jump to L2
L1 : DEC SI
MOV [SI],BL
L2 : INC SI
DEC DL
JNZ L3
MOV [SI],AL
DEC CL
JNZ L4
HLT
Stop
III YEAR
RESULT:
Thus the program for sorting the data inascending and descending order was verified
ISSUE: 01 REVISION: 00
19
III YEAR
VIVA QUESTIONS:
ISSUE: 01 REVISION: 00
20
III YEAR
8086 PROGRAMMING
LARGEST& SMALLEST
AIM:
(ii)
ISSUE: 01 REVISION: 00
21
III YEAR
FLOW CHART
LARGEST
SMALLEST
START
START
INITIALIZE COUNT
INITIALIZE COUNT
POINTER MAX = 0
POINTER MIN = 0
PONITER =
POINTER + 1
PONITER =
POINTER + 1
YES
IS MAX
POINTER ?
IS MIN
POINTER ?
YES
NO
NO
MAX = POINTER
MIN = POINTER
COUNT = COUNT-1
COUNT = COUNT-1
NO
NO
IS COUNT = 0
IS COUNT = 0
?
YES
STORE MAXIMUM
STOP
ISSUE: 01 REVISION: 00
STORE MINIIMUM
STOP
22
III YEAR
LARGEST
PROGRAM
COMMENTS
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
Stop
SMALLEST
PROGRAM
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
ISSUE: 01 REVISION: 00
23
MOV DI,1300H
MOV [DI],AL
HLT
Stop
III YEAR
RESULT:
Thus the program for finding the largest and smallest data from a given array was verified
VIVA QUESTIONS:
1.
ISSUE: 01 REVISION: 00
24
III YEAR
8086 PROGRAMMING
COPYING A STRING
AIM:
To move a string of length FF from source to destination.
APPARATUS REQUIRED:
8086 TRAINER KIT
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
COMMENTS
MOV DI,1300H
CLD
REPNE SCASB
DEC DI
MOV BL,[DI]
MOV [SI],BL
HLT
Stop
ISSUE: 01 REVISION: 00
25
III YEAR
FLOW CHART
START
Initialize DS,ES,SI,DI
Decrement CX
Check for
ZF=1
STOP
RESULT:
Thus the program for copying a string of data from source to destination was verified
ISSUE: 01 REVISION: 00
26
III YEAR
VIVA QUESTIONS:
1. What is the function of READY signal?
This is the acknowledgment from the slow devices (or) memory that they have completed the
data transfer. The signal made available by the devices is synchronized by the 8284A clock
generator to provide ready input to the 8086. The signal is active high.
2. What is the operation of RD signal ?
Read signal RD when low, indicates the peripherals that the processor is performing a memory
(or) I/O read operation.
3. What is the function of DEN signal in minimum mode?
This signal indicates the availability of valid data over the address /data lines. It is used to enable
the Transceivers to separate the data from the multiplexed address / data signal.It is active from
the middle of T2 until the middle of T4 DEN is tristated during hold acknowledge
cycle.
ISSUE: 01 REVISION: 00
27
III YEAR
8086 PROGRAMMING
FIND AND REPLACE
AIM:
To find a character in the string and replace it with another character.
APPARATUS REQUIRED:
8086 TRAINER KIT
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, ZF1 and repeat scanning.
If the byte is found, ZF=1.Move the content of BL register to ES:DI.
PROGRAM
COMMENTS
MOV DI,1300H
MOV SI,1400H
CLD
MOV BH,30H
REPNE SCASB
ISSUE: 01 REVISION: 00
28
MOV BL,[DI]
MOV [SI],BL
MOV [DI],BH
HLT
Stop
III YEAR
FLOWCHART
START
STOP
ISSUE: 01 REVISION: 00
29
III YEAR
RESULT:
Thus the program for finding a data and replacing tha data from a given string of data was
verified
VIVA QUESTIONS:
1. What is the fabrication technology used for 8086?
The 8086 is fabricated using the HMOS (High density n-type metal oxide silicon field effect
transistors) technology and contains approximately 29,000 transistors. The 8086 packed in a 40
pin DIP and requires a single 5V supply.
2. What is multimicro-processor architecture ?
The maximum clock frequency at which a system operate may be considered as one of the
measure of the processor capability of the system.An appropriate system involving several
microprocessors connected using a certain topology ma provide high processing capacity. The
study of such a system known as multi micro processor architecture.
3. What are the functional parts of simple multi micro processor system ?
The simplest type of multimicroprocessor system is one containing a CPU and a numeric data
processor (NDP) and/or an Input / Output processor (IOP)
ISSUE: 01 REVISION: 00
30
III YEAR
8086 INTERFACING
INTERFACING ANALOG TO DIGITAL CONVERTER
AIM:
To write an assembly language program to convert an analog signal into a digital signal using an
ADC interfacing.
APPARATUS REQUIRED:
8086 TRAINER KIT
ISSUE: 01 REVISION: 00
31
III YEAR
FLOW CHART
START
STOP
PROGRAM
COMMENTS
MOV AL,00
OUT 0C8H,AL
MOV AL,08
OUT 0C8H,AL
MOV AL,01
ISSUE: 01 REVISION: 00
32
III YEAR
MOV AL,00
MOV AL,00
Introduce delay
MOV AL,00
MOV AL,00
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
IN AL,0C0H
MOV BX,1100
MOV [BX],AL
HLT
Stop
RESULT:
Thus the program for converting an input analog signal into digital was verified
VIVA QUESTIONS:
1. What are the flag manipulation instructions of 8086.
LAHF : Load AH from low byte of flag register.
SAHF : Store AH to low byte of flag register
PUSHF : Push content of flag to the stack.
POPF : Pop content of stack and load it in the
flag register.
2. What are the three groups of signals in 8086 ?
The 8086 signals are categorized in three groups. They are :
i. The signals having common function in minimum and maximum mode.
ii. The signals having special functions for minimum mode,
iii. The signals having special functions for maximum mode.
ISSUE: 01 REVISION: 00
33
III YEAR
APPARATUS REQUIRED:
8086 TRAINER KIT
DAC Interface board
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. The basic idea behind the generation of
waveforms is the continuous generation of analog output of DAC. With 00 (Hex) as input to DAC2 the
analog output is 5v. Similarly with FF H as input, the output is +5v. 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:
Send the digital value of DAC.
Read the corresponding analog value of its output.
ISSUE: 01 REVISION: 00
34
III YEAR
WAVEFORM GENERATION:
SQUARE WAVEFORM:
Send low value (00) to the DAC.
Introduce suitable delay.
Send high value to DAC.
Introduce delay.
Repeat the above procedure.
SAW-TOOTH WAVEFORM:
Load low value (00) to accumulator.
Send this value to DAC.
Increment the accumulator.
Repeat step (ii) and (iii) until accumulator value reaches FF.
Repeat the above procedure from step 1.
TRIANGULAR WAVEFORM:
Load the low value (00) in accumulator.
Send this accumulator content to DAC.
Increment the accumulator.
Repeat step 2 and 3 until the accumulator reaches FF, decrement the
accumulator and send the accumulator contents to DAC.
Decrementing and sending the accumulator contents to DAC.
The above procedure is repeated from step (i)
ISSUE: 01 REVISION: 00
35
III YEAR
FLOW CHART
START
START
INTIALISE THE ACCUMULATOR SEND
ACC CONTENT TO DAC
DELAY
TRANSFER THE ACCUMULATOR
CONTENTS TO DAC
STOP
ISSUE: 01 REVISION: 00
36
SAWTOOTH WAVEFORM
III YEAR
TRIANGULAR
START
START
INITIALIZE
ACCUMULATOR
INITIALIZE
ACCUMULATOR
SEND ACCUMULATOR
CONTENT TO DAC
SEND ACCUMULATOR
INCREMENT ACCUMULATOR
CONTENT
CONTENT TO DAC
YES
INCREMENT ACCUMULATOR
CONTENT
IS ACC
FF
NO
NO
YES
DECREMENT ACCUMULATOR
CONTENT
IS ACC
FF
SEND ACCUMULATOR
CONTENT TO DAC
IS ACC 00
YES
ISSUE: 01 REVISION: 00
NO
37
III YEAR
COMMENTS
MOV AL,7FH
OUT C0,AL
HLT
Stop
DIGITAL DATA
ANALOG VOLTAGE
COMMENTS
L2 : MOV AL,00H
Load 00 in accumulator
OUT C0,AL
CALL L1
Give a delay
MOV AL,FFH
Load FF in accumulator
OUT C0,AL
CALL L1
Give a delay
JMP L2
Go to starting location
L1 : MOV CX,05FFH
L3 : LOOP L3
RET
ISSUE: 01 REVISION: 00
COMMENTS
Load 00 in accumulator
38
INC AL
JNZ L1
JMP L2
Go to starting location
III YEAR
COMMENTS
L3 : MOV AL,00H
Load 00 in accumulator
L1 : OUT C0,AL
INC AL
JNZ L1
MOV AL,0FFH
Load FF in accumulator
L2 : OUT C0,AL
DEC AL
JNZ L2
JMP L3
Go to starting location
WAVEFORMS
AMPLITUDE
TIMEPERIOD
Square Waveform
Saw-tooth waveform
Triangular waveform
RESULT:
Thus the program for converting a digital signal into analog was verified
ISSUE: 01 REVISION: 00
39
III YEAR
MEMORY
LOCATION
A1
A2
B1
B2
HEX
CODE
4500
09 H
4501
05 H
4502
06 H
4503
0A H
ISSUE: 01 REVISION: 00
40
III YEAR
FLOW CHART
START
DELAY
DECREMENT COUNTER
YES
IS B = 0 ?
NO
GET THE DATA FROM LOOK UP TABLE
ISSUE: 01 REVISION: 00
41
PROGRAM
COMMENTS
OUT 0C0,AL
III YEAR
Introduce delay
JNZ L1
INC DI
LOOP LOOP1
JMP START
1200 : 09,05,06,0A
Array of datas
RESULT:
Thus the program for rotating a stepper motor at different speed was verified
ISSUE: 01 REVISION: 00
42
III YEAR
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
1.
2.
3.
4.
5.
6.
7.
0
0
0
0
1
D
0
D
0
K
0
K
0
K
DD
00- 8Bit character display left entry
01- 16Bit character display left entry
10- 8Bit character display right entry
11- 16Bit character display right entry
KKK- Key Board Mode
000-2Key lockout.
ISSUE: 01 REVISION: 00
43
III YEAR
CD
CD
11
1-Enables Clear display 11
CD
CF
CA
A0-3; B0
1
1
0
0
AI
ISSUE: 01 REVISION: 00
44
III YEAR
FLOWCHART
SET UP POINTER
INITIALIZE THE COUNTER
DELAY
PROGRAM
COMMENTS
Initialize array
MOV CX,000FH
MOV AL,10
OUT C2,AL
MOV AL,CC
OUT C2,AL
MOV AL,90
ISSUE: 01 REVISION: 00
45
L1 : MOV AL,[SI]
OUT C0,AL
CALL DELAY
Give delay
INC SI
LOOP L1
JMP START
Go to starting location
LOOP1 : DEC DX
JNZ LOOP1
RET
III YEAR
RESULT:
Thus the program to display the rolling message HELP US in the display was verified.
ISSUE: 01 REVISION: 00
46
III YEAR
ii.
iii.
iv.
ISSUE: 01 REVISION: 00
47
III YEAR
ALGORITHM:
Mode 21.
2.
3.
4.
5.
Mode 31.
2.
3.
4.
5.
PORT ADDRESS :
1.
2.
3.
4.
5.
6.
7.
CONTROL REGISTER
COUNTER OF CHANNEL 0
COUNTER OF CHANNEL 1
COUNTER OF CHANNEL 2
O/P PORT OF CHANNEL 0
O/P PORT OF CHANNEL 1
O/P PORT OF CHANNEL 2
D6
D5
D4
D3
D2
D1
D0
SC1
SC0
RL1
RL0
M2
M1
M0
BCD
ISSUE: 01 REVISION: 00
Mode 2 =
34 H
48
SC1
SC0
CHANNEL SELECT
RL1
RL0
READ/LOAD
CHANNEL 0
LATCH
CHANNEL 1
LSB
CHANNEL 2
MSB
-----
III YEAR
1 --BCD COUNTER
M2
M1
M0
MODE
MODE 0
MODE 1
MODE 2
MODE 3
MODE 4
MODE 5
PROGRAM
COMMENTS
OUT 0BH
OUT 08H
OUT 08H
HLT
Stop
ISSUE: 01 REVISION: 00
49
III YEAR
PROGRAM
COMMENTS
OUT 0BH
OUT 08H
OUT 08H
HLT
Stop
FLOW CHART
START
INITIALIZE ACCUMULATOR
WITH MODE SET WORD
STOP
RESULT
Thus the program for programmable timer 8253 and its different modes of operation was executed
successfully
ISSUE: 01 REVISION: 00
50
III YEAR
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)
ISSUE: 01 REVISION: 00
51
III YEAR
1 ransmitter ready
1. receiver ready
1.. transmitter empty
1... parity error (pe)
1.... overrun error (oe)
1..... framing error (fe), async only
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
ISSUE: 01 REVISION: 00
52
III YEAR
4. The status word is read from the 8251 on completion of a serial I/O operation, or when the host CPU
is checking the status of the device before starting the next I/O operation
COMMENTS
MOV AL,36
OUT CE,AL
MOV AL,10
OUT C8,AL
MOV AL,00
OUT C8,AL
MOV AL,4E
Set mode for 8251(8bit data, No parity, baud rate factor 16x & 1 stop bit)
OUT C2,AL
MOV AL,37
OUT C2,AL
L1:IN AL,C2
AND AL,04
JZ L1
MOV AL,41
OUT C0,AL
INT 2
RECEIVER END
PROGRAM
COMMENTS
MOV AL,36
OUT CE,AL
MOV AL,10
OUT C8,AL
MOV AL,00
OUT C8,AL
MOV AL,4E
Set mode for 8251(8bit data, No parity, baud rate factor 16x & 1 stop bit)
OUT C2,AL
MOV AL,37
ISSUE: 01 REVISION: 00
53
L1:IN AL,C2
AND AL,02
JZ L1
IN AL,C0
MOV BX,1500
MOV [BX],AL
INT 2
III YEAR
RESULT:
Thus the program for transmitting and receiving a data serially was executed successfully.
ISSUE: 01 REVISION: 00
54
III YEAR
APPARATUS REQUIRED:
8086 kit, 8255 interface kit.
ALGORITHM:
Mode 0
1. Initialize accumulator to hold control word
2. store control word in control word register
3. Read data port A.
4. Store data from port A in memory
5. Place contents in port B
Mode 1 & Mode 2
1. Initialize accumulator to hold control word (for port A)
2. Store control word in control word register
3. Initialize accumulator to hold control word (for port B)
4. Place contents in control word register.
5. Disable all maskable interrupts, enable RST 5.5
6. send interrupt mask for RST 6.5 & 7.5
7. Enable interrupt flag
8. Read data from port A, place contents in port B
ISSUE: 01 REVISION: 00
55
III YEAR
FLOWCHART
Mode 0
Mode 1 & 2
START
START
Store control word in
control register
MODE 0
PROGRAM
COMMENTS
MOV AL,90H
OUT C6,AL
IN AL,C0
OUT C2,AL
HLT
Stop
ISSUE: 01 REVISION: 00
56
III YEAR
MODE 1
PROGRAM
COMMENTS
MOV AL,0B0H
OUT C6,AL
MOV AL,09H
OUT C6,AL
MOV AL,13H
Interrupt generation
OUT 30,AL
MOV AL,0AH
Through 8259
OUT 32,AL
MOV AL,0FH
OUT 32,AL
MOV AL,00H
OUT 32,AL
STI
HLT
Stop
ISR:
Subroutine
IN AL,C0
OUT C2,AL
Send it to Port B
HLT
Stop
ISSUE: 01 REVISION: 00
57
III YEAR
MODE 2
PROGRAM
COMMENTS
MOV AL,0C0H
OUT C6,AL
MOV AL,09H
OUT C6,AL
MOV AL,13H
Interrupt generation
OUT 30,AL
MOV AL,0AH
Through 8259
OUT 32,AL
MOV AL,0FH
OUT 32,AL
MOV AL,00H
OUT 32,AL
STI
HLT
Stop
ISR:
Subroutine
IN AL,C0
OUT C2,AL
Send it to Port B
HLT
Stop
Result:
Thus the program for interfacing a PPI was executed successfully
ISSUE: 01 REVISION: 00
58
III YEAR
8051 PROGRAMMING
8 BIT ADDITION
AIM:
To write a program to add two 8-bit numbers using 8051 microcontroller.
APPARATUS REQUIRED
8051 trainer kit
ALGORITHM:
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.
Load the register R 0 with the second 8- bit data.
Add these two 8-bit numbers.
Store the result.
Stop the program.
ADDRESS
MNEMONIC
OPERAND
HEX
CODE
COMMENTS
4100
CLR
C3
Clear CY Flag
4101
MOV
A, data1
74,data1
4103
ADDC
A, # data 2
24,data2
4105
MOV
DPTR, #
4500H
90,45,00
4108
MOVX
@ DPTR, A
F0
SJMP
L1
80,FE
4109
LABEL
L1
ISSUE: 01 REVISION: 00
59
III YEAR
FLOW CHART
START
Clear PSW
Select Register
Bank
Load A and R 0
with 8- bit datas
Add A & R 0
Store the sum
STOP
RESULT:
Thus the program for 8-bit addition using 8051 was executed.
ISSUE: 01 REVISION: 00
60
III YEAR
VIVA QUESTIONS:
1.What is mean by microcontroller?
A device which contains the microprocessor with integrated peripherals like memory, serial ports,
parallel ports, timer/counter, interrupt controller, data acquisition interfaces like
ADC,DAC is called microcontroller.
2.Explain DJNZ instructions of intel 8051 microcontroller?
a. DJNZ Rn, rel
Decrement the content of the register Rn and jump if not zero.
b. DJNZ direct , rel
Decrement the content of direct 8-bit address and jump if not zero.
3.Explain the contents of the accumulator after the execution ot the following program segments:
MOV A,#3CH
MOV R4,#66H
ANL A,R4
A 3C
R4 66
A 24
ISSUE: 01 REVISION: 00
61
III YEAR
8 BIT SUBTRACTION
AIM:
To perform subtraction of two 8 bit data using 8051 microcontroller and store the result in memory.
APPARATUS REQUIRED
8051 trainer kit
ALGORITHM:
a.
b.
c.
d.
e.
f.
ADDRESS
MNEMONIC
OPERAND
HEX
CODE
COMMENTS
4100
CLR
C3
Clear CY flag
4101
MOV
A, # data1
74, data1
Store data1 in
accumulator
4103
SUBB
A, # data2
94,data2
4105
MOV
DPTR, # 4500
90,45,00
Initialize memory
location
4108
MOVX
@ DPTR, A
F0
SJMP
L1
80,FE
Stop
4109
LABEL
L1
ISSUE: 01 REVISION: 00
62
III YEAR
FLOWCHART
START
CLEAR CARRY
FLAG
GET IST
OPERAND IN
ACCR
SUBTRACT THE
2ND OPERAND
FROM ACCR
N
IS CF=1
Y
INCREMENT
THE BORROW
REGISTER
STORE
RESULT IN
MEMORY
STOP
RESULT
Thus the program for 8-bit subtraction using 8051 was executed
ISSUE: 01 REVISION: 00
63
III YEAR
8051 PROGRAMMING
8 BIT MULTIPLICATION
AIM:
To perform multiplication of two 8 bit data using 8051 microcontroller and store the result in
memory.
APPARATUS REQUIRED
8051 trainer kit
ALGORITHM:
a.
b.
c.
d.
ADDRESS
MNEMONIC
OPERAND
HEX
CODE
COMMENTS
4100
MOV
A ,#data1
74, data1
Store data1 in
accumulator
4102
MOV
B, #data2
75,data2
4104
MUL
A,B
F5,F0
Multiply both
4106
MOV
DPTR, # 4500H
90,45,00
Initialize memory
location
4109
MOVX
@ DPTR, A
F0
401A
INC
DPTR
A3
Go to next memory
location
410B
MOV
A,B
E5,F0
410D
MOV
@ DPTR, A
F0
SJMP
STOP
80,FE
Stop
410E
LABEL
STOP
ISSUE: 01 REVISION: 00
64
III YEAR
FLOW CHART
START
GET
MULTIPLIER
IN ACCR
GET
MULTIPLICAND
IN B REG
MULTIPLY A
WITH B
STORE
RESULT IN
MEMORY
STOP
RESULT
Thus the program for 8-bit multiplication using 8051 was executed
ISSUE: 01 REVISION: 00
65
III YEAR
8051 PROGRAMMING
8 BIT DIVISION
AIM:
To perform division of two 8 bit data using 8051 microcontroller and store the result in memory.
APPARATUS REQUIRED
8051 trainer kit
ALGORITHM:
1.
2.
3.
4.
ADDRESS
MNEMONIC
OPERAND
HEX
CODE
COMMENTS
4100
MOV
A, # data1
74,data1
4102
MOV
B, # data2
75,data2
4104
DIV
A,B
84
Divide
4015
MOV
DPTR, # 4500H
90,45,00
4018
MOVX
@ DPTR, A
F0
Store remainder
4109
INC
DPTR
A3
Go to next memory
location
410A
MOV
A,B
E5,F0
410C
MOV
@ DPTR, A
F0
Store quotient
SJMP
STOP
80,FE
Stop
410D
LABEL
STOP
ISSUE: 01 REVISION: 00
66
III YEAR
FLOW CHART
START
GET DIVIDEND
IN ACCR
GET DIVISOR IN
B REG
DIVIDE A BY B
STORE
QUOTIENT &
REMAINDER
IN MEMORY
STOP
RESULT
Thus the program for 8-bit division using 8051 was executed
ISSUE: 01 REVISION: 00
67
III YEAR
FLOWCHART
START
STOP
ISSUE: 01 REVISION: 00
68
ADDRESS
HEX
CODE
4100
LABEL
III YEAR
MNEMONICS
OPERAND
COMMENT
90,45,00
MOV
DPTR,#4500
4103
74,FF
MOV
A,#FF
4105
D3
SETB
Set CY bit
4016
82,EF
ANL
C, ACC.7
4018
E5,D0
MOV
A,DOH
410A
F0
MOVX
@DPTR,A
410B
A3
INC
DPTR
Go to next location
410C
72,AA
ORL
C, IE.2
410E
C2,D6
CLR
PSW.6
4110
E5,D0
MOV
A,DOH
4112
F0
MOVX
@DPTR,A
4113
A3
INC
DPTR
Go to next location
4114
D2,90
SETB
SCON.5
4116
C2,99
CLR
SCON.1
4118
E5,98
MOV
A,98H
411A
F0
MOVX
@DPTR,A
411B
A3
INC
DPTR
Go to next location
411C
A2,99
MOV
C,SCON.1
411E
E5,D0
MOV
A,DOH
4120
F0
MOVX
@DPTR,A
4122
80,FE
SJMP
L2
Stop
L2
ISSUE: 01 REVISION: 00
69
III YEAR
Program that places a message on the screen every 10 seconds, using int 1ah;
CODE SEGMENT
TIMEDELAY:
MOV SP,1000H
MOV DI,10XD
TIME OUT:
MOV AH,00H
INT 1AH
MOV BX,DX
TIMER:
MOV AH, 00H
INT 1AH
SUB DX, BX
CMP DX, 182XD
JC TIMER
MOV AH, 09H
CS
MOV DX,MSG
INT 21H
DEC DI
JNZ TIMEOUT
MOV AX,4C00H
INT 21H
MSG:
ISSUE: 01 REVISION: 00
70
III YEAR
RESULT:
Thus an ALP program for digital clock and stop watch was executed and verified
successfully.
ISSUE: 01 REVISION: 00
71
III YEAR
ISSUE: 01 REVISION: 00
72
III YEAR
overflow
CPL Px.x
CLR TR1
; stop timer
CLR TF1
SJMP L1
b) Program to transfer a data serially from one kit to another.
Transmitter:
MOV TMOD,#20H
MOV TL1,#FDH
MOV TH1,#FFH
MOV SCON,#50H
SETB TR1
; Start timer1
MOV A,#06h
MOV SBUF,A
LOOP:
CLR TI
HERE:
SJMP HERE
ISSUE: 01 REVISION: 00
73
III YEAR
Receiver:
MOV TMOD,#20H
MOV TL1,#FDH
MOV TH1,#FFH
MOV SCON,#50H
SETB TR1
LOOP:
JNB RI,LOOP
MOV A,SBUF
MOV DPTR,#4500H
MOVX @DPTR,A
CLR RI
HERE:
SJMP HERE
RESULT:
ISSUE: 01 REVISION: 00
74
III YEAR
SERIAL COMMUNICATION
8051>H
HELP MENU
F10
Assembler
Disassembler
For SDA SI-MEL kit, following menu is displayed on pressing the option "T"
8051>T
ALS-SDA SI-MEL Kit Test monitor
ISSUE: 01 REVISION: 00
75
III YEAR
Select (1-6):
Suppose the user presses the key '1', following message is displayed if the internal data RAM is
OK.
After displaying the message, the menu is displayed once again waits for user to enter a key
8051>E
EDIT (R,B,M,P,D)D - EXTERNAL DATA RAM
Enter STA address = 0400
0400 =
0401 =
D5:66
0402 =
D3:77
0403 =
73:88
0404 =
6F:12
0405 =
CB:01
0406 =
0407 =
6F:03
0408 =
7B:04
ISSUE: 01 REVISION: 00
76
0409 =
29:05
040A =
6F:06
040B =
73:07
040C =
FF:08
040D =
040E =
III YEAR
8051>E
EDIT (R,B,M,P,D)B - BITS
Enter STA address = 00
00 = 0:1
01= 0:1
02 = 0:0
03 = 0:1
03 = 1:
03 = 1:
02 = 0:
8051>E
EDIT (R,B,M,P,D)R- REGISTERS
ACC = 00:33
PSW = 00:44
DPH = 00:55
DPL = 00:00
DPL = 00:00
8051>E
EDIT (R,B,M,P,D)-P = PROGRAM CODE
8000 = FF:78
8001 = FF:10
8002 = FF:79
ISSUE: 01 REVISION: 00
77
III YEAR
8003 = FF:20
8004 = FF:7A
8005 = FF: 12
8007 = FF : 00
8008 = FF : 03
8009 = FF : 0F
8051>E
EDIT (R,B,M,P,D)-M - INTERNAL RAM
0000 = 00 : 12
0001 = 00 : 34
0002 = 00 : 00
DISPLAY COMMAND
8051>D
EDIT (R,B,M,P,D)-EXTERNAL DATA RAM
0500 55 66 77 88 12 01 02 03 04 05 06 07 08 09 04 D7
8051>B
BR _ NO: R
BR_ADD 0000
ISSUE: 01 REVISION: 00
78
III YEAR
8051>B
BR _ NO: 0
ERROR! BREAK NUMBERS MUST BE BETWEEN 1 & 8
8051>C
BR_N0:A
8051>C
BR_N0:1
8051>A
ENTER START ADDRESS = 8000
79
III YEAR
RESULT:
VIVA QUESTIONS:
1.What is an Interrupt?
Interrupt is a signal send by an external device to the processor so as to request the processor to
perform a particular task or work
2.. What is program counter? How is it useful in program execution?
The program counter keeps track of program execution. To execute a program the starting address of
the program is loaded in program counter. The PC sends out an address to fetch a byte of instruction
from memory and increments its content automatically.
3. Define stack
ISSUE: 01 REVISION: 00
80