CS2259 LM
CS2259 LM
Kamaraj College of Engineering and Technology, Virudhunagar, during the year 2012 - 2013.
Expt. Page
Date Title of the Experiment Mark Signature
no. No.
21- 24
3 Array Processing Using 8085 Microprocessor
43 – 47
7 Array Processing Using 8086 Microprocessor
61 – 62
10 Logical Manipulation Using 8051 Microcontroller
63 – 65
11 Bit Manipulation Using 8051 Microcontroller
INDEX
Expt. Page
Date Title of the Experiment Mark Signature
no. No.
4
SYLLABUS (Common to CSE & IT)
AIM:
To learn the assembly language programming of 8085, 8086 and 8051 and also to
give a practical training of interfacing the peripheral devices with the processor.
OBJECTIVES:
To implement the assembly language programming of 8085, 8086 and 8051.
To study the system function calls like BIOS/DOS.
To experiment the interface concepts of various peripheral device with the proces-
sor.
Experiments in the following:
Programming with 8085
Programming with 8086-experiments including BIOS/DOS calls:
Keyboard control, Display, File Manipulation.
Interfacing with 8085/8086-8255,8253
Interfacing with 8085/8086-8279,8251
8051 Microcontroller based experiments for Control Applications
Mini- Project
TOTAL: 45 PERIODS
5
LIST OF CYCLES
Cycle I : 8085 PROGRAMMING
8 BIT ARITHMETIC OPERATIONS USING 8085 MICROPROCESSOR
16 BIT ARITHMETIC OPERATIONS USING 8085 MICROPROCESSOR
ARRAY PROCESSING USING 8085 MICROPROCESSOR
GENERATION OF SERIES AND STRING MANIPULATION USING 8085
MICROPROCESSOR
6
Cycle V : PROGRAMMING WITH MASM ASSEMBLER
READ SCAN CODE AND CHARACTER CODE FROM KEYBOARD
USING MASM
STRING DISPLAY USING MASM
7
CYCLE I - 8085 PROGRAMMING
8
INTRODUCTION TO 8085 MICROPROCESSOR
9
and peripherals. The control signals RD (read) and WR (write) indicate the availability
of data on the data bus.
Instruction register and decoder
The instruction register and decoder are part of the ALU. When an instruction is
fetched from memory it is loaded in the instruction register. The decoder decodes the
instruction and establishes the sequence of events to follow.
Register array
The 8085 has six general purpose registers to store 8-bit data during program
execution. These registers are identified as B, C, D, E, H and L. they can be combined as
BC, DE and HL to perform 16-bit operation.
Accumulator
Accumulator is an 8-bit register that is part of the ALU. This register is used to
store 8-bit data and to perform arithmetic and logic operation. The result of an operation
is stored in the accumulator.
Program counter
The program counter is a 16-bit register used to point to the memory address of the next
instruction to be executed.
Stack pointer
It is a 16-bit register which points to the memory location in R/W memory, called the
Stack.
Control bus
It consists of various single lines that carry synchronizing signals. The
microprocessor uses such signals for timing purpose.
10
Ex. No. 1 Date :
AIM:
To Write an Assembly Language Program to perform 8 bit addition, subtraction,
multiplication, division using 8085 microprocessor.
APPARATUS REQUIRED:
8085 Microprocessor Kit, Power Supply (+5v)
PROGRAM:
8 BIT ADDITION:
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
4100 MVI C, 00H
4102 LDA 4200
4105 MOV B, A
4106 L1 LDA 4201
4109 ADD B
410A JNC L1
410B INR C
410C STA 4202
410F MOV A, C
4110 STA 4203
4113 HLT
OBSERVATION:
INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
4200 4202
4201 4203
11
MANUAL CALCULATION:
8 BIT SUBTRACTION:
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
4100 MVI C, 00H
4102 LXI H, 4500
4105 MOV A, M
4106 INX H
4107 SUB M
4108 JNC L1
410B INR C
410C CMA
410D ADI 01H
410F L1 INX H
4110 MOV M, A
4111 INX H
4112 MOV M, C
4113 HLT
OBSERVATION:
INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
4500 4502
4501 4503
MANUAL CALCULATION:
12
8 BIT MULTIPLICATION:
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
4100 LDA 4152
4103 MOV B,A
4104 LXI B, 0000
4107 LHLD 4150
410A XCHG
410B L1 DAD D
410C DCR B
410D JNZ L1
410E SHLD 4152
4110 HLT
OBSERVATION:
INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
4150 4152
4151 4153
MANUAL CALCULATION:
8 BIT DIVISION:
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
4100 LDA 4150
4103 MOV B,A
4104 LDA 4151
4107 MVI C, 00
4109 CMP D
13
410A L1: JC L2
410B SUB B
410C INR C
410D CMP B
410E JNC L1
410F L2 MOV A, C
4110 STA 4153
4113 HLT
OBSERVATION:
INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
4150 4152
4151 4153
MANUAL CALCULATION:
Max. Marks
Category
INFERENCES: Marks Awarded
Preparation 10
Performance 30
Result 40
Viva-voce 10
Record 10
TOTAL 100
RESULT:
14
Ex. No. 2 Date :
AIM:
To write an Assembly Language Program to perform 16 bit addition, subtraction,
multiplication, division and Multi-byte addition using 8085 microprocessor.
APPARATUS REQUIRED:
8085 Microprocessor Kit, Power Supply (+5v)
PROGRAM:
16 BIT ADDITION
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
4100 LXI D,FFFF
4103 LXI H,1111
4106 MVI C,00
4108 DAD D
4109 JNC L1
410A INR C
410B L1 SHLD 4300
410E MOV A,C
410F STA 4302
4112 HLT
MANUAL CALCULATION:
15
OBSERVATION:
INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
4101 4300
4102 4301
4104 4302
4105
16 BIT SUBTRACTION:
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
4100 MVI C, 00
4102 LHLD 4050H
4105 XCHG
4106 LHLD 4052H
4109 MOV A, L
410A SUB E
410B MOV L, A
410C MOVA, H
410D SBB D
410E MOVH, A
410F SHLD 4054H
4112 JNC L1
4115 INR C
4116 L1 MOV A, C
4117 STA 4056H
411A HLT
16
OBSERVATION:
INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
4050 4054
4051 4055
4052 4056
4053
MANUAL CALCULATION:
16 BIT MULTIPLICATION:
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
4100 LXI H,0000
4103 LXI D,FFFF
4106 LXI SP,1111
4109 LXI B,0000
410C L2 DAD SP
410D JNC L1
4110 INX B
4111 L1 DCX D
4112 MOV A,D
4113 ORA E
4114 JNZ L2
4117 SHLD 4150
411A MOV A,C
411B STA 4152
411E MOV A,B
411F STA 4153
4112 HLT
17
OBSERVATION:
INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
4104 4150
4105 4151
4107 4152
4108 4153
MANUAL CALCULATION:
16 BIT DIVISION:
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
4100 LXI B,0000
4103 LXI H,F1F2
4106 LXI D,13F3
4109 MOV A,H
410A L2 CMP D
410B JC L1
410E MOV A,L
410F SUB E
4110 MOV L,A
4111 MOV A,H
4112 SBB D
4113 MOV H,A
4114 INX B
4115 JMP L2
18
4118 SHLD 4150
4119 L1 MOV A,C
411A STA 4152
411D MOV A,B
411E STA 4153
4121 HLT
OBSERVATION:
INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
4104 4150
4105 4151
4107 4152
4108 4153
MANUAL CALCULATION:
19
410F INX H
4110 DCR C
4111 JNZ L1
4112 HLT
OBSERVATION:
INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
4200 4300
4201 4301
4202 4302
4300
4301
4302
MANUAL CALCULATION:
INFERENCES:
Max. Marks
Category
Marks Awarded
Preparation 10
Performance 30
Result 40
Viva-voce 10
Record 10
TOTAL 100
RESULT:
Thus the ALP to perform 16 bit addition, subtraction, multiplication, division
and multibyte addition were executed and verified using 8085 microprocessor.
20
Ex. No. 3 Date :
APPARATUS REQUIRED:
8085 Microprocessor Kit, Power Supply (+5v)
PROGRAM:
LARGEST/SMALLEST IN AN ARRAY:
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
4100 MVI C,05
4102 LXI H,4150
4105 MOV A,M
4106 L2 INX H
4107 MOV B,M
4108 CMP B
4109 JNC /JC L1
410C MOV A,B
410D L1 STA 4250
4110 DCR C
4111 JNZ L2
4114 HLT
21
OBSERVATION:
INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
4150 4250
4151
4152
4153
4154
22
OBSERVATION:
INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
4150 4150
4151 4151
4152 4152
4153 4153
4154 4154
23
OBSERVATION:
INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
4150 4160
4151
4152
4153
4154
INFERENCES:
Max. Marks
Category
Marks Awarded
Preparation 10
Performance 30
Result 40
Viva-voce 10
Record 10
RESULT: TOTAL 100
Thus the following operations were performed using 8085 microprocessor and
outputs were also verified.
1. Largest/Smallest in an array.
2. Ascending/Descending order of an array.
3. Finding Odd/Even number in an array.
24
Ex. No. 4 Date :
AIM:
To Write an Assembly Language Program to perform the following Series
generation and string manipulation operations using 8085 microprocessor.
Generation of Fibonacci series.
Check whether the given string is palindrome or not.
APPARATUS REQUIRED:
8085 Microprocessor Kit, Power Supply (+5v)
PROGRAM:
GENERATION OF FIBONACCI SERIES:
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
4100 LXI H,4150
4103 MVI D,05H
4105 MVI A,00H
4107 MOV B,A
4108 MOV M,A
4109 INX H
410A MVI A,01H
410C MOV C,A
410D MOV M,A
410E INX H
410F L1 MOV A,B
4110 ADD C
4111 MOV B,C
4112 MOV C,A
4113 MOV M,A
25
4114 INX H
4115 DCR D
4116 JNZ L1
4119 HLT
OBSERVATION:
INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
4104 05 4150
4151
4152
4153
4154
MANUAL CALCULATION:
26
410F MOV A,M
4110 STAX D
4111 DCX D
4112 INX H
4113 DCR D
4114 JNZ L1
4117 LXI H,4180
411A MVI C,05
411C INX D
411D LDAX D
411E MOV B,M
411F CMP B
4120 JNZ L2
4123 INX H
4124 INX D
4125 DCR C
4126 JNC L3
4129 JMP L4
412C MVI A,01H
412E STA4150
4131 JMP L5
4134 MVI A,00H
4136 STA 4150
4139 HLT
OBSERVATION: PALINDROME
INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
4180 4150
4181
4182
4183
27
4184
NOT A PALINDROME
INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
4180 4150
4181
4182
4183
4184
MANUAL CALCULATION:
Max. Marks
Category
Marks Awarded
INFERENCES: Preparation 10
Performance 30
Result 40
Viva-voce 10
Record 10
TOTAL 100
RESULT:
Thus the following Series generation and string manipulation operations were
performed using 8085 microprocessor.
Generation of Fibonacci series.
Check whether the given string is palindrome or not.
28
CYCLE II - 8086 PROGRAMMING
29
memory). Because the processor has 16-bit index registers and memory pointers, it can
effectively address only 64 KB of memory. To address memory beyond 64 KB the CPU
uses segment registers - these registers specify memory locations for code, stack, data
and extra data 64 KB segments. The segments can be positioned anywhere in memory,
and, if necessary, user programs can change their position. This addressing method has
one big advantage - it is very easy to write memory-independent code when the size of
code, stack and data is smaller than 64 KB each. The complexity of the code and pro-
gramming increases, sometimes significantly, when the size of stack, data and/code is
larger than 64 KB. To support different variations of this awkward memory addressing
scheme many 8086 compilers included 6 different memory models: tiny, small, com-
pact, medium, large and huge. 64 KB direct addressing limitation was eliminated with
the introduction of the 32-bit protected mode in Intel 80386 processor.
Intel 8086 instruction set includes a few very powerful string instructions. When
these instructions are prefixed by REP (repeat) instruction, the CPU will perform block
operations - move block of data, compare data blocks, set data block to certain value,
etc, that is one 8086 string instruction with a REP prefix could do as much as a 4-5 in -
struction loop on some other processors. To be fair, the Zilog Z80 included move and
search block instructions, and Motorola 68000 could execute block operations using just
two instructions.
The 8086 microprocessor provides support for Intel 8087 numeric co-processor. The
CPU recognizes all Floating-Point (FP) instructions. When the FP instructions reference
the memory, the CPU calculates memory address and performs dummy memory read.
The calculated address, and possibly read data, is captured by the FPU. After that the
CPU proceeds to the next instruction, while the FPU executes the floating-point
instruction. Thus, both integer and floating-point instructions can be executed
concurrently.
Ex. No. 5 Date :
30
To Write an ALP to perform 16 bit addition, subtraction, multiplication, division
and 32 bit addition/subtraction using 8086 microprocessor.
APPARATUS REQUIRED:
8086 Microprocessor Kit
PROGRAM: 16-BIT ADDITION
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
MOV DL, #00
MOV SI, #1050
MOV AX, [SI]
MOV DI, #1052
MOV BX, [DI]
ADD AX, BX
JNC L1
INC DL
L1 MOV [1054], AX
MOV [1056], DL
HLT
Test Data:
INPUT OUTPUT
INPUT OUTPUT
Address/Reg Data Address Data
Address/Reg Data Address Data
1050 F2 1054 F2(lower order)
1050 FD 1054 CC
1051 F1 1055 AB
1051 3F 1055 41
1052 01 1056 BA(higher order)
1052 31 1056 01(borrow)
1053 05 1057 04
1053 FE
Observed Test Data:
INPUT OUTPUT
INPUT OUTPUT
Address/Reg Data Address Data
Address/Reg Data Address Data
1050 1054
1050 1054
1051 1055
1051 1055
1052 1056
1052 1056 31
1053
1053 1057
Manual Calculation:
16-BIT SUBTRACTION
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
MOV DL, #00
MOV SI, #1050
MOV AX, [SI]
MOV DI, #1052
MOV BX, [DI]
SUB AX, BX
JNC L1
INC DL
L1 MOV [1054], AX
MOV [1056], DL
HLT
16-BIT MULTIPLICATION
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
MOV SI, #1050
MOV DI, #1052
MOV AX, [SI]
MOV BX, [DI]
MUL BX
MOV [1054], AX
32
MOV [1056], DX
HLT
33
MOV DI, #1052
MOV AX, [SI]
MOV BX, [DI]
DIV BX
MOV [1054], AX
MOV [1056], DX
HLT
32 BIT ADDITION/SUBTRACTION
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
MOV DL, #00
MOV BX, #1050
MOV AX, [BX]
MOV BX, #1052
MOV CX, [BX]
ADD AX, CX
MOV [1058], AX
MOV BX, #1054
MOV AX, [BX]
MOV BX, #1056
MOV CX, [BX]
ADC AX, CX
JNC L1
INC DL
L1 MOV [105A], AX
MOV [105C], DL
HLT
Max. Marks
Category
Marks Awarded
Preparation 10
Performance 30
Result 40
Viva-voce 10
34
Record 10
TOTAL 100
INFERENCES:
RESULT:
Thus the ALP to perform 16 bit addition, subtraction, multiplication, division
and 32 bit addition/subtraction were executed and verified using 8086 microprocessor.
35
INC SI
DEC CL
MOV BL,#01
MOV [SI],BL
DEC CL
L1: ADD BL,AL
MOV AL,[SI]
INC SI
MOV [SI],BL
LOOP LI
HLT
Test data:
INPUT OUTPUT
ADDRESS/REG DATA ADDRESS DATA
CL 05 1050 00
1051 01
1052 01
1053 02
1054 03
INPUT OUTPUT
Observed test data:
ADDRESS/REG DATA ADDRESS DATA
CL 08 1050
1051
1052
1053
1054
1055
36
1056
1057
SMALLEST/LARGEST NUMBER IN AN ARRAY
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
MOV SI,#1050
MOV CL,[SI]
INC SI
MOV AL,[SI]
DEC CL
L2 INC SI
MOV BL, [SI]
CMP AL, BL
JC L1
{JNC L1 FOR LARGEST
NUMBER}
MOV AL, BL
L1 LOOP L2
MOV [1060], AL
HLT
37
INPUT OUTPUT INPUT OUTPUT
Address/Reg Data Address Data Address/Reg Data Address Data
1050 05 1060 02 1050 05 1060
(Count) (Count)
1051 0B 1051
1052 02 1052
1053 07 1053
1054 09 1054
1055 FF 1055
38
ORDER}
L3 LOOP L2
MOV SI,#1050
MOV CL,DL
LOOP L4
JMP L5
L1 MOV AL,BL
DEC SI
MOV BL,[SI]
MOV[SI],AL
INC SI
MOV [SI],BL
JMP L3
L5 HLT
39
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
MOVCL,#05
MOV SI,#1050
MOV DI,#1070
MOV BX,#1060
L3 MOV AL,[SI]
MOV DL, AL
RCR AL, 01
JC L1
MOV [DI], DL
INC DI
JMP L2
L1 MOV [BX], DL
INC BX
L2 INC SI
LOOP L3
HLT
Test Data:
OUTPUT1( odd) OUTPUT2(even)
ADDRESS/REG DATA ADDRESS/REG DATA ADDRESS/REG DATA
1050 00 1060 03 1070 00
1051 03 1061 01 1071 0A
1052 0A 1062 05
1053 01
1054 05
Test Data:
OUTPUT1( POSITIVE) OUTPUT2(NEGATIVE)
40
ADDRESS/REG DATA ADDRESS/REG DATA ADDRESS/REG DATA
1050 F3 1060 1070
1051 56 1061 1071
1052 8C 1062
1053 59
1054 11
INFERENCES :
41
Max. Marks
Category
Marks Awarded
Preparation 10
Performance 30
Result 40
Viva-voce 10
Record 10
TOTAL 100
RESULT:
Thus the ALP to perform following operations was executed and verified using
8086 microprocessor.
(i)Generation of Fibonacci series
(ii) Find smallest/largest in an array
(iii)Ascending/descending order in an array
(iv)To separate odd/even number in an array
APPARATUS REQUIRED:
8086 Microprocessor Kit
42
SUM OF DATA IN AN ARRAY
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
MOV CL,#05
MOV SI,#1050
MOV BL,#00
MOV BH,#00
L1 MOV AL,[SI]
ADD BL,AL
JNC L2
INC BH
L2 INC SI
LOOP L1
MOV [1070], BX
HLT
INPUT OUTPUT
ADDRESS/REG DATA ADDRESS/REG DATA
1050 31 1070
1051 F6 1071
1052 98
1053 42 43
1054 2C
TO REVERSE AN ARRAY IN DIFFERENT LOCATION
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
MOV CL,#05
MOV SI,#1050
MOV BX,#1060
MOV DL,CL
DEC DL
ADD BL,DL
L1 MOV AL,[SI]
MOV [BX],AL
INC SI
DEC BX
LOOP L1
HLT
44
MOV SI,#1050
DEC DI
L2 MOV AL,[DI]
MOV [SI],AL
INC SI
DEC DI
LOOP L2
HLT
Test Data:
INPUT OUTPUT
ADDRESS/REG DATA ADDRESS/REG DATA
1050 01 1060 05
1051 02 1061 04
1052 03 1062 03
1053 04 1063 02
1054 05 1064 01
Test Data:
INPUT OUTPUT
ADDRESS/REG DATA ADDRESS/REG DATA
1050 01 1050 05
1051 02 1051 04
1052 03 1052 03
1053 04 1053 02
1054 05 1054 01
45
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
MOV CL,#05
MOV SI,#1050
MOV DI,#1060
L1 MOV AL,[SI]
MOV BL,[DI]
MOV [DI],AL
MOV [SI],BL
INC SI
INC DI
LOOP L1
HLT
Test Data:
INPUT1 INPUT 2
ADDDRESS/REG DATA ADDRESS/REG DATA
1050 01 1060 06
1051 02 1061 07
1052 03 1062 08
1053 04 1063 09
1054
OUTPUT 1 05 1064
OUTPUT 2 0A
ADDDRESS/REG DATA ADDRESS/REG DATA
1050 06 1060 01
1051 07 1061 02
1052 08 1062 03
46
1053 09 1063 04
1054 0A 1064 05
INFERENCES: Max. Marks
Category
Marks Awarded
Preparation 10
Performance 30
Result 40
Viva-voce 10
Record 10
TOTAL 100
RESULT:
Thus the ALP to perform following operations was executed and verified using
8086 Microprocessor.
(i) Sum of data in an array
(ii) To reverse an array in an different location
(iii) To reverse an array in an same location
(iv) To swap two arrays.
47
Ex. No. 8 Date :
SEARCH, REPLACE & STRING MANIPULATION USING 8086
MICROPROCESSOR
AIM
To Write an ALP to perform the following operations using 8086 microprocessor
(i) Check whether number is present or not
(ii) Search & replace a number
(iii)To check the given string is palindrome or not
APPARATUS REQUIRED:
8086 Microprocessor Kit
48
Test Data:
49
L3 HLT
Test Data:
50
JNZ L3
INC SI
INC BX
LOOP L2
MOV AL, #00
MOV [1070], AL
JMP L4
L3 MOV AL, #01
MOV [1070], AL
L4 HLT
Test Data:
INPUT OUTPUT
Address/Reg Data Address Data
1050 01 1070 00(palindrome)
1051 02
1052 03
1053 02
1054 01
Test Data:
INPUT OUTPUT
Address/Reg Data Address Data
1050 01 1070 01( not palindrome)
1051 02
1052 03
1053 04
1054 05
51
INFERENCES :
Max. Marks
Category
Marks Awarded
Preparation 10
Performance 30
Result 40
Viva-voce 10
Record 10
TOTAL 100
RESULT:
Thus the ALP to perform following operations was executed and verified using
8086 microprocessor.
i) Check whether number is present or not
(ii) Search & replace a number
(iii)To check the given string is palindrome or not
52
CYCLE III - 8051 PROGRAMMING
53
INTRODUCTION TO 8051 MICROCONTROLLER
Apart from 8051, 8052 and 8031 complete the 8051 family. The 8052 microcon-
troller has 256 bytes of RAM and 3 timers. Programs written for 8051 projects can be
used for 8052 as well. The 8031 has all features of 8051 except that it is ROM-less. An
external ROM that is as large as 64 k bytes can be programmed and added to this chip
for execution. The main disadvantage of adding external ROM is that 2 out of 4 ports
are used up leaving less for I/O operations.
8051’s history dates back to when Intel Corporation first built the 8 – bit micro-
controller in 1981. This microcontroller was referred as “system on a chip” because it
had 128 bytes of RAM, 4 Kbytes of ROM, 2 Timers, 1 Serial port, and four ports on a
single chip.
Intel permitted other microcontroller manufacturers to fabricate different ver-
sions of 8051 with the condition that code compatibility should be maintained. The ad-
vantage of this is that when the program is written, it can be used for any version of
8051 irrespective of manufacturer.
54
Ex. No. 9 Date :
ARITHMETIC MANIPULATION USING 8051 MICROCONTROLLER
AIM
To Write an ALP to perform following operations using 8051 microcontroller
(i) 8-bit addition indirect addressing mode
(ii) 8-bit subtraction indirect addressing mode
(iii) 8-bit division
(iv) 8-bit multiplication & (v) 16-bit addition/subtraction
APPARATUS REQUIRED
8051 Microcontroller Kit
8 BIT ADDITION- IN DIRECT ADDRESSING MODE
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
MOV DPTR, #8600
MOVX A, @DPTR
MOV R1, A
INC DPTR
MOVX A, @DPTR
MOV R0, A
INC DPTR
MOVX A, @DPTR
ADD A, R0
JNC L1
INC R1
L1 INC DPTR
MOVX @DPTR, A
INC DPTR
MOV A,R1
MOVX @DPTR,A
55
L3 SJMP L3
INPUT OUTPUT
INPUT OUTPUT
Address/Reg Data Address Data
Address/Reg Data Address Data
8600 00 8603 A9
8600 8603
8601 AA 8604 01
8601 8604
carry
8602
8602 FF
56
Test Data: Observed Test Data:
INPUT OUTPUT
INPUT OUTPUT
Address/Reg Data Address Data
Address/Reg Data Address Data
8600 00 8603 FD
8600 8603
8601 05 8604 01
8601 8604
(borrow)
8602
8602 02
8-BIT MULTIPLICATION
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
MOV DPTR, #8150
MOVX A, @DPTR
MOV F0, A
INC DPTR
MOVX A, @DPTR
MUL AB
INC DPTR
MOVX @DPTR, A
MOV A, F0
INC DPTR
MOVX @DPTR, A
L3 SJMP L3
57
8-BIT DIVISION
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
MOV DPTR, #8150
MOVX A, @DPTR
MOV F0, A
INC DPTR
MOVX A, @DPTR
MUL AB
INC DPTR
MOVX @DPTR, A
MOV A, F0
INC DPTR
MOVX @DPTR, A
L3 SJMP L3
58
16 –BIT ADDITION
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
MOV DPTR,#8150
MOV R2,#00
MOVX A,@DPTR
MOV R0,A
INC DPTR
MOVX A,@DPTR
ADD A,R0
MOV R1,A
INC DPTR
MOVX A,@DPTR
MOV R0,A
INC DPTR
MOVX A,@DPTR
ADDC A,R0
JNC L1
INC R2
L1 INC DPTR
MOVX @DPTR,A
MOV A, R1
INC DPTR
MOVX @DPTR,A
INC DPTR
MOV A,R2
MOVX @DPTR,A
L3 SJMP L3
Note : For 16 bit subtraction use ‘CLR C’ Command at first line and use ‘SUBB’
instruction replacing ‘ADD’ and ‘ADDC’
Test Data: Observed Test Data:
59
INPUT OUTPUT INPUT OUTPUT
Address/Reg Data Address Data Address/Reg Data Address Data
8150 31 8154 CF(H) 8150 31 8154 CF(H)
8151 10 8155 41(L) 8151 10 8155 41(L)
8152 F1 8156 01(Carry) 8152 F1 8156 01(Carry)
8153 DE 8153 DE
INFERENCES:
Max. Marks
Category
Marks Awarded
Preparation 10
Performance 30
Result 40
Viva-voce 10
Record 10
TOTAL 100
RESULT:
Thus the ALP to perform following operations was executed and verified using
8051 microcontroller.
(i) 8-bit addition indirect addressing mode
(ii) 8-bit subtraction indirect addressing mode
(iii)8-bit division
(iv)8-bit multiplication
(v)16-bit addition/subtraction
Ex. No. 10 Date :
LOGICAL MANIPULATION USING 8051 MICROCONTROLLER
AIM
To Write an ALP to perform following operations using 8051 microcontroller
60
(i) Convert nibbles to bytes (ii) Convert bytes to nibbles
APPARATUS REQUIRED
8051 Microcontroller Kit
CONVERT NIBBLES TO BYTES
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
MOV DPTR,#8150
MOVX A,@DPTR
SWAP A
MOV R0, A
INC DPTR
MOVX A,@DPTR
ADD A, R0
INC DPTR
MOVX @DPTR, A
L1 SJMP L1
SWAP A
ANL A, 0F
INC DPTR
MOVX @DPTR, A
61
L1: SJMP L1
Thus the ALP to perform following operations was executed and verified using
8051 microcontroller.
(i) Convert nibbles to bytes
(ii) Convert bytes to nibbles
Ex. No. 11 Date :
62
BIT MANIPULATION USING 8051 MICROCONTROLLER
AIM
To Write an ALP to perform following operations using 8051 microcontroller
(i) Count the number of odd & even numbers in an array
(ii) Find positive or negative number
APPARATUS REQUIRED
8051 Microcontroller Kit
COUNT THE NUMBER OF ODD& EVEN NUMBERS IN AN ARRAY
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
MOV DPTR,#8150
MOVX A,@DPTR
MOV R0,A
MOV R1,#00
MOV R2,#00
L3 INC DPTR
MOVX A,@DPTR
RRC A
JNC L1
INC R1
SJMP L2
L1 INC R2
L2 DJNC R0, L3
INC DPTR
MOV A, R1
MOVX @DPTR, A
INC DPTR
MOV A, R2
MOVX @DPTR, A
L4 L4 SJMP L4
63
Test Data: Observed Test Data:
INPUT OUTPUT
INPUT OUTPUT
Address/Reg Data Address Data
Address/Reg Data Address Data
8150 05 8600 02 (odd)
8150 05 8600
8151 00 8601 03 (even)
8151 55 8601
8152 02
8152 18
8153 03
8153 03
8154 04
8154 4C
8155 05
8155 EF
FIND POSITIVE OR NEGATIVE
NUMBER
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
MOV DPTR,#8150
MOVX A,@DPTR
RLC A
JNC L1
MOV R0,#00
SJMP L2
L1 MOV R0,#01
L2 MOV A,R0
INC DPTR
MOVX @DPTR,A
L3 SJMP L3
64
INPUT OUTPUT
Address/ Data Address Data INPUT OUTPUT
Reg Address/ Data Address Data
8150 F5 8151 01 Reg
(negative) 8150 8151
8150 09 8151 00 8150 8151
(positive)
INFERENCES :
Max. Marks
Category
Marks Awarded
Preparation 10
Performance 30
Result 40
Viva-voce 10
Record 10
TOTAL 100
RESULT:
Thus the ALP to perform following operations was executed and verified using
8051 microcontroller.
(i) Count the number of odd & even numbers in an array
(ii) Find positive or negative number
65
CYCLE IV – INTERFACING PROGRAMMING
66
Ex. No. 12 Date :
APPARATUS REQUIRED
Microprocessor Kit 8086, Keyboard / Display Interfacing Kit.
HARDWARE DESCRIPTION:
The 8279 is a general purpose programmable keyboard / display interface device.
The keyboard portion of 8279 can provide a scanned interface to a 64 contact key
matrix. Keyboard entries are debounced and strobed- in as 8- character FIFO
automatically. The display portion provides a scanned display interface for 8 or 16
LED display. Both right entry (eg. Calculator) and left entry (eg. Type writer format)
are possible. 8279 has 16 X 8 displays RAM to accommodate seven segment codes for
16 digit displays.
LOOK-UP TABLE:
ADDRESS/REG DATA
1200 FF FF FF FF
1204 FF FF FF FF
1208 98 68 7C C8
120C FF 1C 29 FF
67
LED SEGMENT:
f
b
g
c
e
.dp
Data bus D7 D6 D5 D4 D3 D2 D1 D0
Segments d c b a db g f e
MNEMONICS:
Rolling display (display message “HELP US”)
68
CALL DELAY E8, 06, 00
INC SI
LOOP NEXT
JMP START EB, E2, FF
DELAY MOV DX, A0FF
LOOP1: DEC DX
JNZ LOOP1
RET
INFERENCES:
Max. Marks
Category
Marks Awarded
Preparation 10
Performance 30
Result 40
Viva-voce 10
Record 10
TOTAL 100
RESULT:
Thus Keyboard / display interface (8279) was interfaced with microprocessor
8086 and the given message ‘HELP US’ was also rotated.
69
INTERFACING PROGRAMMABLE INTERVAL TIMER (8253)
AIM:
To write an ALP to interface the programmable interval timer (8253) with
microprocessor 8086 and to generate the square wave.
APPARATUS REQUIRED:
Microprocessor Kit 8086, Programmable Interval Timer Kit, CRO
HARDWARE DESCRIPTION:
8253 is a programmable interval timer/counter is organized as three
independent 16 bit counter, each with a count rate of up to 2.6 MHz. Each counter has
three inputs i.e., clock input for counter, gate enable input and output. Counter can be
operated by programming its control word. The counter can be used as either as a BCD
or as binary counter.
PROCEDURE
Output the control word to control register.
Output the count.
The output in CRO will remain high until one half of count and go low for
the order 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.
Set the jumper to connect the CLK 0 of 8253 to PCLK of frequency 1.5 MHz.
The following program divides this PCLK by 10 and thus the output at chan-
nel 0 is 150 KHz. Hence a square wave of frequency 150 KHz is generated at
channel 0.
CONTROL WORD: 36
70
0 0 1 1 0 1 1 0
PROGRAM:
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
MOV AL, 36
OUT CE, AL
MOV AL, 10
OUT C8, AL
MOV AL, 00
OUT C8, AL Max. Marks
Category
HLT Marks Awarded
Preparation 10
INFERENCES: Performance 30
Result 40
Viva-voce 10
Record 10
TOTAL 100
RESULT:
Thus the programmable interval timer (8253) was interfaced with
microprocessor 8086 and the square wave was also generated.
Ex. No. 14 Date :
71
INTERFACING TRAFFIC LIGHT CONTROLLER (8255)
AIM:
To write an ALP to interface a traffic light controller with microprocessor 8086
using 8255 interface and to control the flow of traffic at a four way junction.
APPARATUS REQUIRED:
8086 Microprocessor Kit, Traffic Light Controller Interfacing Kit.
HARDWARE DESCRIPTION:
The kit consists of four road four lane junction which consist of green, yellow &
red LED. The LED’s are made ON & OFF for controlling the traffic flow. For
pedestrian there is dual color LED (green & red).
The traffic light controller kit is interfaced with microprocessor kit via 8255.
8255 acts in mode 0 operation. Here ports A& B are used as an output port. To make
pedestrian LED green make the bit 0, for red make the bit 1. For other LED to glow set
1 otherwise set 0.
PB7 G PA4
Y PA6
PB1 PA5 PA1
G Y R R PA7
PB4 PB6
PB3 R
PB2 Y R Y G
PB0 G PA3 PA2 PA0
PB5
CONTROL WORD: 80
72
D7 D6 D5 D4 D3 D2 D1 D0
1 0 0 0 0 0 0 0
TRAFFIC FLOW
73
CONTROL WORDS:
R G
G G A7 A6 A5 A4 A3 A2 A1 A0 B7 B6 B5 B4 B3 B2 B1 B0
0 0 0 1 1 0 1 0 1 0 1 0 0 0 0 1
= 1A = A1
G R
Y Y A7 A6 A5 A4 A3 A2 A1 A0 B7 B6 B5 B4 B3 B2 B1 B0
0 1 1 0 0 1 0 0 1 0 1 0 0 1 0 0
G G
= 64 = A4
Y Y
G G
R
A7 A6 A5 A4 A3 A2 A1 A0 B7 B6 B5 B4 B3 B2 B1 B0
1 0 0 0 0 0 0 1 0 1 0 1 1 0 1 0
= 81 = 5A
R G
G
Y G
Y A7 A6 A5 A4 A3 A2 A1 A0 B7 B6 B5 B4 B3 B2 B1 B0
0 1 1 0 0 1 0 0 0 1 0 1 0 1 0 0
= 64 = 54
Y Y
G
74
PORT A ADDRESS = 20
PORT B ADDRESS = 22
CONTROL REGISTER = 26
Max. Marks
Category
Marks Awarded
Preparation 10
Performance 30
Result 40
Viva-voce 10
Record 10
TOTAL 100
RESULT:
Thus the traffic light controller was interfaced with 8086 microprocessor kit using
8255 interface and flow of traffic at a four way junction was also controlled.
76
AIM:
To interface a stepper motor controller with microprocessor 8086 and to run the
stepper motor at different speed in both clock wise and anticlockwise directions.
APPARATUS REQUIRED:
Microprocessor Kit 8086, Stepper Motor Controller Interfacing Kit.
HARDWARE DESCRIPTION:
A stepper motor is a motor in which the rotor is able to assume only discrete
stationary angular position. In the given stepper motor there are 4 stator poles and pairs
of rotor poles. Therefore there exits 12 possible stable positions in which a south pole
of the rotor can lock with a north pole of stator. The stable positions can be attained by
simply energizing the winding on any one of the stator pole with DC supply.
The different stepping schemes are
1. Wave scheme.
2. Two phase scheme.
3. Half stepping scheme.
Two phase scheme:
When the winding on two successive stator poles are exited, then typical
equilibrium condition of rotor is obtained. The stator poles are A1, A2, B1 & B2. The
step angle is 30 degree. The Switching sequence for 2-phase scheme is given in the
table.
MNEMONICS:
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
START: MOV DI, 1016
MOV CL, 04
REPT: MOV AL, [DI]
OUT C0, AL
MOV DX, 1010
DELAY: DEC DX
JNZ DELAY
INC DI
77
LOOP REPT
JMP START
NOTE : The speed of the motor can be varied by varying the content of DX register
CLOCKWISE ANTICLOCKWISE
STEP A1 A2 B1 B2 STEP A1 A2 B1 B2
1 1 0 0 1 1 1 0 1 0
2 0 1 0 1 2 0 1 1 0
3 0 1 1 0 3 0 1 0 1
4 1 0 1 0 4 1 0 0 1
INFERENCES:
Max. Marks
Category
Marks Awarded
Preparation 10
Performance 30
Result 40
Viva-voce 10
Record 10
TOTAL 100
RESULT:
Thus stepper motor controller was interfaced with microprocessor 8086 and the
stepper motor was rotated at different speed in both clock wise and anticlockwise
directions.
Ex. No. 16 Date :
TIMER/COUNTER USING 8051 PROGRAMMING RESOURCES
78
AIM
1. To write an ALP to generate a square wave of frequency 1KHz at port 1.5,
use timer 1 with the crystal frequency of 11.0592MHz
2. To write an ALP to generate square waveform of 1KHz frequency at port 1.4
using software time delay
APPARATUS REQUIRED
8051 microcontroller kit and CRO
PROGRAM
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
MOV TMOD,#10H
SETB P1.5
TOP: MOV TL1,#33H
MOV TH1,#FEH
SETB TR1
BACK: JNB TF1,BACK
CLR TF1
CLR TR1
CPL P1.5
SJMP TOP
ADDRESS LABEL MNEMONICS OP CODE COMMENTS
SETB P1.4
LCALL DELAY
TOP: CPL P1.4
LCALL DELAY
SJMP TOP
DELAY MOV R0,#E5H
BACK: DJNZ R0, BACK
RET
CALCULATION
79
I. To write an ALP to generate a square wave of frequency 1KHz at port 1.5 ,use
timer 1 with the crystal frequency of 11.0592MHz
Crystal frequency = 11.0592MHz
Timer frequency (Tf) =Crystal frequency/12 =921.6 KHz
Timer period = 1/Tf = 1.085 µs
Required time delay = [FFFF-Timer count +1]* timer period
500µs = [65535-timercount +1] * 1.085µs
Timer count = 65536-491
65075d
FE33H
II. To write an ALP to generate square waveform of 1KHz frequency at port 1.4 us-
ing software time delay
Crystal frequency = 11.0592MHz
Timer frequency (Tf) =Crystal frequency/12 =921.6 KHz
Timer period = 1/Tf = 1.085 µs
Time delay calculation
MOV R0,#E5H 1
BACK: DJNZ R0,BACK 2*COUNT
RET 2
3+2*COUNT
[3+2*COUNT]*1.085 µs=DESIRED TIME DELAY
[3+2*COUNT]=500/1.085 µs=461
2*COUNT=461-3
C0UNT=458/2=229=E5H
80
INFERENCES :
Max. Marks
Category
Marks Awarded
Preparation 10
Performance 30
Result 40
Viva-voce 10
Record 10
TOTAL 100
RESULT:
Thus the ALP to generate a square wave of frequency 1KHz at port 1.5 ,use
timer 1 with the crystal frequency of 11.0592 MHz and to generate square waveform of
1KHz frequency at port 1.4 using software time delay were executed and verified using
8051 microcontroller.
81
Ex. No. 17 Date :
COMMUNICATION BETWEEN 8051 MICROCONTROLLER KIT AND PC
AIM
To write a C program to interface DIP switch of 8051 microcontroller Kit with PC.
APPARATUS REQUIRED
8051 Microcontroller Kit and PC (installed with KEIL software)
PROGRAM
#include<reg51.h> //Define 8051 Registers
#define SW P2 //Define Switch to Port2
#define Led P0 //Define Led to Port0
//----------------------
// Main Function
//----------------------
void main()
{
// P2=0xff; //Port-2 as input to FFh
//P0=0x00; //Port-0 as output to 00h
while(1) //Loop Forever
{
Led = SW; //Assign the Switch value to Led
}
}
NOTE:
The DIP switch is connected to the port-2 active low '0' and the LED to
the port-0.
Make jumper jp4 to enable position
82
PROCEDURE
1. Open the Keil software from desktop.
2. To create a new project: - Project -> New project. Type the project name and
save. From project menu, select device for target. Then a window opens. Select
ATMEL -> AT89C51 from that window. Click OK. Then click “no” for the
question “copy standard 8051 start up code”?
3. To set the options for your target:- Project Options for target
Change the crystal value to 11.0592MHz.
Enable “Create Hex file “option from output menu bar.
Then click O.K
4. To type the program and to save: - File New. Type the program. Then
Filesave. Give the Filename with ‘.C’ extension to save the file. Then Click
save.To add the Program to your project:-
Expand the target 1 tab(Press on ‘+’)
Right click on source group 1
Select Add files to group select your program file. Click
Add Click close
5. To create Hex file: Project Build target. correct the errors, if any. The hex file
will be created in the name of your project. close the keil software.
6. Download the hex file into flash magic.(open flash magic from desktop)
A. Communication
Comm. port : Com 1
Baud rate:9600
Device :89V51RD2
Ineterface:none
B. Erase select “erase all Flash”
C. Hex file
Load the created hex file by using browse button.
In ISP pull down menu, select ‘Read Device signature” is read.
The device signature’s manufacture ID: BF, device ID:91
In “options” menu,-Advanced optionCommunication
83
Select Half –duplex Communication.
Select “Hard ward configuration”
Select “Assert DTR and RTS while COM port open
Select Verify “After programming”
Click “start” .After Display “Finished” message. Turn on the
Flash magic kit. Also setting appropriate switch position (SW 30)
to “ 7-seg” program is verified.
INFERENCES:
Max. Marks
Category
Marks Awarded
Preparation 10
Performance 30
Result 40
Viva-voce 10
Record 10
TOTAL 100
RESULT:
Thus, the C program to interface DIP switch of 8051 microcontroller kit
with PC was executed and verified using KEIL software.
84
Ex. No. 18 Date :
SERIAL COMMUNICATION USING 8251
AIM
To transmit series of data between two microprocessor kits (8086) using 8251
APPARATUS REQUIRED
1. 8086 microprocessor kit 2
2. Serial cable 1
PROGRAM TRANSMITTER
85
1013 TEST AL,04 A8 04
1015 JZ CHECK 74 FA
1017 MOV AL,[SI] 8A 04
1019 OUT 08,AL E6 08
101B INC SI 46
101C CMP AL,3FH 3C 3F Check EOF
101E JNZ RELOAD 75 EF
1020 LOOP CHECK E2 EF
1022 INT 02 CD 02 Reset the system
Test data:
INPUT(transmitter) OUTPUT(Receiver)
Address/Reg Data Address Data
1500 11 1500 11
1501 22 1501 22
1502 33 1502 33
1503 44 1503 44
1504 55 1504 55
1505 3F
1506 3F
1507 3F
1508 3F
1509 3F
86
PROGRAM - RECEIVER
87
PROCEDURE
1. In the transmitter system, the data to be transmitted, are stored starting from
the
memory location, indicated by the memory pointer (1500H as per the above
program).
2. 5 Consecutive "3F"s are stored at the end of the data stream to indicate EOF.
3. The receiver program is executed first and then the transmitter program.
4. The received data are verified, starting from the memory location, indicated
by the memory pointer (1500H as per the above program).
INFERENCES:
Max. Marks
Category
Marks Awarded
Preparation 10
Performance 30
Result 40
Viva-voce 10
Record 10
TOTAL 100
RESULT:
88
Thus the assembly language program to transmit series of data between two
microprocessor kit (8086) using 8251 was executed and verified
89
PC PROGRAMMING WITH ASSEMBLY LANGUAGE USING MASM
Common Procedure:
2. In the command window type the directory name(ex: ‘d:’) after that change the
directory to 8086(masm) (ex: ‘cd masm’) after that type edit in that window to
go to program window
12. Type : e 1200[see output in corresponding address] use space bar to see next out-
put value]
90
Ex. No. 19 Date :
READ SCAN CODE AND CHARACTER CODE FROM KEYBOARD USING
MASM
AIM
To Write an ALP program to read scan code and character code from keyboard
using 8086 MASM assembler
REQUIREMENTS
PC with 8086 MASM Assembler
PROGRAM
Code segment
Assume cs: code, ds: code
Org 1000h
Mov ah, 0h
Int 16h
Mov si, 1200h
Mov [si], al
Inc si
Mov [si], ah
Mov ah, 4ch Max. Marks
Category
Marks Awarded
Preparation 10
Int 21h
Performance 30
Code ends
Result 40
End
Viva-voce 10
Record 10
TOTAL 100
91
Sample view:
RESULT:
92
Thus an ALP program to read scan code and character code from keyboard was
executed and verified using 8086 MASM assembler.
Ex. No. 20 Date :
STRING DISPLAY USING MASM
AIM
To write an ALP program to display the string “kcet” using 8086 MASM
assembler
REQUIREMENTS
PC with 8086 MASM Assembler
PROGRAM
Code segment
Assume cs: code, ds: code
Org 1000h
Mov ah, 09h
Mov dx, 1200h
Int 21h
Mov ah, 4ch
Int 21h
Org 1200h Max. Marks
Db “kcet$” Category
Marks Awarded
Code ends Preparation 10
End
Performance 30
Result 40
Viva-voce 10
Record 10
TOTAL 100
RESULT:
93
Thus an ALP program to display the string “kcet” was executed and verified
using 8086 MASM assembler
VIVA QUESTIONS
94
Viva questions
1. Define opcode and operand?
95
16. What is the function of SHLD instruction?
96
35. What is the function of DEC DX instruction?
97
54. What is the function of JNC instruction?
64. How many memory locations can be addressed by a microprocessor with 14 address lines?
65. How many address lines are necessary to address two megabytes (2048K) of memory?
66. How many address lines are necessary to address two megabytes(2048K) of memory?
98
73. What is the purpose of BIU?
99
92. Define SEGEMNT and ENDS.
100