Download as pdf or txt
Download as pdf or txt
You are on page 1of 124

MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

OBSERVATION MANUAL
FOR

MICROPROCESSORS AND
MICROCONTROLLERS LAB
FOR B.TECH III YEAR I SEMESTER

NAME OF THE STUDENT:

ROLL NO.:

SECTION:

ACADEMIC YEAR: 2018 - 2019

VIGNAN INSTITUTE OF TECHNOLOGY AND SCIENCE


(Programmes Accredited by NBA and Certified by ISO 9001:2000)
(Approved by AICTE and Affiliated to JNT University, Hyderabad)
Vignan hills, Deshmukhi Village, Pochampally Mandal, Yadadri District - 508284
Sponsored by : Lavu Educational Society

Department of Electronics and Communication Engineering 1


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

COURSE OBJECTIVES AND COURSE OUTCOMES

Course objectives:
 This course is intended to
 Introduce the basic concepts of microprocessor and Microcontrollers.
 Develop in students the assembly language programming skills and real time
applications of Microprocessor as well as microcontroller.
 Understand how different I/O devices can be interfaced to Microprocessors.

Course Outcomes: After undergoing the lab course students will be able to
 Apply the fundamentals of assembly level programming of microprocessors and
microcontrollers.
 Analyze abstract problems and apply a combination of hardware and software to address
the problem
 Contrast how different I/O devices can be interfaced to processor and will explore
several techniques of interfacing.
 Experiment with standard microprocessor interfaces including serial ports, digital-to-
analog converters and analog-to-digital converters.

Department of Electronics and Communication Engineering 2


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

SYLLABUS

JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD


L T/P/D C - -/3/- 2

MICROPROCESSORS AND MICROCONTROLLERS LAB

1. Programs for 16 bit arithmetic operations for 8086 (using Various Addressing Modes).
2. Program for sorting an array for 8086.
3. Program for searching for a number or character in a string for 8086.
4. Program for string manipulations for 8086.
5. Program for digital clock design using 8086.
6. Interfacing ADC and DAC to 8086.
7. Parallel communication between two microprocessors using 8255.
8. Serial communication between two microprocessor kits using 8251.
9. Interfacing to 8086 and programming to control stepper motor.
10. Programming using arithmetic, logical and bit manipulation instructions of 8051.
11. Program and verify Timer/Counter in 8051.
12. Program and verify Interrupt handling in 8051.
13. UART Operation in 8051.
14. Communication between 8051 kit and PC.
15. Interfacing LCD to 8051.
16. Interfacing Matrix/Keyboard to 8051.
17. Data Transfer from Peripheral to Memory through DMA controller 8237/8257.

Note: Minimum of 12 experiments to be conducted.

Department of Electronics and Communication Engineering 3


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

Department of Electronics and Communication Engineering 4


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

INDEX
S.No. NAME OF THE EXPERIEMNT Page No. Remarks

1 Programs for 16 bit arithmetic operations for 8086 (using Various


15
Addressing Modes).
2 Program for sorting an array for 8086. 21

3 Program for searching for a number or character in a string for


25
8086.
4 Program for string manipulations for 8086. 31

5 Program for digital clock design using 8086. 41

6 Interfacing ADC and DAC to 8086. 47

7 Parallel communication between two microprocessors using 8255. 57

8 Serial communication between two microprocessor kits using 8251. 61

9 Interfacing to 8086 and programming to control stepper motor. 65

10 Programming using arithmetic, logical and bit manipulation


77
instructions of 8051.
1 Program and verify Timer/Counter in 8051. 83

2 Program and verify Interrupt handling in 8051. 87

3 UART Operation in 8051. 91

4 Communication between 8051 kit and PC. 95

5 Interfacing LCD to 8051. 99

6 Interfacing Matrix/Keyboard to 8051. 107

7 Data Transfer from Peripheral to Memory through DMA controller


111
8237/8257.

ADDITIONAL EXPERIEMNTS
8 Program to find number of Even and Odd numbers in a given array. 117

9 Program to find number of Positive and Negative numbers in a


121
given array.
10 Program to find number of Largest and Smallest numbers in a given
125
array.

Department of Electronics and Communication Engineering 5


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

Department of Electronics and Communication Engineering 6


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

INTRODUCTION TO 8086 MICROPROCESSOR

8086 ARCHITECTURE:

Department of Electronics and Communication Engineering 7


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PIN DIAGRAM:

8086 INSTRUCTION SET SUMMARY:


The following is a brief summary of the 8086 instruction set:

Data Transfer Instructions


MOV : Move byte or word to register or memory
IN, OUT : Input byte or word from port, output word to port
LEA : Load effective address
LDS, LES : Load pointer using data segment, extra segment
PUSH, POP : Push word onto stack, pop word off stack
XCHG : Exchange byte or word
XLAT : Translate byte using look-up table

Department of Electronics and Communication Engineering 8


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

