2.microprocessor Microcontroller Lab 2
2.microprocessor Microcontroller Lab 2
com
CHENDU
COLLEGE OF ENGINEERING AND TECHNOLOGY
MADURANTAKAM.
KANCHEEPURAM-603311.
www.vidyarthiplus.com
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
INDEX
EXPT.NO
PAGE
NO
3
10
11
36
38
40
Digital clock
42
10
45
11
Printer status
48
12
49
13
53
14
59
15
70
16
www.vidyarthiplus.com
17
31
72
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
EXPT NO: 01
DATE:
AIM:
To write an Assembly Language Program (ALP) for performing the Arithmetic
operation of two byte numbers.
APPARATUS REQUIRED:
SL.N
O
1.
2.
ITEM
Microprocessor kit
Power Supply
SPECIFICATION
8086 kit
+5 V dc
QUANTITY
1
1
PROBLEM STATEMENT:
Write an ALP in 8086 to add and subtract two byte numbers stored in the
memory location 1000H to 1003H and store the result in the memory location
1004H to 1005H.Also provide an instruction in the above program to consider the
carry also and store the carry in the memory location 1006H.
ALGORITHM:
(iii) Multiplication of 16-bit
(i) 16-bit addition
Initialize the MSBs of sum to 0
Get the first number.
Add the second number to the first
number.
If there is any carry, increment
MSBs of sum by 1.
Store LSBs of sum.
Store MSBs of sum.
(ii) 16-bit subtraction
Initialize the MSBs of difference to
0
Get the first number
Subtract the second number from
the first number.
If there is any borrow, increment
MSBs of difference by 1.
Store LSBs of difference
Store MSBs of difference.
numbers:
Get the multiplier.
Get the multiplicand
Initialize the product to 0.
Product
=
product
+
multiplicand
Decrement the multiplier by 1
If multiplicand is not equal to
0,repeat from step (d) otherwise
store the product.
(iv) Division of 16-bit numbers.
Get the dividend
Get the divisor
Initialize the quotient to 0.
Dividend = dividend divisor
If the divisor is greater, store the
quotient. Go to step g.
www.vidyarthiplus.com
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
FLOWCHART
ADDITION
SUBTRACTION
START
START
GET FIRST
OPERAND TO A
SUBTRACT
SECOND OPERAND
FROM MEMORY
YES
A=A+B
IS THERE
ANY CY
YES
NO
IS THERE
ANY CARRY
COUNTER =
COUNTER + 1
NO
STORE THE SUM
COUNTER =
COUNTER + 1
STORE THE
DIFFERENCE
STOP
STOP
www.vidyarthiplus.com
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
ADDITION
ADDRESS
Opcodes
PROGRAM
DEPT OF CSE
COMMENTS
Initialize counter CX
MOV AX,[1200]
ADD AX,BX
JNC L1
INC CX
L1 : MOV [1206],CX
MOV [1204], AX
HLT
SUBTRACTION
ADDRESS
OPCODES
PROGRAM
COMMENTS
Initialize counter CX
MOV AX,[1200]
SUB AX,BX
JNC L1
INC CX
L1 : MOV [1206],CX
MOV [1204], AX
HLT
www.vidyarthiplus.com
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
RESULT:.
ADDITION
MEMORY
DATA
SUBTRACTION
MEMORY
DATA
MANUAL CALCULATION
www.vidyarthiplus.com
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
FLOWCHART
MULTIPLICATION
DIVISION
Start
StartStart
QUOTIENT = 0
REGISTER=00
REGISTER=00
DIVIDEND =
DIVIDEND-DIVISOR
REGISTER
= REGISTER
REGISTER
=
+ MULTIPLICAND
REGISTER +
MULTIPLICAND
QUOTIENT = QUOTIENT+1
Multiplier=MULTIPLI
ER Multiplier=MU
1
LTIPLIER 1
NO
NO
IS IS
MULTIPLI
MULTIPLIER
ER=0?
IS
DIVIDEN
D<
DIVISOR
?
=0?
YES
YES
STORE QUOTIENT
STORE REMAINDER
= DIVIDEND NOW
STOP
STOP
www.vidyarthiplus.com
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
MULTIPLICATION
ADDRESS
Opcodes
PROGRAM
COMMENTS
MOV AX,[1200]
MUL BX
Multiply both
MOV [1206],AX
MOV AX,DX
MOV [1208],AX
HLT
DIVISION
ADDRESS
Opcodes
PROGRAM
COMMENTS
MOV AX,[1200]
DIV BX
MOV [1206],AX
MOV AX,DX
MOV [1208],AX
HLT
www.vidyarthiplus.com
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
RESULT:.
MULTIPLICATION
MEMORY
DATA
DIVISON
MEMORY
DATA
MANUAL CALCULATION
Thus Arithmetic operation of two byte numbers are performed and the result is stored.
www.vidyarthiplus.com
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
EXP.NO: 02
DATE:
AIM:
To convert a given Move a data block without overlap
.
ALGORITHM:
1. Initialize the memory location to the data pointer.
2. Increment B register.
3. Increment accumulator by 1 and adjust it to decimal every time.
4. Compare the given decimal number with accumulator value.
5. When both matches, the equivalent hexadecimal value is in Bregister.
6. Store the resultant in memory location.
PROGRAM:
DATA SEGMENT
X DB 01H,02H,03H,04H,05H ;Initialize Data Segments Memory Locations
Y DB 05 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA ; Initialize DS to point to start of the memory
MOV DS,AX ; set aside for storing of data
MOV CX,05H ; Load counter
LEA SI,X+04 ; SI pointer pointed to top of the memory block
LEA DI,X+04+03 ; 03 is displacement of over lapping, DI pointed to
;the top of the destination block
CODE ENDS
END START
Output:
RESULT:
Thus the output for the Move a data block without overlap was executed successfully
www.vidyarthiplus.com
10
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
DATE:
AIM:
To convert a given decimal number to hexadecimal.
ALGORITHM:
1. Initialize the memory location to the data pointer.
2. Increment B register.
3. Increment accumulator by 1 and adjust it to decimal every time.
4. Compare the given decimal number with accumulator value.
5. When both matches, the equivalent hexadecimal value is in Bregister.
6. Store the resultant in memory location.
FLOWCHART :
www.vidyarthiplus.com
11
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
PROGRAM:
INPUT
OUTPUT
MEMORY
DATA
www.vidyarthiplus.com
12
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
www.vidyarthiplus.com
13
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
www.vidyarthiplus.com
DEPT OF CSE
14
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
www.vidyarthiplus.com
15
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
PROGRAM
RESULT:
Thus the output for the addition for two matrix was executed successfully.
www.vidyarthiplus.com
16
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
EXPT NO:04
COPYING A STRING
AIM:
To move a string of length FF from source to destination.
DATE:
ALGORITHM:
a. Initialize the data segment .(DS)
b. Initialize the extra data segment .(ES)
c. Initialize the start of string in the DS. (SI)
d. Initialize the start of string in the ES. (DI)
e. Move the length of the string(FF) in CX register.
f. Move the byte from DS TO ES, till CX=0.
START
Initialize DS,ES,SI,DI
CX=length of string,
DF=0.
Decrement CX
NO
Check for
ZF=1
STOP
www.vidyarthiplus.com
17
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
COPYING A STRING
ADDRESS OPCODES
PROGRAM
DEPT OF CSE
COMMENTS
MOV SI,1200H
MOV DI,1300H
MOV CX,0006H
CLD
REP MOVSB
HLT
RESULT:
INPUT
MEMORY
DATA
OUTPUT
MEMORY
DATA
Thus a string of a particular length is moved from source segment to destination segment
www.vidyarthiplus.com
18
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
SEARCHING A STRING
AIM:
To scan for a given byte in the string and find the relative address of the byte from the
starting location of the string.
ALGORITHM:
a. Initialize the extra segment .(ES)
b. Initialize the start of string in the ES. (DI)
c. Move the number of elements in the string in CX register.
d. Move the byte to be searched in the AL register.
e. Scan for the byte in ES. If the byte is found ZF=0, move the address pointed by ES:DI
to BX.
START
NO
Check for
ZF=1
Move DI to BX
STOP
www.vidyarthiplus.com
19
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
SEARCHING FOR A CHARACTER IN THE STRING
ADDRESS OPCODES
PROGRAM
DEPT OF CSE
COMMENTS
MOV DI,1300H
CLD
REPNE SCASB
DEC DI
MOV BL,[DI]
MOV [SI],BL
HLT
Stop
RESULT:
INPUT
MEMORY
DATA
OUTPUT
MEMORY LOCATION
DATA
Thus a given byte or word in a string of a particular length in the extra segment(destination)
is found .
www.vidyarthiplus.com
20
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
NO
Check for ZF=1
YES
Move the content of BL
to ES:DI
STOP
www.vidyarthiplus.com
21
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
MOV SI,1400H
CLD
MOV BH,30H
REPNE SCASB
DEC DI
MOV BL,[DI]
MOV [SI],BL
MOV [DI],BH
HLT
Stop
RESULT:
INPUT
MEMORY
DATA
OUTPUT
MEMORY
DATA
Thus a given byte or word in a string of a particular length in the extra segment(destination)
is found and is replaced with another character.
www.vidyarthiplus.com
22
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
AIM:
ITEM
Microprocessor kit
Power Supply
SPECIFICATION
8086
+5 V dc
QUANTITY
1
1
PROBLEM STATEMENT:
An array of length 10 is given from the location. Sort it into descending
and ascending order and store the result.
ALGORITHM:
(i)
Sorting in ascending order:
a. Load the array count in two registers C1 and C2.
b. Get the first two numbers.
c. Compare the numbers and exchange if necessary so that the two numbers are
in ascending order.
d. Decrement C2.
e. Get the third number from the array and repeat the process until C2 is 0.
f. Decrement C1 and repeat the process until C1 is 0.
(ii)
www.vidyarthiplus.com
23
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
FLOWCHART
ASCENDING ORDER
DEPT OF CSE
DESCENDING ORDER
START
START
INITIALIZE POINTER
INITIALIZE POINTER
COUNT = COUNT 1
COUNT = COUNT 1
FLAG = 0
FLAG = 0
YES
IS POINTER
POINTER
+1
YES
IS POINTER
POINTER
+1
NO
NO
TEMP = POINTER
POINTER = POINTER + 1
POINTER + 1 = TEMP
TEMP = POINTER
POINTER = POINTER + 1
POINTER + 1 = TEMP
POINTER = POINTER +1
COUNT = COUNT + 1
POINTER = POINTER +1
COUNT = COUNT + 1
NO
NO
IS
IS
COUNT
COUNT
=0
=0
YES
YES
NO
IS FLAG
IS FLAG
= 0
= 0
YES
YES
STOP
STOP
www.vidyarthiplus.com
24
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
ASCENDING
ADDRESS
OPCODES
PROGRAM
MOV SI,1200H
COMMENTS
Initialize memory location for array size
MOV CL,[SI]
Number of comparisons in CL
L4 : MOV SI,1200H
MOV DL,[SI]
INC SI
MOV AL,[SI]
L3 : INC SI
MOV BL,[SI]
CMP AL,BL
JNB L1
If AL < BL go to L1
DEC SI
MOV [SI],AL
MOV AL,BL
JMP L2
Jump to L2
L1 : DEC SI
MOV [SI],BL
L2 : INC SI
DEC DL
JNZ L3
MOV [SI],AL
DEC CL
JNZ L4
HLT
Stop
PROGRAM
MOV SI,1200H
COMMENTS
Initialize memory location for array size
MOV CL,[SI]
Number of comparisons in CL
L4 : MOV SI,1200H
MOV DL,[SI]
INC SI
MOV AL,[SI]
L3 : INC SI
DESCENDING
ADDRESS
OPCODES
www.vidyarthiplus.com
25
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
MOV BL,[SI]
CMP AL,BL
JB L1
If AL > BL go to L1
DEC SI
MOV [SI],AL
MOV AL,BL
JMP L2
Jump to L2
L1 : DEC SI
MOV [SI],BL
L2 : INC SI
DEC DL
JNZ L3
MOV [SI],AL
DEC CL
JNZ L4
HLT
Stop
RESULT:.
ASCENDING
MEMORY
DATA
DESCENDING
MEMORY
DATA
Thus given array of numbers are sorted in ascending & descending order.
www.vidyarthiplus.com
26
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
LARGEST& SMALLEST
AIM:
ITEM
SPECIFICATION
Microprocessor kit
Power Supply
8086
+5 V dc
QUANTITY
1
1
PROBLEM STATEMENT:
An array of length 10 is given from the location. Find the largest and
smallest number and store the result.
ALGORITHM:
(i)
Finding largest number:
a.
b.
c.
d.
(ii)
e.
f.
g.
h.
www.vidyarthiplus.com
27
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
FLOWCHART
LARGEST NUMBER IN AN ARRAY
DEPT OF CSE
START
START
INITIALIZE
COUNT
POINTER MAX =
0
INITIALIZE
COUNT
POINTER MIN = 0
PONITER =
POINTER + 1
PONITER =
POINTER + 1
YES
IS MAX
YES
POINTE
R ?
IS MIN
POINTER
?
NO
NO
MAX = POINTER
MIN = POINTER
COUNT = COUNT-1
COUNT = COUNT-1
NO
NO
IS COUNT = 0
?
IS COUNT = 0
?
YES
YES
STORE MINIIMUM
STORE MAXIMUM
STOP
STOP
www.vidyarthiplus.com
28
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
LARGEST
ADDRESS OPCODES
PROGRAM
COMMENTS
MOV SI,1200H
MOV CL,[SI]
INC SI
MOV AL,[SI]
DEC CL
L2 : INC SI
CMP AL,[SI]
JNB L1
MOV AL,[SI]
L1 : DEC CL
JNZ L2
MOV DI,1300H
MOV [DI],AL
HLT
Stop
SMALLEST
ADDRESS
OPCODES
PROGRAM
COMMENTS
MOV SI,1200H
MOV CL,[SI]
INC SI
MOV AL,[SI]
DEC CL
L2 : INC SI
CMP AL,[SI]
JB L1
MOV AL,[SI]
L1 : DEC CL
JNZ L2
MOV DI,1300H
MOV [DI],AL
HLT
Stop
www.vidyarthiplus.com
29
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
RESULT:.
LARGEST
MEMORY
DATA
SMALLEST
MEMORY
DATA
www.vidyarthiplus.com
30
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
EXPT NO:05
DATE:
AIM:
To write an Assembly Language Program (ALP) for performing the Arithmetic
operation of two byte numbers
APPARATUS REQUIRED:
SL.N
O
1.
2.
ITEM
Microprocessor kit
Power Supply
SPECIFICATION
8086 kit
+5 V dc
QUANTITY
1
1
PROGRAM:
;PASSWORD IS MASM1234
DATA SEGMENT
PASSWORD DB 'MASM1234'
LEN EQU ($-PASSWORD)
MSG1 DB 10,13,'ENTER YOUR PASSWORD: $'
MSG2 DB 10,13,'WELCOME TO ELECTRONICS WORLD!!$'
MSG3 DB 10,13,'INCORRECT PASSWORD!$'
NEW DB 10,13,'$'
INST DB 10 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
LEA DX,MSG1
MOV AH,09H
INT 21H
MOV SI,00
UP1:
MOV AH,08H
INT 21H
CMP AL,0DH
JE DOWN
MOV [INST+SI],AL
MOV DL,'*'
MOV AH,02H
INT 21H
INC SI
JMP UP1
DOWN:
www.vidyarthiplus.com
31
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
MOV BX,00
MOV CX,LEN
CHECK:
MOV AL,[INST+BX]
MOV DL,[PASSWORD+BX]
CMP AL,DL
JNE FAIL
INC BX
LOOP CHECK
LEA DX,MSG2
MOV AH,09H
INT 21H
JMP FINISH
FAIL:
LEA DX,MSG3
MOV AH,009H
INT 21H
FINISH:
INT 3
CODE ENDS
END START
END
;Today.asm Display month/day/year.
; Feb 1st, 2012
;CIS 206 Ken Howard
.MODEL small
.STACK 100h
.DATA
mess1 DB 10, 13, 'Today is $' ; 10=LF, 13=CR
.CODE
Today PROC
MOV AX, @data
MOV DS, AX
MOV DX, OFFSET mess1 ; Move string to DX
MOV AH, 09h
; 09h call to display string (DX > AH > DOS)
INT 21H
; Send to DOS
; CX year, DH month, DL day
MOV AH, 2AH
; Get the date (appendix D)
INT 21H
; Send to DOS
PUSH CX
; Move year to the stack
MOV CX, 0
; Clear CX
MOV CL, DL
PUSH CX
; Move day to stack
MOV CL, DH
; Move month > CL
PUSH CX
; Move month to stack
MOV DH, 0
; Clear DH
; ************************** DISPLAY MONTH ************************
www.vidyarthiplus.com
32
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
www.vidyarthiplus.com
33
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
www.vidyarthiplus.com
34
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
RESULT:
Thus the output for the Password checking, Print RAM size and system date was
executed successfully
www.vidyarthiplus.com
35
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
EXP.NO: 06
DATE:
AIM:
To write an assembly language program in 8086 to Counters and Time Delay
APPARATUS REQUIRED:
SL.NO
ITEM
1.
Microprocessor kit
2.
Power Supply
3.
Stepper Motor Interface board
4.
Stepper Motor
SPECIFICATION
8086
+5 V, dc,+12 V dc
-
QUANTITY
1
1
1
1
PROGRAM:
.MODEL SMALL
.DATA
MSGIN DB 'Enter delay duration (0-50): $'
MSG1 DB 'This is Microprocessor!$'
DELAYTIME DW 0000H
.CODE
MOV DX,@DATA
MOV DS,DX
LEA DX,MSGIN
MOV AH,09H
INT 21H
IN1:
MOV AH,01H
INT 21H
CMP AL,0DH ;
JE NXT
SUB AL,30H
MOV DL,AL
MOV AX,BX
MOV CL,0AH
MUL CL
MOV BX,AX
AND DX,00FFH
ADD BX,DX
MOV DELAYTIME,BX
LOOP IN1
www.vidyarthiplus.com
36
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
NXT:
MOV CX,DELAYTIME
MOV DL,10
MOV AH,02H
INT 21H
LEA SI,MSG1
LP: PUSH DX
MOV DL,[SI]
CMP DL,'$'
JE NXT2
MOV AH,02H
INT 21H
ADD SI,1
POP DX
MOV DI,DELAYTIME
MOV AH, 0
INT 1Ah
MOV BX, DX
Delay:
MOV AH, 0
INT 1Ah
SUB DX, BX
CMP DI, DX
JA Delay
LOOP LP
NXT2: MOV AH,4CH
INT 21H
END
RESULT:
Thus the output for the Counters and Time Delay was executed successfully
www.vidyarthiplus.com
37
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
EXP.NO: 07
DATE:
AIM:
To write an assembly language program in 8086 to Traffic light control
APPARATUS REQUIRED:
SL.NO
SPECIFICATION
QUANTITY
ITEM
1.
8086
1
Microprocessor kit
2.
+5 V, dc,+12 V dc
1
Power Supply
3.
1
Traffic light control Interface
board
PROGRAM:
www.vidyarthiplus.com
38
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
www.vidyarthiplus.com
DEPT OF CSE
39
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
EXP.NO: 08
DATE:
AIM:
To write an assembly language program in 8086 to rotate the motor at different speeds.
APPARATUS REQUIRED:
SL.NO
1.
2.
3.
4.
ITEM
Microprocessor kit
Power Supply
Stepper Motor Interface board
Stepper Motor
SPECIFICATION
8086
+5 V, dc,+12 V dc
-
QUANTITY
1
1
1
1
PROBLEM STATEMENT:
Write a code for achieving a specific angle of rotation in a given time and particular
number of rotations in a specific time.
THEORY:
A motor in which the rotor is able to assume only discrete stationary angular
position is a stepper motor. The rotary motion occurs in a stepwise manner from one
equilibrium position to the next.Two-phase scheme: Any two adjacent stator windings are
energized. There are two magnetic fields active in quadrature and none of the rotor pole faces
can be in direct alignment with the stator poles. A partial but symmetric alignment of the
rotor poles is of course possible.
ALGORITHM:
For running stepper motor clockwise and anticlockwise directions
(i)
Get the first data from the lookup table.
(ii)
Initialize the counter and move data into accumulator.
(iii) Drive the stepper motor circuitry and introduce delay
(iv)
Decrement the counter is not zero repeat from step(iii)
(v)
Repeat the above procedure both for backward and forward directions.
SWITCHING SEQUENCE OF STEPPER MOTOR:
MEMORY
LOCATION
4500
4501
4502
4503
A1
A2
B1
B2
1
0
0
1
0
1
1
0
0
0
1
1
0
1
0
0
HEX
CODE
09 H
05 H
06 H
0A H
www.vidyarthiplus.com
40
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
FLOWCHART:
DEPT OF CSE
START
INTIALIZE COUNTER FOR LOOK UP TABLE
DECREMENT COUNTER
IS B = 0 ?
COMMENTS
OUT 0C0,AL
Introduce delay
JNZ L1
INC DI
LOOP LOOP1
JMP START
1200 : 09,05,06,0A
Array of datas
RESULT: Thus the assembly language program for rotating stepper motor in both clockwise
and anticlockwise directions is written and verified.
www.vidyarthiplus.com
41
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
DIGITAL CLOCK
EXP.NO: 09
DATE:
Aim
To display the digital clock specifically by displaying the hours, minutes and seconds
using 8086 kits
Apparatus required
S.No
1
2
Item
Microprocessor kit
Power Supply
Specification
8086
5V
+5 V, dc,
+12 V dc
Preliminary Settings
Org 1000h
Store time value in memory location 1500- Seconds
1501- Minutes
1502- Hours
Digital clock program
www.vidyarthiplus.com
42
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
www.vidyarthiplus.com
DEPT OF CSE
43
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
Result
Thus the digital clock program has been written and executed using 8086
microprocessor kit and the output of digital clock was displayed as [hours: minutes: seconds]
successfully.
www.vidyarthiplus.com
44
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
EXP.NO:10
DATE:
AIM :
To display the rolling message HELP US in the display.
APPARATUS REQUIRED:
8086 Microprocessor kit, Power supply, Interfacing board.
ALGORITHM :
Display of rolling message HELP US
1. Initialize the counter
2. Set 8279 for 8 digit character display, right entry
3. Set 8279 for clearing the display
4. Write the command to display
5. Load the character into accumulator and display it
6. Introduce the delay
7. Repeat from step 1.
1. Display Mode Setup: Control word-10 H
0
0
0
0
0
0
1
D
0
D
0
K
0
K
0
K
1
CD
1
CD
0
CF
0
CA
DD
00- 8Bit character display left entry
01- 16Bit character display left entry
10- 8Bit character display right entry
11- 16Bit character display right entry
KKK- Key Board Mode
000-2Key lockout.
2.Clear Display: Control word-DC H
1
1
1
1
0
0
1
CD
11
45
1-Clear all bits
(Combined effect of CD)
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
0
1
0
0
AI
SEGMENT DEFINITION
DATA BUS
D7
SEGMENTS d
D6
D5
D4
D3
D2
D1
D0
dp
www.vidyarthiplus.com
46
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
PROGRAM TABLE
PROGRAM
COMMENTS
Initialize array
MOV CX,000FH
MOV AL,10
OUT C2,AL
MOV AL,CC
OUT C2,AL
MOV AL,90
OUT C2,AL
L1 : MOV AL,[SI]
OUT C0,AL
CALL DELAY
Give delay
INC SI
LOOP L1
JMP START
Go to starting location
LOOP1 : DEC DX
JNZ LOOP1
RET
LOOK-UP TABLE:
1200
1204
98
FF
68
1C
7C
29
C8
FF
RESULT:
MEMORY
LOCATION
1200H
1201H
1202H
1203H
1204H
1205H
1206H
1207H
d
1
0
0
1
1
0
0
1
HEX DATA
f
0
0
0
0
1
0
1
1
98
68
7C
C8
FF
1C
29
FF
Thus the rolling message HELP US is displayed using 8279 interface kit.
www.vidyarthiplus.com
47
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
PRINTER STATUS
EXP.NO:11
AIM:
To display the Printer Status in the display
DATE:
APPARATUS REQUIRED:
8086 Microprocessor kit, Power supply, interfacing board.
PROGRAM:
XOR AX, AX
XOR BX, BX
;this divides my 3digit number by 100 giving me my, hundredth digit
MOV AX, RES
MOV BX, 100
DIV BX
;prints the hundredth digit
ADD AL, '0'
MOV DL, AL
PUSH AX ; save AX on the stack
MOV AH, 02h
INT 21h
POP AX ; restore ax
;divides the remainder by 10 giving me my tens digit
MOV BX, 10
DIV BX
;prints my tens digit
ADD AL, '0'
MOV DL, AL
PUSH AX ; save AX on the stack
MOV AH, 02h
INT 21h
POP AX ; restore ax
;print my last remainder which is my ones
ADD AH, '0'
MOV DL, AH
MOV AH, 02h
INT 21h
RESULT:
Thus the output for the Move a data block without overlap was executed successfully
www.vidyarthiplus.com
48
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
EXP.NO: 12
DATE:
Aim
To connect two 8086 microprocessor kits and to serially communicate with
each other by considering transmitter and receiver kits.
Apparatus required
Procedure
1. Take two no of 8086 microprocessor kits.
2. Enter the transmitter program in transmitter kit.
3. Enter the receiver program in receiver kit.
4. Interface the two kits with 9-9 serial cable in the serial port of the microprocessor kits.
(LCD kit means PC-PC cable. LED kit means kit-kit cable)
5. Enter the data in transmitter kit use the memory location 1500.
6. Execute the receiver kit.
7. Execute the transmitter kit.
8. Result will be available in receiver kit memory location 1500.
Transmitter Program
www.vidyarthiplus.com
49
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
Receiver Program
Result
Thus the serial communication between two 8086 microprocessor kits has been
established and the data is transmitted in one kit and received in the other kit
successfully
www.vidyarthiplus.com
50
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
Procedure
1. Take two 8086 microprocessor kits.
2. Enter the transmitter program in transmitter kit.
3. Enter the receiver program in receiver kit.
4. Interface the two kits with 26-core cable on PPI-1.
5. Execute the receiver kit.
6. Execute the transmitter kit.
7. Go and see the memory location 1200 in receiver to get same eight data.
8. Data is available in transmitter kit in the memory location.
9. Change the data & execute the following procedure & get the result in receiver kit.
Transmitter program
www.vidyarthiplus.com
51
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
Receiver Program
Result
Thus the serial communication between two 8086 microprocessor kits has been established
and the data is transmitted in one kit and received in the other kit successfully.
www.vidyarthiplus.com
52
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
EXPT NO:13
DATE:
AIM:
To write an assembly language program to convert an analog signal into a digital signal
using an ADC interfacing.
APPARATUS REQUIRED:
ITEM
SL.NO
SPECIFICATION
QUANTITY
1.
8086
1
Microprocessor kit
2.
+5 V dc,+12 V dc
1
Power Supply
3.
1
ADC Interface board
THEORY:
An ADC usually has two additional control lines: the SOC input to tell the ADC when to
start the conversion and the EOC output to announce when the conversion is complete. The
following program initiates the conversion process, checks the EOC pin of ADC 0809 as to
whether the conversion is over and then inputs the data to the processor. It also instructs the
processor to store the converted digital data at RAM location.
ALGORITHM:
(i)
Select the channel and latch the address.
(ii)
Send the start conversion pulse.
(iii) Read EOC signal.
(iv)
If EOC = 1 continue else go to step (iii)
(v)
Read the digital output.
(vi)
Store it in a memory location.
FLOW CHART:
START
STOP
www.vidyarthiplus.com
53
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
PROGRAM TABLE
PROGRAM
COMMENTS
MOV AL,00
OUT 0C8H,AL
MOV AL,08
OUT 0C8H,AL
MOV AL,01
OUT 0D0H,AL
MOV AL,00
MOV AL,00
Introduce delay
MOV AL,00
MOV AL,00
OUT 0D0H,AL
L1 : IN AL, 0D8H
AND AL,01
CMP AL,01
Read the EOC signal from port & check for end of
conversion
JNZ L1
IN AL,0C0H
MOV BX,1100
MOV [BX],AL
HLT
RESULT:
Stop
ANALOG
VOLTAGE
DISPLAY
LOCATION
Thus the ADC was interfaced with 8086 and the given analog inputs were converted into its
digital equivalent.
www.vidyarthiplus.com
54
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
www.vidyarthiplus.com
55
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
FLOWCHART:
MEASUREMENT OF ANALOG VOLTAGE
DEPT OF CSE
START
INTIALISE THE
ACCUMULATOR SEND ACC
CONTENT TO DAC
SEND THE
DIGITALVALUE TO
ACCUMULATOR
DELAY
TRANSFER THE
ACCUMULATOR
CONTENTS TO DAC
TRIANGULAR WAVEFORM
STOP
START
SAWTOOTH WAVEFORM
INITIALIZE
ACCUMULATOR
START
SEND ACCUMULATOR
CONTENT TO DAC
INITIALIZE
ACCUMULATOR
INCREMENT
ACCUMULATOR
CONTENT
SEND ACCUMULATOR
CONTENT TO DAC
YES
INCREMENT
ACCUMULATOR
CONTENT
NO
IS ACC
FF
NO
YES
DECREMENT
ACCUMULATOR CONTENT
IS ACC
FF
SEND
ACCUMULATOR
CONTENT TO DAC
YES
www.vidyarthiplus.com
IS ACC
00
NO
56
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
COMMENTS
MOV AL,7FH
OUT C0,AL
HLT
Stop
DIGITAL DATA
ANALOG VOLTAGE
COMMENTS
L2 : MOV AL,00H
Load 00 in accumulator
OUT C0,AL
CALL L1
Give a delay
MOV AL,FFH
Load FF in accumulator
OUT C0,AL
CALL L1
Give a delay
JMP L2
Go to starting location
L1 : MOV CX,05FFH
L3 : LOOP L3
RET
COMMENTS
L2 : MOV AL,00H
Load 00 in accumulator
L1 : OUT C0,AL
INC AL
JNZ L1
JMP L2
Go to starting location
www.vidyarthiplus.com
57
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
COMMENTS
L3 : MOV AL,00H
Load 00 in accumulator
L1 : OUT C0,AL
INC AL
JNZ L1
MOV AL,0FFH
Load FF in accumulator
L2 : OUT C0,AL
DEC AL
JNZ L2
JMP L3
Go to starting location
RESULT:WAVEFORM GENERATION:
WAVEFORMS
AMPLITUDE
TIMEPERIOD
Square Waveform
Saw-tooth waveform
Triangular waveform
MODEL GRAPH:
Square Waveform
Saw-tooth waveform
Triangular waveform
Thus the DAC was interfaced with 8085 and different waveforms have been generated.
www.vidyarthiplus.com
58
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
EXPT NO:14
DATE:
8 BIT ADDITION
AIM:
To write a program to add two 8-bit numbers using 8051 microcontroller.
ALGORITHM:
1. Clear Program Status Word.
2. Select Register bank by giving proper values to RS1 & RS0 of PSW.
3. Load accumulator A with any desired 8-bit data.
4. Load the register R 0 with the second 8- bit data.
5. Add these two 8-bit numbers.
6. Store the result.
7. Stop the program.
FLOW CHART:
START
Clear PSW
Select Register
Bank
Load A and R 0
with 8- bit datas
Add A & R 0
Store the sum
STOP
www.vidyarthiplus.com
59
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
8 Bit Addition (Immediate Addressing)
ADDRESS LABEL MNEMONIC OPERAND
4100
CLR
HEX
CODE
C3
4101
MOV
A, data1
74,data1
4103
ADDC
A, # data 2
24,data2
4105
MOV
90,45,00
4108
MOVX
DPTR, #
4500H
@ DPTR, A
SJMP
L1
80,FE
4109
L1
F0
DEPT OF CSE
COMMENTS
Clear CY Flag
RESULT:
OUTPUT
MEMORY LOCATION
DATA
4500
Thus the 8051 ALP for addition of two 8 bit numbers is executed.
www.vidyarthiplus.com
60
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
8 BIT SUBTRACTION
AIM:
To perform subtraction of two 8 bit data and store the result in memory.
ALGORITHM:
a. Clear the carry flag.
b. Initialize the register for borrow.
c. Get the first operand into the accumulator.
d. Subtract the second operand from the accumulator.
e. If a borrow results increment the carry register.
f. Store the result in memory.
FLOWCHART:
START
CLEAR CARRY
FLAG
GET IST
OPERAND IN
ACCR
SUBTRACT THE
2ND OPERAND
FROM ACCR
N
IS CF=1
Y
INCREMENT
THE BORROW
REGISTER
STORE
RESULT IN
MEMORY
STOP
www.vidyarthiplus.com
61
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
8 Bit Subtraction (Immediate Addressing)
ADDRESS LABEL
MNEMONIC OPERAND
4100
CLR
HEX
CODE
C3
4101
MOV
A, # data1
74, data1
4103
SUBB
A, # data2
94,data2
4105
MOV
DPTR, # 4500
90,45,00
4108
MOVX
@ DPTR, A
F0
SJMP
L1
80,FE
4109
L1
DEPT OF CSE
COMMENTS
Store data1 in
accumulator
Subtract data2 from
data1
Initialize memory
location
Store the difference
in memory location
Stop
Clear CY flag
RESULT:
OUTPUT
MEMORY LOCATION
DATA
4500
Thus the 8051 ALP for subtraction of two 8 bit numbers is executed.
www.vidyarthiplus.com
62
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
8 BIT MULTIPLICATION
AIM:
To perform multiplication of two 8 bit data and store the result in memory.
ALGORITHM:
a. Get the multiplier in the accumulator.
b. Get the multiplicand in the B register.
c. Multiply A with B.
d. Store the product in memory.
FLOWCHART:
START
GET
MULTIPLIER
IN ACCR
GET
MULTIPLICAND
IN B REG
MULTIPLY A
WITH B
STORE
RESULT IN
MEMORY
STOP
www.vidyarthiplus.com
63
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
8 Bit Multiplication
ADDRESS LABEL
MNEMONIC
OPERAND
4100
MOV
A ,#data1
HEX
CODE
74, data1
4102
MOV
B, #data2
75,data2
Store data1 in
accumulator
Store data2 in B reg
4104
MUL
A,B
F5,F0
Multiply both
4106
MOV
90,45,00
4109
MOVX
DPTR, #
4500H
@ DPTR, A
401A
INC
DPTR
A3
Initialize memory
location
Store lower order
result
Go to next memory
location
410B
MOV
A,B
E5,F0
410D
410E
STOP
F0
COMMENTS
MOV
@ DPTR, A
F0
SJMP
STOP
80,FE
Stop
RESULT:
INPUT
MEMORY LOCATION
DATA
OUTPUT
MEMORY LOCATION
4500
4502
4501
4503
DATA
Thus the 8051 ALP for multiplication of two 8 bit numbers is executed.
www.vidyarthiplus.com
64
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
8 BIT DIVISION
AIM:
To perform division of two 8 bit data and store the result in memory.
ALGORITHM:
1. Get the Dividend in the accumulator.
2. Get the Divisor in the B register.
3. Divide A by B.
4. Store the Quotient and Remainder in memory.
FLOWCHART:
START
GET DIVIDEND
IN ACCR
GET DIVISOR IN
B REG
DIVIDE A BY B
STORE
QUOTIENT &
REMAINDER
IN MEMORY
STOP
www.vidyarthiplus.com
65
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
8 Bit Division
ADDRESS LABEL MNEMONIC
OPERAND
4100
MOV
A, # data1
HEX
CODE
74,data1
4102
MOV
B, # data2
75,data2
Store data1 in
accumulator
Store data2 in B reg
4104
DIV
A,B
84
Divide
4015
MOV
DPTR, # 4500H
90,45,00
4018
MOVX
@ DPTR, A
F0
Initialize memory
location
Store remainder
4109
INC
DPTR
A3
410A
MOV
A,B
E5,F0
COMMENTS
Go to next memory
location
Store quotient
410C
410D
STOP
MOV
@ DPTR, A
F0
SJMP
STOP
80,FE
Stop
RESULT:
INPUT
MEMORY LOCATION
4500
(dividend)
4501
(divisor)
DATA
OUTPUT
MEMORY LOCATION
4502
(remainder)
4503
DATA
(quotient)
Thus the 8051 ALP for division of two 8 bit numbers is executed.
www.vidyarthiplus.com
66
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
FLOWCHART:
START
www.vidyarthiplus.com
67
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
PROGRAM TABLE
ADDRESS HEX
CODE
4100
90,45,00
LABEL
MNEMONICS
OPERAND
COMMENT
MOV
DPTR,#4500
Initialize
memory
location
Get the data in
accumulator
Set CY bit
4103
74,FF
MOV
A,#FF
4105
D3
SETB
4016
82,EF
ANL
C, ACC.7
4018
410A
E5,D0
F0
MOV
MOVX
A,DOH
@DPTR,A
410B
A3
INC
DPTR
Go to next location
410C
72,AA
ORL
C, IE.2
410E
C2,D6
CLR
PSW.6
4110
4112
E5,D0
F0
MOV
MOVX
A,DOH
@DPTR,A
4113
A3
INC
DPTR
Go to next location
4114
4116
D2,90
C2,99
SETB
CLR
SCON.5
SCON.1
4118
411A
E5,98
F0
MOV
MOVX
A,98H
@DPTR,A
411B
A3
INC
DPTR
Go to next location
411C
A2,99
MOV
C,SCON.1
411E
E5,D0
MOV
A,DOH
4120
F0
MOVX
@DPTR,A
4122
80,FE
SJMP
L2
L2
www.vidyarthiplus.com
Stop
68
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
RESULT:
MEMORY
LOCATION
BEFORE
AFTER
EXECUTION EXECUTION
4500H (PSW)
CY
AC
FO
RS1
RS0 OV
00H
88H
4501H (PSW)
CY
AC
FO
RS1
RS0 OV
40H
88H
4502H (SCON)
20H
4503H (PSW)
CY
09H
AC
FO
RS1
RS0 OV
FFH
www.vidyarthiplus.com
69
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
DATE:
AIM:
To convert Square and Cube program, Find 2s complement of a number using 8051
micro controller
RESOURCES REQUIERED:
8051 microcontroller kit
Keyboard
Power supply
PROGRAM:
www.vidyarthiplus.com
70
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
www.vidyarthiplus.com
71
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
EXPT NO:16
DATE:
AIM:
To convert BCD number into ASCII by using 8051 micro controller
RESOURCES REQUIERED:
8051 microcontroller kit
Keyboard
Power supply
www.vidyarthiplus.com
72
www.vidyarthiplus.com
CS6412 MICROPROCESSOR AND
MICROCONTROLLER LAB
DEPT OF CSE
FLOWCHART:
RESULT:
The given number is converted into ASCII using 8051 microcontroller kit.
www.vidyarthiplus.com
73