Logical Instructions
NOT : Logical NOT of byte or word (one's complement)
AND : Logical AND of byte or word
OR : Logical OR of byte or word
XOR : Logical exclusive-OR of byte or word
TEST : Test byte or word (AND without storing)

Shift and Rotate Instructions


SHL SHR : Logical shift left, right byte or word by 1 or CL
SAL SAR : Arithmetic shift left, right byte or word by 1 or CL
ROL ROR : Rotate left, right byte or word by 1 or CL
RCL RCR : Rotate left, right through carry byte or word by 1 or CL

Arithmetic Instructions
ADD SUB : Add, subtract byte or word
ADC SBB : Add, subtract byte or word and carry (borrow)
INC DEC : Increment, decrement byte or word
NEG : Negate byte or word (two's complement)
CMP : Compare byte or word (subtract without storing)
MUL DIV : Multiply, divide byte or word (unsigned)
IMUL IDIV : Integer multiply or divide byte or word (signed)
CBW CWD : Convert byte to word, word to double word (useful before
multiply/divide)
AAA,AAS,AAM,AAD: ASCII adjust for addition, subtraction, multiplication,
division (ASCII codes 30-39)
DAA, DAS : Decimal adjust for addition, subtraction (binary coded
decimal numbers)

Transfer Instructions
JMP : Unconditional jump
JA (JNBE) : Jump if above (not below or equal)
JAE (JNB) : Jump if above or equal (not below)
JB (JNAE) : Jump if below (not above or equal)
JBE (JNA) : Jump if below or equal (not above)
JE (JZ) : Jump if equal (zero)
JG (JNLE) : Jump if greater (not less or equal)
JGE (JNL) : Jump if greater or equal (not less)
JL (JNGE) : Jump if less (not greater nor equal)
JLE (JNG) : Jump if less or equal (not greater)

Department of Electronics and Communication Engineering 9


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

Department of Electronics and Communication Engineering 10


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

INTRODUCTION TO MASM
MS-MASM:
Microsoft’s Macro Assembler (MASM) is an integrated software package Written by
Microsoft Corporation for professional software developers. it consists of an editor, an
assembler, a linker and a debugger(Code View). The programmer’s workbench
combines these four parts into a user-friendly programming environment with built in on
line help. The following are the steps used if you are to run MASM from DOS.
Summarized basic DOS - Debugger commands.

EDITOR:
An editor is a program, which allows you to create a file containing the assembly
language statements for your program. As you type in your program the editor stores the
ASCII codes for the letters and numbers in successive RAM locations. When you have
typed in all of your programs you then save the file on a floppy of hard disk. This file is
called source file. The next step is to process the source file with an assembler. In the
MASM/TASM assembler you should give your source file name the extension .ASM

ASSEMBLER:
An assembler program is used to translate the assembly language mnemonics for
instructions to the corresponding binary codes. When you run the assembler it reads the
source file of your program from the disk where you saved it after reading on the first pass
through the source program, the assembler determines the displacement of named data
items, the offset of labels and this information is stored on a symbol table. On the second
pass through the source program, the assembler produces the binary code for each
instruction and inserts the offset etc that was calculated during the first pass. The
assembler generates two files on floppy or hard disk. The first file called the object file
is given the extension. OBJ. The object file contains the binary codes for the
instructions and information about the addresses of the instructions. The second file
generated by the assembler is called assembler list file. The list file contains your
assembly language statements the binary codes for each instructions and the offset
for each instruction. In MASM/TASM assembler MASM source file name ASM is
used to assemble the file. Edit source file name LST is used to view the list file which is
generated, when you assemble the file.

Department of Electronics and Communication Engineering 11


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

LINKER:

A linker is a program used to join several object files into one large object file and
convert it to an exe file. The linker produces a link file, which contains the binary codes for
all the combined modules. The linker however doesn’t assign absolute addresses to the
program, it assigns is said to be re-locatable because it can be put anywhere in
memory to be run. In TASM/MASM LINK source filename is used to link the file.

DEBUGGER:

A debugger is a program which allows you to load your object code program into system
memory, execute the program and troubleshoot or debug it. The debugger allows you to
look at the contents of registers and memory locations after your program runs. It allows
you to change the contents of register and memory locations after your program runs. It
allows you to change the contents of register and memory locations and return the
program. A debugger also allows you to set a break point at any point in the
program. If you inset a breakpoint the debugger will run the program up to the
instruction where the breakpoint is set and stop execution. You can then examine
register and memory contents to see whether the results are correct at that point. In
MASM, MD filename is used to debug the file.

DEBUGGER FUNCTIONS:

1. Debugger allows to look at the contents of registers and memory locations.


2. We can extend 8-bit register to 16-bit register with the help of extended register option.
3. Debugger allows to set breakpoints at any point with the program.
4. The debugger will run the program up to the instruction where the breakpoint is set and
then stop execution of program. At this point, we can examine registry and memory
contents at that point.
5. With the help of dump we can view register contents.
6. we can trace the program step by step with the help of T.
7. We can execute the program completely at a time using G.

Department of Electronics and Communication Engineering 12


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

COMMAND SYNTAX

Assemble A [address]
Compare C range address
Dump D [range]
Enter E address [list]
Fill F range list
Go G [=address] [addresses]
Hex H value1 value2
Input I port
Load L[address] [drive][first sector][number]
Move M range address
Name N[pathname][argument list]
Output O port byte
Proceed P [=address][number]
Quit Q [Quit]
Register R[register]
Search S range list
Trace T [=address][value]
Unassembled U [range]
Write W [address}[drive][first sector][number]

MICROPROCESSOR MASM EXECUTION PROCEDURE

STEP1: Opening DOS prompt, Click on start menu button and click on Run and then
type CMD at command prompt DOS window will be appeared.

STEP2: Checking the MASM installation. To know MASM is installed or not simply
type MASM at the command prompt Upon that it replies MASM version vendor
(Microsoft), etc., If you get any error there is no MASM in that PC.

STEP3: Directory changing (create a folder with your branch and not in C drive)
Change the current directory to your own directory suppose your folder in D drive type
the following commands to change the directory at command prompt type D: hit enter,
now you are in D drive type cd folder name hit the enter.
Ex. D: cd MASM/ECEA
Now we are in folder ECEA

STEP4: writing the program. At the command prompt type the edit programname.asm
Ex. Edit add1.asm
Immediately editor window will be opened. Type the program in that window. After
completion, save the program. To save the program, go to file opt in the menu bar and
select save opt now your code is ready to assemble.

STEP5: Assembling, linking and executing the program Go to file opt& click exit opt.
Now DOS prompt will be displayed ,to assemble the program type the following
commands at the DOS prompt MASM program name, program name, program name hit
the enter.
Ex. MASM add1.asm;

Department of Electronics and Communication Engineering 13


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

If there are any errors in the program assembler reports all of them at the command
prompt with line no’s, if there are no bugs you are ready to link the program. To link the
program type the following line at command prompt.
Link program name
Ex. Link add1.Obj;
After linking to execute the program type the following command
Debug programname.exe hit the enter
Ex. Debug add1.exe
To execute the program, instruction by instruction (debugging) first of all press the R
key (register) hit the enter key, it’ll displays all the registers and their initial values in
HEXADECIMAL note down the values of all the register which are used in the
program. To execute the next instruction press t key (TRACE) hit the enter it’ll execute
that instruction and displays the contents of all the register. You have to do this until you
reach the last instruction of the program. After execution you have to observe the results
(in memory or registers based on what you have written in the program).

STEP6: copying list file (common for all programs):


A list file contains your code starting address and end address along with your program
For every program assembler generates a list file at your folder, Programname.lst (ex.
Add.lst) you should copy this to your lab observation
Opening a list file Edit programname.lst
Ex. Edit add1.lst

Department of Electronics and Communication Engineering 14


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

EXPERIMENT 1

Programs for 16 bit arithmetic operations for 8086 (using Various Addressing
Modes).
PROGRAM 1 (A): 16-bit Numbers Addition/Subtraction using Immediate Addressing
Mode

OBJECTIVE: To write an assembly language program for perform


Addition/Subtraction using Immediate Addressing Mode.

TOOLS REQUIRED: PC With installed Windows 7, DOSBOX and MASM.

FLOW CHART:

PROGRAM:

ASSUME CS:CODE
CODE SEGMENT
Start:
MOV AX, 1235
ADD AX, 4683 ; SUB for Subtraction
INT 03H
CODE ENDS
END Start

OUTPUT:

Department of Electronics and Communication Engineering 15


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM 1 (B): 16-bit ARITHMETIC OPERATIONS FOR 8086 USING DIRECT


ADDRESSING MODE AND REGISTER ADDRESSING MODE.

OBJECTIVE: To write an assembly language program for perform arithmetic


operations in 8086 using Direct addressing mode and Register addressing mode.

TOOLS REQUIRED: PC With installed Windows 7, DOSBOX and MASM.

FLOW CHART:

Department of Electronics and Communication Engineering 16


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:

ASSUME CS:CODE, DS:DATA


DATA SEGMENT
N1 DW 1525H
N2 DW 2695H
SUM DW ?
DIFF DW ?
MULT1 DW ?
MULT2 DW ?
REM DW ?
QUO DW ?
DATA ENDS

CODE SEGMENT
Start: MOV AX, DATA // Initialization of data segment
MOV DS, AX
MOV AX, 0000H // XOR AX, AX
MOV AX, N1
ADD AX, N2 // Direct Addressing Mode
MOV SUM, AX
MOV AX, N1
SUB AX, N2
MOV DIFF, AX
MOV AX,N1
MOV BX,N2
MUL BX // Register
MOV MULT 1, AX
MOV MULT 2, DX
MOV AX, N1
MOV BX, N2
XOR DX, DX
DIV BX
MOV REM, DX
MOV QUO, AX
INT 03H
CODE ENDS
END Start

OUTPUT:

Department of Electronics and Communication Engineering 17


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM 1 (C): 16-bit ARITHMETIC OPERATIONS FOR 8086 USING


INDEXED ADDRESSING MODE.

OBJECTIVE: To write an assembly language program for perform arithmetic


operations in 8086 using Indexed addressing mode.

TOOLS REQUIRED: PC With installed Windows 7, DOSBOX and MASM.

FLOW CHART:

Department of Electronics and Communication Engineering 18


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:

ASSUME CS:CODE, DS:DATA


DATA SEGMENT
ORG 1000H // Organizing the memory
N DW 1525H, 2695H // Defining the array in 8086
SUM DW ?
DATA ENDS
CODE SEGMENT
Start:
MOV AX, DATA
MOV DS, AX
LEA SI, N
MOV AX, [SI]
INC SI
INC SI
ADD AX, [SI]
MOV SUM, AX
INT 03H
CODE ENDS
END Start

OUTPUT:

RESULT:

Department of Electronics and Communication Engineering 19


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

VIVA QUESTIONS:

1. What are the various registers in 8086?

2. In 8086, name the 8 bit registers?

3. What are the various flags in 8086?

4. What is Stack Pointer?

5. What is Instruction pointer?

Department of Electronics and Communication Engineering 20


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

EXPERIMENT 2
PROGRAM FOR SORTING AN ARRAY FOR 8086

PROGRAM 2 A): Ascending order sorting

OBJECTIVE: To write an assembly language program to arrange the given numbers in


sorted order.

TOOLS REQUIRED: PC With installed Windows 7, DOSBOX and MASM.

FLOW CHART:

Department of Electronics and Communication Engineering 21


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:

ASSUME CS:CODE, DS:DATA


DATA SEGMENT
ORG 2000H
ARRAY1 DW 8342H,1452H,3536H,7741H,4502H // Declaring an array
LEN1 EQU ($-ARRAY1)/2 //EQU is a assembler directive
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA
MOV DS,AX
MOV BX,LEN1-1
ABC: MOV CX, BX // External Loop
LEA SI, ARRAY1
BACK: MOV AX,[SI] // Internal Loop
CMP AX,[SI+2] // Comparing
JC XYZ ;JNC for Descending order sorting // Jump if carrying is set
XCHG AX,[SI+2]
XCHG AX,[SI]
XYZ: INC SI
INC SI
DEC CX
JNZ BACK //if ZF is not equal then jump
DEC BX
JNZ ABC // Jump if zero flag ZF=0
INT 03H
CODE ENDS
END START

OUTPUT:

RESULT:

Department of Electronics and Communication Engineering 22


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

VIVA QUESTIONS:

1. What is the function of JNC?

2. What is the use of CMP instruction?

3. \What is the difference between conditional and unconditional jump instructions?

4. What is the function of XCHG in the program?

5. What is significance of accumulator?

Department of Electronics and Communication Engineering 23


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

Department of Electronics and Communication Engineering 24


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

EXPERIMENT 3
PROGRAM FOR SEARCHING FOR A NUMBER OR CHARACTER IN A
STRING FOR 8086.

PROGRAM 3 (A): Searching for a character in a string for 8086

OBJECTIVE: To write an assembly language program for searching for a character in a


string for 8086.

TOOLS REQUIRED: PC With installed Windows 7, DOSBOX and MASM.

FLOW CHART:

Department of Electronics and Communication Engineering 25


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:

ASSUME CS: CODE, DS: DATA


DATA SEGMENT
STR1 DB “PROCESSOR$” // Declaring a string
LEN EQU ($-STR1)
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
XOR AX, AX
LEA SI, STR1
MOV AL, ‘A’
MOV CX, LEN
L1:
CMP AL, [SI]
JE L2 // Jump if equal
INC SI
LOOP L1
MOV BX, 0000H // Character not found
INT 03H
L2:
MOV BX, 0FFFFH // Character is found
INT 03H
CODE ENDS
END START

OUTPUT:

Department of Electronics and Communication Engineering 26


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM 3 (B): Searching for a character in a string and displaying the outcome for
8086

OBJECTIVE: To write an assembly language program for searching for a character in a


string for 8086 and displaying the “Character found”/” Character not found”
accordingly.

TOOLS REQUIRED: PC With installed Windows 7, DOSBOX and MASM.

FLOW CHART:

Department of Electronics and Communication Engineering 27


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
STR1 DB “PROCESSOR$”
LEN EQU ($-STR1)
STR2 DB “CHARACTER FOUND$”
STR3 DB “CHARACTER NOT FOUND$”
ABC MACRO X // DOS function call of INT 21H
LEA DX, X // MACRO is similar to that of printf, It is used for displaying string
MOV AH, 09H
INT 21H
ENDM
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
LEA SI, STR1
MOV AL, ‘A’
MOV CX, LEN
L1:
CMP AL, [SI]
JE L2
INC SI
LOOP L1 // LEA DX, STR3
ABC STR3 // MOV AH, 09H
INT 03H // INT 21H
L2:
ABC STR2
INT 03H
CODE ENDS
END START

OUTPUT:

Department of Electronics and Communication Engineering 28


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

RESULT:

VIVA QUESTIONS:

1. Name 5 different addressing modes?

2. How many interrupts are there in 8086?

3. What is clock frequency for 8086?

4. What is the significance of DF (Direction Flag) in String Manipulations?

5. Name 5 different addressing modes?

Department of Electronics and Communication Engineering 29


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

Department of Electronics and Communication Engineering 30


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

EXPERIMENT 4
PROGRAM FOR STRING MANIPULATIONS FOR 8086.

PROGRAM 4 (A): DISPLAY STRING AND REVERSE STRING

OBJECTIVE: To write an assembly language program to display string and reverse the
given string.

TOOLS REQUIRED: PC With installed Windows 7, DOSBOX and MASM.

FLOW CHART:

Department of Electronics and Communication Engineering 31


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
STR DB 'VIGANA$'
LEN EQU $-STR
DATA ENDS
CODE SEGMENT
START:MOV AX,DATA
MOV DS,AX
LEA SI,STR
MOV CX,LEN-1
MOV DX,OFFSET STR // LEA DX, STR
MOV AH,09H // DOS function call for displaying a string
INT 21H
MOV AH, 2
MOV DL, 10 // /r ASCII value for return to zero
INT 21H
MOV AH, 2
MOV DL, 13 // /n ASCII value for new line
INT 21H
ADD SI,CX
DEC SI
BACK:
MOV DL,[SI]
MOV AH,02H
INT 21H
DEC SI
LOOP BACK
INT 3H
CODE ENDS
END START

OUTPUT:

Department of Electronics and Communication Engineering 32


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM 4 (B): CHARECTERS INSERTION IN THE GIVEN STRING

OBJECTIVE: To write an assembly language program to insert characters ‘MAKES’


after the word ‘VESSELS’ into the given string 'EMPTY VESSELS MORE NOISE'.

TOOLS REQUIRED: PC With installed Windows 7, DOSBOX and MASM.

FLOW CHART:

Department of Electronics and Communication Engineering 33


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:
ASSUME CS: CODE, DS: DATA, ES: EXTRA
DATA SEGMENT
STRING1 DB 'EMPTY VESSELS MORE NOISE$'
STRLEN EQU ($-STRING1)
DATA ENDS
EXTRA SEGMENT
STRING2 DB STRLEN+6 DUP (00)
EXTRA ENDS
CODE SEGMENT
START:MOV AX, DATA
MOV DS, AX
MOV AX, EXTRA
MOV ES, AX
MOV SI, OFFSET STRING1
MOV DI, OFFSET STRING2
CLD
MOV CX, 14
REP MOVSB
MOV DL, 5
BACK: MOV AH, 01
INT 21H
STOS STRING2
DEC DL
JNZ BACK
MOV CX, 11
REP MOVSB
INT 3H
CODE ENDS
END START

OUTPUT:

Department of Electronics and Communication Engineering 34


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM 4 (C): CHARECTERS DELETION IN THE GIVEN STRING

OBJECTIVE: To write an assembly language program to delete an extra character ‘D’


in the word ‘ANDD’ in the given string 'MICROPROCESSORS ANDD
MICROCONTROLLERS$'.

TOOLS REQUIRED: PC With installed Windows 7, DOSBOX and MASM.

FLOW CHART:

Department of Electronics and Communication Engineering 35


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:
ASSUME CS: CODE, DS: DATA, ES: EXTRA
DATA SEGMENT
STRING1 DB 'MICROPROCESSORS ANDD MICROCONTROLLERS$'
STRLEN EQU ($-STRING1)
DATA ENDS
EXTRA SEGMENT
STRING2 DB STRLEN-1 DUP (0)
EXTRA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AX, EXTRA
MOV ES, AX
MOV SI, OFFSET STRING1
MOV DI, OFFSET STRING2
CLD
MOV CX, 19
REP MOVSB
CLD
INC SI
MOV CX, 18
REP MOVSB
INT 3H
CODE ENDS
END START

OUTPUT:

Department of Electronics and Communication Engineering 36


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM 4 (D): COMPAIRISON OF TWO STRINGS

OBJECTIVE: To write an assembly language program for comparison of two strings.

TOOLS REQUIRED: PC With installed Windows 7, DOSBOX and MASM.

FLOW CHART:

Department of Electronics and Communication Engineering 37


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:
ASSUME CS:CODE, DS:DATA, ES:EXTRA
DATA SEGMENT
STRING1 DB 'EMPTY'
STRLEN EQU ($-STRING1)
NOTSFUL DB 'STRINGS ARE UNEQUAL$'
SFUL DB 'STRINGS ARE EQUAL$'
DATA ENDS
EXTRA SEGMENT
STRING2 DB 'EMVTY'
EXTRA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AX, EXTRA
MOV ES, AX
MOV SI, OFFSET STRING1
MOV DI, OFFSET STRING2
CLD
MOV CX, STRLEN
REP CMPSB
JE FORW
MOV AH, 09H
MOV DX, OFFSET NOTSFUL
INT 21H
JMP EXITP
FORW:MOV AH,09H
MOV DX, OFFSET SFUL
INT 21H
EXITP:
NOP
MOV AH, 4CH
INT 21H
INT 3H
CODE ENDS
END START

Department of Electronics and Communication Engineering 38


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

OUTPUT:

RESULT:

VIVA QUESTIONS:

1. What are Software interrupts?

2. Which interrupt has the highest priority?

3. Explain about "LEA"?

4. Define Pipelining?

Department of Electronics and Communication Engineering 39


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

5. What is the main use of ready pin?

Department of Electronics and Communication Engineering 40


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

EXPERIMENT 5
PROGRAM FOR DIGITAL CLOCK DESIGN USING 8086.

PROGRAM 5 (A): SIMULATING DIGITAL CLOCK

OBJECTIVE: To write an assembly language program to display S for every second,


M for every minute and H for every hour on the computer screen.

TOOLS REQUIRED: PC With installed Windows 7, DOSBOX and MASM.

FLOW CHART:

Department of Electronics and Communication Engineering 41


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:
ASSUME CS:CODE, DS:DATA
DATA SEGMENT
STR1 DB 'S$'
STR2 DB 'M$'
STR3 DB 'H$'
DATA ENDS
CODE SEGMENT
START:MOV AX,DATA
MOV DS,AX
XOR DX,DX
L1:XOR AX,AX
XOR BX,BX
XOR CX,CX
XOR DI,DI
L2:CALL DELAY
LEA DX,STR1
MOV AH,09H
INT 21H
INC BL
CMP BL,59D
JNZ L2
LEA DX,STR2
MOV AH,09H
INT 21H
XOR BL,BL
INC BH
INT 03H
CMP BH,59D
JNZ L2
LEA DX,STR3
MOV AH,09H
INT 21H

Department of Electronics and Communication Engineering 42


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

XOR BH,BH
INC DI
CMP DI,23D
JNZ L2
JMP L1
DELAY PROC NEAR
MOV SI,7
X1:MOV CX,0FFFFH
X2:NOP
NOP
LOOP X2
DEC SI
JNZ X1
RET
DELAY ENDP
INT 03H
CODE ENDS
END START

OUTPUT:

Department of Electronics and Communication Engineering 43


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

RESULT:

VIVA QUESTIONS:
1. What is the use of HLDA?

2. What are MUL & IMUL instructions?

3. What is the significance of 2-Pass assembler?

4. How many bits is 8085 microprocessor?

5. What is the memory size of 8085 microprocessor?

Department of Electronics and Communication Engineering 44


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

6. Windows Driver for ESA86-2 Trainer (WIN86-2)


TESTING THE INSTALLATION:
1) Switch on the PC.
2) Connect ESA86-2 Trainer to the Host PC using 9 to 9 pin serial cable supplied by ESA.
3) Give power to ESA86-2 Trainer.
4) Make the Dipswitches on ESA86-2 Trainer for 9600 baud rate and for serial monitor
(Refer ESA86-2 user manual Hard copy).
5) Start Win86-2 application on Host PC. You should then see the following Dialog Box.

6) If the Trainer is connected to COM1 port on your Host PC & configured for 9600- baud
rate, click No. Click Yes otherwise. If yes, you will see the following dialog box.

7) Select the BaudRate as per the dipswitch configuration on ESA86-2 Trainer. Select the
Com Port where the trainer is connected. Click Apply. You should then see the
following window. Win86-2 User Manual Page 7 of 9

Department of Electronics and Communication Engineering 45


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

8) In some cases if the communication is not established you will see the following dialog
box. In this case please check the Power on ESA86-2 Trainer. Check whether Serial
cable is connected to the PC & ESA86-2 Trainer and check the parameter by clicking
Settings.

9) If the communication is established properly, from the displayed window you can work
with ESA86-2 Trainer. You can view the Registers, Memory Dumps, Download the hex
images, Upload the hex dump to the Host PC, Run the downloaded hex images, single
stepping, breakpoints, watch windows, Memory modification etc.,
These options are explained in detail in online help of Win86-2 (Win86-2.hlp).

Note:- Whenever the command window is full, it is recommended to clear the


command window with “ CLS “ command. Otherwise display will become a little
bit slower.

TROUBLE SHOOTING:
1) Check the PC Serial Port working condition.
2) Check the Serial Cable working condition.
3) Check ESA86-2 Trainer Kit for Signon message (On LED).
4) Dipswitch Settings

NOTE: Same Way Windows Driver for ESA31 Trainer (WIN31) can be used to
interface 8051 (ESA31) Trainer kit with PC.

Department of Electronics and Communication Engineering 46


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

EXPERIMENT 6
INTERFACING ADC AND DAC TO 8086.
PROGRAM 6 (A): INTERFACING ADC TO 8086

OBJECTIVE: To write an assembly language program to interface Analog to Digital


converter to 8086 kit.

TOOLS REQUIRED: 8086 trainer kit with power adapter, ADC interfacing board, PC
With installed Windows 7, DOSBOX and MASM.

FLOW CHART:

Department of Electronics and Communication Engineering 47


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:
ASSUME CS: CODE
CODE SEGMENT
ORG 2000H
START:MOV DX,0FFE6H
MOV AL,8BH
OUT DX,AL
MOV AL,10H
MOV DX,0FFE0H
OUT DX,AL
NOP
NOP
MOV AL,00H
OUT DX,AL
MOV DX,0FFE4H
L1:IN AL,DX
AND AL,00H
JNZ L1
L2:IN AL,DX
AND AL,01H
JNZ L2
MOV DX,0FFE0H
MOV AL,40H
OUT DX, AL
MOV DX, 0FFE2H
IN AL,DX
INT 03H
CODE ENDS
END START

OUTPUT:

Department of Electronics and Communication Engineering 48


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM 6 (B): INTERFACING DAC TO 8086 FOR GENERATING SQUARE


WAVE

OBJECTIVE: To write an assembly language program to interface Digital to Analog


converter to 8086 kit for generating square wave.

TOOLS REQUIRED: 8086 trainer kit with power adapter, DAC interfacing board,
CRO, PC With installed Windows 7, DOSBOX and MASM.

FLOW CHART:

Department of Electronics and Communication Engineering 49


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:
ASSUME CS:CODE
CODE SEGMENT
ORG 2000H
START: MOV DX,0FFE6H
MOV AL,80H
OUT DX,AL
MOV DX,0FFE0H
L1: MOV AL,00H
OUT DX,AL
CALL DELAY
MOV AL,0FFH
OUT DX,AL
CALL DELAY
JMP L1
DELAY PROC NEAR
MOV CX,4005H
X1:NOP
NOP
LOOP X1
RET
DELAY ENDP
INT 03H
CODE ENDS
END START

OUTPUT:

Department of Electronics and Communication Engineering 50


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM 6 (C): INTERFACING DAC TO 8086 FOR GENERATING


TRIANGULAR WAVE

OBJECTIVE: To write an assembly language program to interface Digital to Analog


converter to 8086 kit for generating triangular wave..

TOOLS REQUIRED: 8086 trainer kit with power adapter, DAC interfacing board,
CRO, PC With installed Windows 7, DOSBOX and MASM.

FLOW CHART:

Department of Electronics and Communication Engineering 51


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:
ASSUME CS:CODE
CODE SEGMENT
ORG 2000H
START: MOV DX,0FFE6H
MOV AL,80H
OUT DX,AL
MOV DX,0FFE0H
X: MOV AL,00H
L1:OUT DX,AL
INC AL
CMP AL,0FFH
JNE L1
L2:OUT DX,AL
DEC AL
CMP AL,00H
JNE L2
JMP X
INT 03H
CODE ENDS
END START

OUTPUT:

Department of Electronics and Communication Engineering 52


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM 6 (D): INTERFACING DAC TO 8086 FOR GENERATING SINE


WAVE

OBJECTIVE: To write an assembly language program to interface Digital to Analog


converter to 8086 kit for generating sine wave.

TOOLS REQUIRED: 8086 trainer kit with power adapter, DAC interfacing board,
CRO, PC With installed Windows 7, DOSBOX and MASM.

FLOW CHART:

Department of Electronics and Communication Engineering 53


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:
ASSUME CS:CODE
CODE SEGMENT
ORG 3000H
N DB 75H, 95H, 0AAH, 0BFH, 0D1H, 0E0H, 0EDH, 0F6H, 0FCH, 0FEH, 0FCH,
0F6H, 0EDH, 0E0H, 0D1H, 0BFH, 0AAH, 95H, 75H, 69H, 54H, 40H, 2DH, 1EH, 11H,
08H, 02H, 00H, 02H, 08H, 11H, 1EH, 2DH, 40H, 54H, 69H
ORG 2000H
START: MOV DX,0FFE6H
MOV AL,80H
OUT DX,AL
MOV DX,0FFE0H
BACK: MOV CX,24H
MOV SI, 3000H
L1: MOV AL,[SI]
OUT DX,AL
INC SI
DEC CX
JNZ L1
JMP BACK
INT 03H
CODE ENDS
END START

OUTPUT:

RESULT:

Department of Electronics and Communication Engineering 54


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

VIVA QUESTIONS:

1. Why data bus is bi-directional?

2. Why address bus is unidirectional?

3. What is the size of instruction queue in 8086?

4. What is meant by LATCH?

5. Explain the difference between a JMP and CALL instruction?

Department of Electronics and Communication Engineering 55


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

EXPERIMENT 7
PARALLEL COMMUNICATION BETWEEN TWO MICROPROCESSORS
USING 8255
.
PROGRAM 7 (A): PARALLEL COMMUNICATION BETWEEN TWO MICROPROCESSORS
USING 8255.

OBJECTIVE: To write an assembly language program to generate sine wave by using


8255 interfacing with 8086 microprocessor.

TOOLS REQUIRED: 8086 trainer kit with power adapter, Dual DAC kit, CRO, PC
With installed Windows 7, DOSBOX and MASM.

THEORY: The parallel input-output port chip 8255 is also called as Programmable
peripheral input-output Port. The Intel’s 8255 are designed for use with Intel’s 8 -bit, 16-
bit and higher capability microprocessors. It has 24 input/output lines which may be
individually programmed in 2-groups of 12 lines each, or 3 groups of 8 lines .The two
groups of I/O pins are named as GROUP A and GROUP B. Each of these two groups
contain a sub group of 8 I/O lines called as 8-bit Port and other sub group of 4 I/O lines
are a 4-bit port. Thus GROUP A Contains an 8-bit port A along with a 4-bit port, C
upper. Port lines are identified by symbols PAO-PA7, While the port C lines are
identified as PC4-PC7 .Similarly group B contains an 8-bit port B, containing lines PB0-
PB7 and a 4-bit port C with lower bits PC0-PC3 .The port C upper and port C lower can
be used in recombination as an 8-bit port-C .Both the port Cs are assigned the same
address. Thus one may have either Three 8-bit I/O ports are two 8-bit and two 4-bit I/O
ports from 8255.All of these ports can function independently either as input or as output
ports. This can be achieved by programming the bits of an internal register of 8255
called as Control word register. (CWR).

FLOW CHART:

Department of Electronics and Communication Engineering 56


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PORT ADDRESSES OF 8255(low) on ESA 86/88-2 kit


Control word register = FFE6
Port A = FFE0
Port B = FFE2
Port C = FFE4

PROGRAM:

Transmitter side:
ASSUME CS:CODE
CODE SEGMENT
ORG 2000H
START: MOV DX,0FFE6H
MOV AL,80H
OUT DX,AL
MOV AL,73H
MOV DX, 0FFE0H
OUT DX,AL
INT 03H
CODE ENDS
END START

Receiver side:
ASSUME CS:CODE
CODE SEGMENT
ORG 2000H
START: MOV DX,0FFE7H
MOV AL,9BH
OUT DX,AL
MOV DX, 0FFE1H
IN AL, DX
MOV BL,AL
INT 03H
CODE ENDS
END START

Department of Electronics and Communication Engineering 57


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

OUTPUT:

RESULT:

VIVA QUESTIONS:
1. What is a stack?

2. What is meant by cross-compiler?

3. Which is the highest priority interrupt?

4. ̅̅̅̅̅̅̅ ?
What is the function of 𝐼𝑁𝑇𝐴

5. What is CWR of 8255?

Department of Electronics and Communication Engineering 58


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

EXPERIMENT 8
SERIAL COMMUNICATION BETWEEN TWO MICROPROCESSOR KITS
USING 8251.
.
PROGRAM 8 (A): SERIAL COMMUNICATION BETWEEN TWO MICROPROCESSORS
USING 8251 USART

OBJECTIVE: To write an assembly language program for serial communication


between two microprocessors.

TOOLS REQUIRED: 8086 trainer kit with power adapter, PC With installed
Windows 7, DOSBOX and MASM.

THEORY:

The 8251 is a USART (Universal Synchronous Asynchronous Receiver Transmitter) for


serial data communication. As a peripheral device of a microcomputer system, the 8251
receives parallel data from the CPU and transmits serial data after conversion. This
device also receives serial data from the outside and transmits parallel data to the CPU
after conversion

RXD (input terminal): This is a terminal which receives serial data.


RXRDY (Output terminal): This is a terminal which indicates that the 8251 contains a
character that is ready to READ. If the CPU reads a data character, RXRDY will be reset
by the leading edge of RD signal. Unless the CPU reads a data character before the next
one is received completely, the preceding data will be lost. In such a case, an overrun
error flag status word will be set.

RXC (Input terminal): This is a clock input signal which determines the transfer speed
of received data. In "synchronous mode," the baud rate is the same as the frequency of
RXC. In "asynchronous mode," it is possible to select the baud rate factor by mode
instruction. It can be 1, 1/16, 1/64 the RXC.

SYNDET/BD (Input or output terminal): This is a terminal whose function changes


according to mode. In "internal synchronous mode." this terminal is at high level, if sync
characters are received and synchronized. If a status word is read, the terminal will be
reset. In "external synchronous mode, "this is an input terminal. A "High" on this input
forces the 8251 to start receiving data characters. In "asynchronous mode," this is an
output terminal which generates "high level“ output upon the detection of a "break"
character if receiver data contains a "low-level" space between the Microprocessor &
Microcontroller Lab Dept. of ECE stop bits of two continuous characters. The terminal
will be reset, if RXD is at high level. After Reset is active, the terminal will be output at
low level.

Department of Electronics and Communication Engineering 59


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

DSR (Input terminal): This is an input port for MODEM interface. The input status of
the terminal can be recognized by the CPU reading status words.

DTR (Output terminal): This is an output port for MODEM interface. It is possible to
set the status of DTR by a command.

CTS (Input terminal): This is an input terminal for MODEM interface which is used
for controlling a transmit circuit. The terminal controls data transmission if the device is
set in "TX Enable" status by a command. Data is transmittable if the terminal is at low
level.

RTS (Output terminal): This is an output port for MODEM interface. It is possible to
set the status RTS by a command.

FLOW CHART:

Department of Electronics and Communication Engineering 60


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:
ASSUME CS:CODE
CODE SEGMENT
ORG 2000H
START: MOV AL,36
MOV DX,0086H
OUT DX,AL
MOV DX,0080H
MOV AL,0A
OUT DX,AL
MOV AL,00
OUT DX,AL
MOV SP,3000
MOV DX,0092
OUT DX,AL
OUT DX,AL
OUT DX,AL
OUT DX,AL
CALL 205F
MOV AL,40
OUT DX,AL
CALL 205F
MOV AL,CE
OUT DX,AL
CALL 205F
MOV AL,27
OUT DX,AL
CALL 205F
MOV SI,2100
MOV DX,0092
IN AL,DX
CMP AL,1B
JE 2031
MOV DX,0090
IN AL,DX
AND AL,81
CMP BL,AL
JE 205E
MOV DX,0092
IN AL,DX
AND AL,81
CMP AL,81
JNE 2043
MOV AL,BL
MOV DX,0090
OUT DX,AL
OUT DX,AL
MOV [SI],AL
INC SI

Department of Electronics and Communication Engineering 61


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

JMP 2031
OUT DX,AL
INC SI
JMP 2043
INT 03
MOV CX,0002
LOOP 2062
RET
INT 03H
CODE ENDS
END START

OUTPUT:

RESULT:

VIVA QUESTIONS:

1. What is the drawback in memory mapped I/0?

2. Why interfacing is needed for I/O devices?

3. Define T-State (In Processor Timing Diagram) ?

4. What is USART?

5. What is baud rate?

Department of Electronics and Communication Engineering 62


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

EXPERIMENT 9
INTERFACING TO 8086 AND PROGRAMMING TO CONTROL STEPPER MOTOR
.
PROGRAM 9 (A): INTERFACING TO 8086 AND PROGRAMMING TO CONTROL STEPPER
MOTOR FOR TWO ROTATIONS IN CLOCKWISE DIRECTION WITH 10 rpm SPEED.

OBJECTIVE: To Interfacing to stepper motor with 8086 and to write an assembly


language program to control stepper motor for two rotations in clockwise direction with
10 rpm speed..

TOOLS REQUIRED: 8086 trainer kit with power adapter, Stepper motor interface kit,
PC With installed Windows 7, DOSBOX and MASM.

FLOW CHART:

Department of Electronics and Communication Engineering 63


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:
ASSUME CS:CODE
CODE SEGMENT
ORG 2000H
START:
MOV DX,0FFE6H
MOV AL,80H
OUT DX,AL
MOV DX,0FFE0H
MOV AL,88H
MOV BX,400D
L1:
OUT DX,AL
CALL DELAY
ROR AL,01
DEC BX
JNZ L1
DELAY PROC NEAR
MOV CX,8008D
L2:
NOP
NOP
LOOP L2
RET
DELAY ENDP
INT 03H
CODE ENDS
END START

OUTPUT:

Department of Electronics and Communication Engineering 64


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM 9 (B): INTERFACING TO 8086 AND PROGRAMMING TO CONTROL STEPPER


MOTOR FOR INFINITE ROTATIONS IN ANTI-CLOCKWISE DIRECTION WITH ANY SPEED.

OBJECTIVE: To Interfacing to stepper motor with 8086 and to write an assembly


language program to control stepper motor for infinite rotations in anti-clockwise
direction with any speed.

TOOLS REQUIRED: 8086 trainer kit with power adapter, Stepper motor interface kit,
PC With installed Windows 7, DOSBOX and MASM.

FLOW CHART:

Department of Electronics and Communication Engineering 65


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:
ASSUME CS:CODE
CODE SEGMENT
ORG 2000H
START:
MOV DX,0FFE6H
MOV AL,80H
OUT DX,AL
MOV DX,0FFE0H
MOV AL,88H
L1:
OUT DX,AL
CALL DELAY
ROL AL,01
JMP L1
DELAY PROC NEAR
MOV CX, 8008D
L2:
NOP
NOP
LOOP L2
RET
DELAY ENDP
INT 03H
CODE ENDS
END START

OUTPUT:

Department of Electronics and Communication Engineering 66


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM 9 (C): INTERFACING TO 8086 AND PROGRAMMING TO CONTROL STEPPER


MOTOR FOR ROTATIONS IN CLOCKWISE1800 FOLLOWED BY ANTI-CLOCKWISE 900 WITH 30
rpm SPEED.

OBJECTIVE: To Interfacing to stepper motor with 8086 and to write an assembly


language program to control stepper motor for rotations in clockwise1800 followed by
anti-clockwise 900 with 30 rpm speed.

TOOLS REQUIRED: 8086 trainer kit with power adapter, Stepper motor interface kit,
PC With installed Windows 7, DOSBOX and MASM.

FLOW CHART:

Department of Electronics and Communication Engineering 67


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:
ASSUME CS:CODE
CODE SEGMENT
ORG 2000H
START:
MOV DX,0FFE6H
MOV AL,80H
OUT DX,AL
MOV DX,0FFE0H
MOV AL,88H
MOV BL, 100D
L1: OUT DX,AL
CALL DELAY
ROR AL,01
DEC BL
JNZ L1
NOP
NOP
MOV BH, 50D
L2: OUT DX,AL
CALL DELAY
ROL AL,01
DEC BH
JNZ L2
DELAY PROC NEAR
MOV CX,8669D
L3: NOP
NOP
LOOP L3
RET
INT 03H
CODE ENDS
END START

OUTPUT:

RESULT:

Department of Electronics and Communication Engineering 68


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

VIVA QUESTIONS:
1. Explain the principle of stepper motor.

2. How to calculate step angle?

3. What is the necessity of driver IC?

4. How to protect windings from back EMF?

5. Explain advantages of stepper motor over ordinary motor?

Department of Electronics and Communication Engineering 69


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

Assembly Language Programming in Keil µVision

Creating an Assembly project in Keil


1) Open the Keil IDE by clicking on its icon on the desktop.
2) Choose New uVision Project from the Project menu.

3) Create a new folder and Name it OurFirstProject. Type the name ourFirstProject for
the project and click Save.

4) In the Data base tree, choose the vendor and then the chip you want to use and then click
OK. For example, if you want to use the LPC2368, click on the NXP and then on the
LPC2368 and then press OK.

Department of Electronics and Communication Engineering 70


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

5) Click the YES button to add the startup file to the project.

6) Make a new file by clicking on the New Icon (you can make a new file by pressing
Ctrl+N or choosing New from the File menu, as well.)

7) Press Ctrl+S to save the new file. (You can also save the file by choosing Save from the
File menu.)

8) Name the file as program.asm and save it in the OurFirstProject directory.

9) Type the following sample program in the file

Department of Electronics and Communication Engineering 71


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

10) Add the program.asm file to the project. To do so:


a. Right click on Source Group 1 and choose Add Files to Group.

b. Then go to the OurFirstProject directory and choose Program.asm, press Add and
then Close.

Building

11) To compile click on the Build icon or choose build target from the Project menu.

12) If the program is built successfully the following message appears:

Debugging and Tracing

Department of Electronics and Communication Engineering 72


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

13) To start debugging click on Start/Stop Debug Session icon or choose Start/Stop Debug
Session from the Debug menu. (or simply press Ctrl+F5)

14) If it starts tracing successfully, a cursor appears in front of the next instruction to be
executed.

15) Go to the Peripherals menu. It has tools for monitoring different peripherals. We can
see values of registers while tracing the program or change their values by clicking on
each bit.

Department of Electronics and Communication Engineering 73


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

16) To trace the program use the Step Over button or click on Step Over from the Debug
menu. It executes the instructions of the program one after another. To trace the program
you can use the Step button, as well. The difference between the Step Over and Step is in
executing functions. While Step goes into the function and executes its instructions one
by one, Step Over executes the function completely and goes to the instruction next to
the function. To see the difference between them, trace the program once with Step Over
and then with Step. When you are in the function and you want the function to be
executed completely you can use Step Out. In the case, the instructions of the function
will be executed, it returns from the function, and goes to the instruction which is next to
the function call.

17) To exit from the debugging mode press Start/Stop Debug Session.

Department of Electronics and Communication Engineering 74


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

EXPERIMENT 10
PROGRAMMING USING ARITHMETIC, LOGICAL AND BIT MANIPULATION
INSTRUCTIONS OF 8051.
PROGRAM 10 (A): PROGRAMS FOR ARITHMETIC OPERATIONS

OBJECTIVE: To write an assembly language programs to perform arithmetic


operations for 8051.

TOOLS REQUIRED: PC with installed Keil µVision IDE - MDK plus.

FLOW CHART:

Department of Electronics and Communication Engineering 75


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:

MOV R0,#50
MOV A,#23H
MOV B,#12H
ADD A,B

MOV @R0,A
MOV A,#25H
MOV B,#16H
SUBB A,B
INC R0
MOV @R0,A

MOV A,#06H
MOV B,#05H
MUL AB
INC R0
MOV @R0,A

MOV A,#06
MOV B,#05
DIV AB
INC R0
MOV @R0,A

INC R0
MOV @R0,B
LCALL 0003
END

OUTPUT:

Department of Electronics and Communication Engineering 76


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM 10 (B): PROGRAMS FOR LOGICAL AND BIT MANIPULATION OPERATIONS

OBJECTIVE: To write an assembly language programs to perform logical and bit


manipulation operations for 8051.

TOOLS REQUIRED: PC with installed Keil µVision IDE - MDK plus.

FLOW CHART:

Department of Electronics and Communication Engineering 77


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:
1. AND LOGIC OPERATION
MOV A,#32H
MOV B,#23H
ANL A,B
X: SJMP X
END

2. OR LOGIC OPERATION
MOV A,#32H
MOV B,#23H
ORL A,B
X: SJMP X
END

3. EXCULSIVE OR LOGIC OPERATION


MOV A,#32H
MOV B,#23H
XRL A,B
X: SJMP X
END

4. COMPLIMENT OPERATION
MOV A,#32H
CPL A
X: SJMP X
END

5. SWAPING OPERATION
MOV A,#32H
SWAP A
X: SJMP X
END

6. REGISTER/PORT CLERING OPERATION


MOV A,#32H
CLR A
X: SJMP X
END

7. DATA EXCHANGE OPERATION


MOV A,#32H
MOV B,#23H
XCH A,B
X: SJMP X
END

8. BIT SET/RESET OPERATION


MOV P1, 0F0H
SETB P1.2
CLR P1.7
X: SJMP X
END

Department of Electronics and Communication Engineering 78


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

OUTPUT:

RESULT:

VIVA QUESTIONS:
1. What amount of external memory supported to 8051 microcontroller?

2. Explain CLR?

Department of Electronics and Communication Engineering 79


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

3. What does SWAP do?

4. What is the Significance of SJMP in the above Programs?

5. Difference between # and @ in 8051 addressing?

Department of Electronics and Communication Engineering 80


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

EXPERIMENT 11
PROGRAM AND VERIFY TIMER/COUNTER IN 8051
PROGRAM 11 (A): PROGRAM AND VERIFY TIMER/COUNTER IN 8051

OBJECTIVE: To write an assembly language programs to Verify Timer/Counter In


8051.

TOOLS REQUIRED: PC with installed Keil µVision IDE - MDK plus.

FLOW CHART:

Department of Electronics and Communication Engineering 81


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:

ORG 0000H
RPT:
MOV TMOD,#15H
SETB P3.4
MOV TL0,#00H
MOV TH0,#00H
SETB TR0
MOV R0,#70
AGAIN:
MOV TL1,#00
MOV TH1,#00
SETB TR1
BACK:
JNB TF1,BACK
CLR TF1
CLR TR1
DJNZ R0,AGAIN
CPL P3.0
MOV A,TL0
MOV P2,A
SJMP RPT
END

OUTPUT:

Department of Electronics and Communication Engineering 82


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

RESULT:

VIVA QUESTIONS:
1. What is DJNZ?

2. How Many Timers does 8051 have?

3. How can timers used as counters?

4. What is TR0/TR1?

5. What is TF0/TF1?

Department of Electronics and Communication Engineering 83


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

Department of Electronics and Communication Engineering 84


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

EXPERIMENT 12
PROGRAM AND VERIFY INTERRUPT HANDLING IN 8051
PROGRAM 12 (A): PROGRAM AND VERIFY TIMER/COUNTER IN 8051(EXAMPLE-1)

OBJECTIVE: To write an assembly language programs to Verify Interrupt Handling In


8051.

TOOLS REQUIRED: PC with installed Keil µVision IDE - MDK plus.

FLOW CHART:

Department of Electronics and Communication Engineering 85


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:

ORG 0000H
LJMP MAIN

ORG 000BH
CPL P1.2
RETI

ORG 0030H
MAIN:
MOV TMOD,#02H
MOV TH0,#0B6H
MOV IE,#82H
SETB TR0
BACK:
MOV P0, #'A'
MOV P2, #'B'
SJMP BACK
END

OUTPUT:

Department of Electronics and Communication Engineering 86


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM 12 (B): PROGRAM AND VERIFY TIMER/COUNTER IN 8051 (EXAMPLE-2)

OBJECTIVE: To write an assembly language programs to Verify Interrupt Handling In


8051.

TOOLS REQUIRED: PC with installed Keil µVision IDE - MDK plus.

FLOW CHART:

Department of Electronics and Communication Engineering 87


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:

ORG 0000H
LJMP MAIN
ORG 0003H
LED1:
MOV P0,#00H
MOV R0,#0255
DJNZ R0,LED1
RETI
ORG 0013H
LED2:
MOV P2,#00H
MOV R0,#0255
DJNZ R0,LED2
RETI
ORG 0030H
MAIN:
MOV IE,#85H
HERE:SJMP HERE
END

OUTPUT:

RESULT:

VIVA QUESTIONS:

1. What is 8253 ?

2. Define the modes of 8253?

Department of Electronics and Communication Engineering 88


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

3. Explain the necessity of each counter.

4. What is the purpose of Timer/counter.

5. Which timer is used to set the baud rate for serial communication in 8051?

Department of Electronics and Communication Engineering 89


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

Department of Electronics and Communication Engineering 90


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

EXPERIMENT 13
UART OPERATION IN 8051
PROGRAM 13 (A): SERIAL COMMUNICATION - UART OPERATION IN 8051

OBJECTIVE: To write an assembly language program UART Operation in 8051.

TOOLS REQUIRED: PC with installed Keil µVision IDE - MDK plus.

FLOW CHART:

Department of Electronics and Communication Engineering 91


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:
MOV TMOD, #20H
MOV TH1, #-3
MOV SCON, #50H
SETB TR1
AGAIN:
MOV SBUF, #'M'
HERE:
JNB TI,HERE
CLR TI
MOV SBUF, #'P'
HERE1:
JNB TI,HERE1
CLR TI
MOV SBUF, #'M'
HERE2:
JNB TI,HERE2
CLR TI
MOV SBUF, #'C'
HERE3:
JNB TI,HERE3
CLR TI
X:SJMP X
END

OUTPUT:

RESULT:

VIVA QUESTIONS:
1. ________________ helps the programmer in selecting the sources of interrupts.
2. The 8051 micro controller having __________ number of Interrupt pins.
3. If IP register has only the default priorities then Timer overflow have the
____________ priority
4. In 8051 instruction set OV flag affects for _____________ operations.
5. Difference between BSR and IO modes?

Department of Electronics and Communication Engineering 92


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

EXPERIMENT 14
COMMUNICATION BETWEEN 8051 KIT AND PC
PROGRAM 14 (A): COMMUNICATION BETWEEN 8051 KIT AND PC

OBJECTIVE: To write an assembly language program to establish communication


between 8051 kit and PC.

TOOLS REQUIRED: 8051 Trainer kit and PC with installed Keil µVision IDE - MDK
plus.

FLOW CHART:

Department of Electronics and Communication Engineering 93


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:

MOV A,#36
MOV DPTR,#2043
MOVX @DPTR,A
MOV DPTR,#2040
MOV A,#0A
MOVX @DPTR,A
MOV A,#00
MOVX @DPTR,A
MOV R1,#3000
MOV DPTR,#0092
MOVX @DPTR,A
MOVX @DPTR,A
MOVX @DPTR,A
MOVX @DPTR,A
CALL DELAY
MOV A,#40
MOVX @DPTR,A
CALL DELAY
MOV A,#CE
MOVX @DPTR,A
CALL DELAY
MOV A,#27
MOVX @DPTR,A
CALL DELAY
MOV DPTR,9000
MOV DPTR,#0092
UP:MOVX @DPTR,A
CMP A,1B
JE UP
MOV DPTR,#0090
MOVX @DPTR,A
ANL A,81
CJNE B,A.DOWN
MOV DPTR,#0092
UP1:MOVX @DPTR,A
ANL A,81
CJNE AL,81.UP1
MOV A,B
MOV DPTR,#0090
MOVX @DPTR,A
MOVX @DPTR,A
MOV R3,9700
MOV R3,A
INC R3
JMP UP
MOVX @DPTR,A
INC R3

Department of Electronics and Communication Engineering 94


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

JMP UP
INT 03
DOWN:MOV CX,0002
DELAY:
HERE:LOOP HERE
RET

EXAMPLE:2
MOV TMOD, #20H ;set timer1 in 16 bit timer mode
MOV TH1, #0FDH ;initialize serial communication
MOV TH1, #0FDH
MOV SCON, #40H ;load timer 1 to generate baud rate of 96KBps
SETB TR1 ;start timer 1
AGAIN:
SETB REN ;enable reception
X1: CLP RI
CJNZ X1 ;wait until data is received
CLR RI ;clear receive flag
MOV A, SBUF ;get data in to acc
CLR REN ;now disable reception
MOV SBUF, A ;start transmission
X2: CLP TI
CJNZ X2 ;wait until data transmitted
CLR TI ;clear transmission flag
SJMP AGAIN
END

OUTPUT:

RESULT:

Department of Electronics and Communication Engineering 95


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

VIVA QUESTIONS:

1. Explain branching instructions?

2. List bit manipulation instructions.

3. Explain DJNZ and CJNE instructions?

4. What is importance of PSEN’ and EA’

5. Which signal is used for demultiplexing address and data lines?

Department of Electronics and Communication Engineering 96


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

EXPERIMENT 15
INTERFACING LCD TO 8051
PROGRAM 15 (A): INTERFACING LCD TO 8051

OBJECTIVE: To write an assembly language program to interfacing LCD to 8051.

TOOLS REQUIRED: 8051 Trainer kit, LCD Module and PC with installed Keil
µVision IDE - MDK plus.

FLOW CHART:

Department of Electronics and Communication Engineering 97


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:
CNTRL EQU 2043H ; 8255 control port address
PORTC EQU 2042H ; 8255 port C address
PORTB EQU 2041H ; 8255 port B address
PORTA EQU 2040H ; 8255 port A address
FUNCTION_SET EQU 38H ; display commands
DIS_ON_OFF EQU 0EH
RETURN_HOME EQU 02H
MODE_SET EQU 06H
CLEAR_DIS EQU 01H
DDRAM_ADD EQU 80H
CNT EQU 40H
CNT1 EQU 41H
CNT2 EQU 42H
MOV SP,#50H
MOV PSW,#00H
MOV CNT2,#10H
MOV R0,#14H
MOV R1,#FFH
LCALL DELAY
MOV DPTR,#CNTRL
MOV A,#80H
MOVX @DPTR,A
LCALL SET_CON_LINES
BACK: MOV R2,#03H
LCALL SET_WR_CON_LINES
MOV A,#00H
MOVX @DPTR,A
MOV DPTR,#PORTA
MOV A,#FUNCTION_SET
MOVX @DPTR,AMOV
DPTR,#CNTRL
MOV A,#05H
MOVX @DPTR,A
NOP
NOP
MOV A,#04H
MOVX @DPTR,A
MOV R0,#06H
MOV R1,#E4H
LCALL DELAY
DJNZ R2,BACK
LCALL CHK_BUSY

LCALL SET_WR_CON_LINES
MOV A,#00H
MOVX @DPTR,A
MOV DPTR,#PORTA
MOV A,#DIS_ON_OFF

Department of Electronics and Communication Engineering 98


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

MOVX @DPTR,A
MOV DPTR,#CNTRL
MOV A,#05H
MOVX @DPTR,A
NOP
NOP
MOV A,#04H
MOVX @DPTR,A
LCALL CHK_BUSY
LCALL SET_WR_CON_LINES
MOV A,#00H
MOV DPTR,#PORTA
MOV A,#RETURN_HOME
MOVX @DPTR,A
MOV DPTR,#CNTRL
MOV A,#05H
MOVX @DPTR,A
NOP
NOP
MOV A,#04H
MOVX @DPTR,A
LCALL CHK_BUSY
LCALL SET_WR_CON_LINES
MOV A,#00H
MOVX @DPTR,A
MOV DPTR,#PORTA
MOV A,#MODE_SET
MOVX @DPTR,A
MOV DPTR,#CNTRL
MOV A,#05H
MOVX @DPTR,A
NOP
NOP
MOV A,#04H
MOVX @DPTR,A
LCALL CHK_BUSY
LCALL SET_WR_CON_LINES
MOV A,#00H
MOVX @DPTR,A
MOV DPTR,#PORTA
MOV A,#CLEAR_DIS
MOVX @DPTR,A
MOV DPTR,#CNTRL
MOV A,#05H
MOVX @DPTR,A
NOP
NOP
MOV A,#04H
MOVX @DPTR,A

Department of Electronics and Communication Engineering 99


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

MOV CNT1,#02H
MOV CNT,#08H
MOV R0,#DDRAM_ADD
LCALL CHK_BUSY
LCALL SET_WR_CON_LINES
MOV A,#00H
MOV DPTR,#PORTA
MOV A,R0
MOVX @DPTR,A
MOV DPTR,#CNTRL
MOV A,#05H
MOVX @DPTR,A
NOP
NOP
MOV A,#04H
MOVX @DPTR,A
CLR A
MOV DPTR,#MSG
MOVX A,@DPTR
BACK3: MOV R1,A
INC DPTR
PUSH DPH
PUSH DPL
LCALL CHK_BUSY
LCALL SET_WR_CON_LINES
MOV A,#01H
MOVX @DPTR,A
MOV DPTR,#PORTA
MOV A,R1
MOVX @DPTR,A
MOV DPTR,#CNTRL
MOV A,#05H
MOVX @DPTR,A
NOP
NOP
MOV A,#04H
MOVX @DPTR,A
POP DPL
POP DPH
CLR A
PUSH R0
PUSH R1
MOV R0,#7FH
MOV R1,#FFH
LCALL DELAY
POP R1
POP R0
DJNZ CNT,BACK3
DJNZ CNT1,F1

Department of Electronics and Communication Engineering 100


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

DJNZ CNT2,FORW1
LJMP FORW
MOV CNT,#08H
F1: PUSH DPH
PUSH DPL
LCALL CHK_BUSY
LCALL SET_WR_CON_LINES
MOV A,#00H
MOVX @DPTR,A
MOV DPTR,#PORTA
MOV A,#C0H
MOVX @DPTR,A
MOV DPTR,#CNTRL
MOV A,#05H
MOVX @DPTR,A
NOP
NOP
MOV A,#04H
MOVX @DPTR,A
POP DPL
POP DPH
CLR A
LJMP BACK3
PUSH DPH
FORW1: PUSH DPL
MOV R0,#DDRAM_ADD
LCALL CHK_BUSY
LCALL SET_WR_CON_LINES
MOV A,#00H
MOVX @DPTR,A
MOV DPTR,#PORTA
MOV A,R0
MOVX @DPTR,A
MOV DPTR,#CNTRL
MOV A,#05H
MOVX @DPTR,A
NOP
NOP
MOV A,#04H
MOVX @DPTR,A
MOV CNT,#08H
MOV CNT1,#02H
POP DPL
POP DPH
CLR A
LJMP BACK3
FORW : LCALL 0003H
SET_CON_LINES: MOV DPTR,#CNTRL
MOV A,#01H

Department of Electronics and Communication Engineering 101


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

MOVX @DPTR,A
MOV A,#03H
MOVX @DPTR,A
MOV A,#04H
MOVX @DPTR,A
RET
CHK_BUSY: MOV DPTR,#CNTRL
MOV A,#90H
MOVX @DPTR,A
MOV A,#04H
MOVX @DPTR,A
MOV A,#00H
MOVX @DPTR,A
MOV A,#03H
MOVX @DPTR,A
BACK2: MOV A,#05H
MOVX @DPTR,A
MOV DPTR,#PORTA
MOVX A,@DPTR
MOV B,A
MOV DPTR,#CNTRL
MOV A,#04H
MOVX @DPTR,A
MOV A,B
JNB A.7,F2
LJMP BACK2
F2: MOV DPTR,#CNTRL
MOV A,#80H
MOVX @DPTR,A
RET
SET_WR_CON_LINES: MOV DPTR,#CNTRL
MOV A,#04H
MOVX @DPTR,A
MOV A,#02H
MOVX @DPTR,A
DELAY: RET
LOOP1: PUSH R1
LOOP: NOP
DJNZ R1,LOOP
POP R1
DJNZ R0,LOOP1
RET

Department of Electronics and Communication Engineering 102


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

OUTPUT:

RESULT:

VIVA QUESTIONS:

1. Explain principal of stack in 8051?

2. What are SFR’s?

Department of Electronics and Communication Engineering 103


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

3. Mention capacity of internal and external RAM?

4. How many address lines are required to interface 64Kb of memory?

5. Explain the importance of ports?

Department of Electronics and Communication Engineering 104


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

EXPERIMENT 16
INTERFACING MATRIX/KEYBOARD TO 8051
PROGRAM 16 (A): INTERFACING MATRIX/KEYBOARD TO 8051

OBJECTIVE: To write an assembly language program to interfacing matrix/keyboard


to 8051.

TOOLS REQUIRED: 8051 Trainer kit, Keyboard Module and PC with installed Keil
µVision IDE - MDK plus.

THEORY: The key board here we are interfacing is a matrix keyboard. This key board
is designed with a particular rows and columns. These rows and columns are connected
to the microcontroller through its ports of the micro controller 8051. We normally use
8*8 matrix key board. So only two ports of 8051 can be easily connected to the rows and
columns of the key board.
Whenever a key is pressed, a row and a column gets shorted through that pressed
key and all the other keys are left open. When a key is pressed only a bit in the port goes
high. This indicates microcontroller that the key is pressed. By this high on the bit key
in the corresponding column is identified.
Once we are sure that one of key in the key board is pressed next our aim is to
identify that key. To do this we firstly check for particular row and then we check the
corresponding column the key board.
To check the row of the pressed key in the keyboard, one of the row is made high
by making one of bit in the output port of 8051 high. This is done until the row is found
out. Once we get the row next out job is to find out the column of the pressed key. The
column is detected by contents in the input ports with the help of a counter. The content
of the input port is rotated with carry until the carry bit is set.
The contents of the counter is then compared and displayed in the display. This
display is designed using a seven segment display and a BCD to seven segment decoder
IC 7447.
The BCD equivalent number of counter is sent through output part of 8051
displays the number of pressed key.

Circuit diagram of INTERFACING KEY BOARD TO 8051.

Department of Electronics and Communication Engineering 105


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

Keyboard is organized in a matrix of rows and columns as shown in the figure. The
microcontroller accesses both rows and columns through the port.
1. The 8051 has 4 I/O ports P0 to P3 each with 8 I/O pins, P0.0 to P0.7, P1.0 to P1.7, P2.0
to P2.7, P3.0 to P3.7. The one of the port P1 (it understood that P1 means P1.0 to P1.7)
as an I/P port for microcontroller 8051, port P0 as an O/P port of microcontroller 8051
and port P2 is used for displaying the number of pressed key.
2. Make all rows of port P0 high so that it gives high signal when key is pressed.
3. See if any key is pressed by scanning the port P1 by checking all columns for non zero
condition.
4. If any key is pressed, to identify which key is pressed make one row high at a time.
5. Initiate a counter to hold the count so that each key is counted.
6. Check port P1 for nonzero condition. If any nonzero number is there in [accumulator],
start column scanning by following step 9.
7. Otherwise make next row high in port P1.
8. Add a count of 08h to the counter to move to the next row by repeating steps from step
6.
9. If any key pressed is found, the [accumulator] content is rotated right through the carry
until carry bit sets, while doing this increment the count in the counter till carry is found.
10. Move the content in the counter to display in data field or to memory location
11. To repeat the procedures go to step 2.

FLOW CHART:

Department of Electronics and Communication Engineering 106


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:

to check that whether any key is pressed


START: MOV A,#00H
MOV P1,A ;MAKING ALL ROWS OF PORT P1 ZERO
MOV A,#0FH
MOV P1,A ;MAKING ALL ROWS OF PORT P1 HIGH
PRESS: MOV A,P2
JZ PRESS ;CHECK UNTIL ANY KEY IS PRESSED

after making sure that any key is pressed

MOV A,#01H ;MAKE ONE ROW HIGH AT A TIME


MOV R4,A
MOV R3,#00H ;INITIATING COUNTER
NEXT: MOV A,R4
MOV P1,A ;MAKING ONE ROW HIGH AT A TIME
MOV A,P2 ;TAKING INPUT FROM PORT A
JNZ COLSCAN ;AFTER GETTING THE ROW JUMP TO
CHECK
COLUMN
MOV A,R4
RL A ;ROTATE LEFT TO CHECK NEXT ROW
MOV R4,A
MOV A,R3
ADD A,#08H ;INCREMENT COUNTER BY 08 COUNT
MOV R3,A
SJMP NEXT ;JUMP TO CHECK NEXT ROW

after identifying the row to check the colomn following steps are followed

COLSCAN: MOV R5,#00H


IN: RRC A ;ROTATE RIGHT WITH CARRY UNTIL
GET THE CARRY
JC OUT ;JUMP ON GETTING CARRY
INC R3 ;INCREMENT ONE COUNT
JMP IN
OUT: MOV A,R3
DA A ;DECIMAL ADJUST THE CONTENTS OF
COUNTER
BEFORE DISPLAY
MOV P2,A
JMP START ;REPEAT FOR CHECK NEXT KEY

Department of Electronics and Communication Engineering 107


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

OUTPUT:

RESULT:

VIVA QUESTIONS:

1. What is a Matrix Keyboard?

2. Define IVT.

3. List out handshaking signals of 8255?

4. What is MODEM?

5. What is the importance of 11.0592 MHz frequency?

Department of Electronics and Communication Engineering 108


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

EXPERIMENT 17
DATA TRANSFER FROM PERIPHERAL TO MEMORY THROUGH DMA
CONTROLLER 8237/8257
PROGRAM 17 (A): DATA TRANSFER FROM PERIPHERAL TO MEMORY THROUGH DMA
CONTROLLER 8237/8257

OBJECTIVE: To write an assembly language program to data transfer from peripheral


to memory through DMA controller 8257.

TOOLS REQUIRED: 8086 trainer kit with power adapter, DMA Controller 8257, PC
With installed Windows 7, DOSBOX and MASM.

THEORY: Interface DMA with 8086 so that the channel 0 DMA addresses reg.,TC reg.
and MSR has an I/O address 80 H, 81 H and 88 H . Initialize the 8257 with normal
priority, TC stop and non-extended write. Auto load is not required. Write an ALP to
move 2KB of data from peripheral device to memory address 2000 H: 5000 H, with the
above initialization. The transfer has to take place using channel 0.

MSR = 41 H
DMA address register = 5000 H
TC = 47FF H

FLOW CHART:

Department of Electronics and Communication Engineering 109


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:

ASSSUME CS:CODE
ADDREG EQU 80 H
TC EQU 81 H
MSR EQU 88 H
CODE SEGMENT
START: MOV AX, 2000 H
MOV DS,AX
MOV AX,5000 H ; DMA ADDRESS REGISTER
OUT ADDREG, AL ; DMA ADDRESS REGISTER
OUT ADDREG, AH ; DMA ADDRESS REGISTER
MOV AX,47FF H ; TERMINAL COUNT REGISTER
OUT TC, AL ; TERMINAL COUNT REGISTER
OUT TC, AH ; TERMINAL COUNT REGISTER
MOV AL,41 H ; MODE SET REGISTER
OUT MSR, AL ; MODE SET REGISTER
HLT
CODE ENDS
END START

OUTPUT:

RESULT:

Department of Electronics and Communication Engineering 110


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

VIVA QUESTIONS:

1. What is the main use of READY pin?

2. Explain PROC?

3. What is the Significance of AL reg in I/O Interfacing?

4. What is the Address of CWR of 8255(High) on ESA 86/88-2?

5. What is BSR mode of 8255?

Department of Electronics and Communication Engineering 111


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

Department of Electronics and Communication Engineering 112


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

ADDITIONAL EXPERIMENTS

Department of Electronics and Communication Engineering 113


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

Department of Electronics and Communication Engineering 114


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

EXPERIMENT-18
FINDING EVEN AND ODD NUMBERS IN AN GIVEN ARRAY

OBJECTIVE: To write an assembly language program to find the even and odd
numbers in an given array..

TOOLS REQUIRED: PC With installed Windows 7, DOSBOX and MASM.

FLOW CHART:

Department of Electronics and Communication Engineering 115


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
N1 DB 56H, 49H, 33H
EVN DW 1 DUP (00)
ODD DW 1 DUP (00)
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
XOR AX, AX
MOV SI, OFFSET N1
MOV DX, 0000H
MOV BX, 0000H
MOV CX, 0003H
BACK: MOV AL, [SI]
ROR AL, 01H
JC X
INC BX
JMP Y
X: INC DX
Y: INC SI
DEC CX
JNZ BACK
MOV EVN,BX
MOV ODD,DX
INT 3H
CODE ENDS
END START

OUTPUT:

Department of Electronics and Communication Engineering 116


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

RESULT:

VIVA QUESTIONS:

1. What happens when HLT instruction is executed in processor?

2. What is meant by a bus?

3. Give an example of one address microprocessor?

4. In what way interrupts are classified in 8086?

5. What are Hardware interrupts?

Department of Electronics and Communication Engineering 117


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

Department of Electronics and Communication Engineering 118


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

EXPERIMENT-19
FINDING POSITIVE AND NEGATIVE NUMBERS IN AN GIVEN ARRAY

OBJECTIVE: To write an assembly language program to find the Positive and


Negative numbers in an given array..

TOOLS REQUIRED: PC With installed Windows 7, DOSBOX and MASM.

FLOW CHART:

Department of Electronics and Communication Engineering 119


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:
ASSUME CS:CODE, DS:DATA
DATA SEGMENT
N1 DB 51H, 20H, 33H, 80H,19H
POSITIVE DW 1 DUP (00)
NEGATIVE DW 1 DUP (00)
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
XOR AX, AX
MOV SI, OFFSET N1
MOV DX, 0000H
MOV BX, 0000H
MOV CX, 0005H
BACK: MOV AL, [SI]
ROL AL, 01H
JC X
INC BX
JMP Y
X: INC DX
Y: INC SI
DEC CX
JNZ BACK
MOV POSITIVE,BX
MOV NEGATIVE,DX
INT 3H
CODE ENDS
END START

OUTPUT:

Department of Electronics and Communication Engineering 120


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

RESULT:

VIVA QUESTIONS:

1. What happens when we set Trap Flag?

2. In 8086 which is called as Accumulator?

3. What are input & output devices?

4. Which device can be used as clock source for 8086?

5. Why crystal is a preferred clock source?

Department of Electronics and Communication Engineering 121


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

EXPERIMENT-20
FINDING THE LARGSET AND SMALLEST NUMBERS IN AN GIVEN ARRAY

OBJECTIVE: To write an assembly language program to find the Largest and Smallest
numbers in an given array..

TOOLS REQUIRED: PC With installed Windows 7, DOSBOX and MASM.

FLOW CHART:

Department of Electronics and Communication Engineering 122


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

PROGRAM:
ASSUME CS:CODE, DS:DATA
DATA SEGMENT
N1 DB 20H, 33H,08H,19H,77h
LARGEST DB 1 DUP(00)
SMALLEST DB 1 DUP(00)
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
XOR AX, AX
MOV SI, OFFSET N1
MOV DX, 0000H
MOV BX, 0000H
MOV CX, 0004H
MOV AL, [SI]
BACK: CMP AL,[SI+1]
JG X
MOV AL,[SI+1]
X: INC SI
LOOP BACK
MOV LARGEST,AL
MOV CX,04H
MOV SI,OFFSET N1
MOV AL, [SI]
BACK1: CMP AL,[SI+1]
JL Y
MOV AL,[SI+1]
Y: INC SI
LOOP BACK1
MOV SMALLEST,AL
INT 3H
CODE ENDS
END START

OUTPUT:

Department of Electronics and Communication Engineering 123


MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

RESULT:

VIVA QUESTIONS:

1. Which is by default pointer for CS/ES?

2. How many segments present in it?

3. What is the size of each segment?

4. Basic difference between 8085 and 8086?

5. Which operations are not available in 8085?

Department of Electronics and Communication Engineering 124

You might also like