2.microprocessor Microcontroller Lab 1
2.microprocessor Microcontroller Lab 1
LABORATORY MANUAL
Prepared by
N.S.SHINIJA, ASSISTANT PROFESSOR
Faculty of Electronics & Communication Engineering
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
INDEX
9 Digital clock 42
11 Printer status 48
2
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
APPARATUS REQUIRED:
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:
(i) 16-bit addition (iii) Multiplication of 16-bit
Initialize the MSBs of sum to 0 numbers:
Get the first number. Get the multiplier.
Add the second number to the first Get the multiplicand
number. Initialize the product to 0.
If there is any carry, increment Product = product +
MSBs of sum by 1. multiplicand
Store LSBs of sum. Decrement the multiplier by 1
Store MSBs of sum. If multiplicand is not equal to
0,repeat from step (d) otherwise
(ii) 16-bit subtraction store the product.
Initialize the MSBs of difference to (iv) Division of 16-bit numbers.
0 Get the dividend
Get the first number Get the divisor
Subtract the second number from Initialize the quotient to 0.
the first number. Dividend = dividend – divisor
If there is any borrow, increment If the divisor is greater, store the
MSBs of difference by 1. quotient. Go to step g.
Store LSBs of difference If dividend is greater, quotient
Store MSBs of difference. = quotient + 1. Repeat from
step (d)Store the dividend
value as remainder.
3
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
FLOWCHART
ADDITION SUBTRACTION
START START
YES
A=A+B
IS THERE
ANY CY
YES
NO COUNTER =
IS THERE
ANY CARRY COUNTER + 1
COUNTER =
COUNTER + 1
STORE THE
DIFFERENCE
NO
STOP
4
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
ADDITION
ADDRESS Opcodes PROGRAM COMMENTS
SUBTRACTION
ADDRESS OPCODES PROGRAM COMMENTS
5
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
RESULT:.
ADDITION
MEMORY
DATA
SUBTRACTION
MEMORY
DATA
MANUAL CALCULATION
6
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
IS
NO DIVIDEN
D<
DIVISOR
NO IS IS
MULTIPLI ?
MULTIPLIER
ER=0?
=0?
YES
STOP
STOP
7
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
MULTIPLICATION
DIVISION
8
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.
9
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
10
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
11
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
PROGRAM:
INPUT OUTPUT
MEMORY
DATA
12
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
13
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
14
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
FLOWCHART
15
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
PROGRAM
RESULT:
Thus the output for the addition for two matrix was executed successfully.
16
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
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
17
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
COPYING A STRING
ADDRESS OPCODES PROGRAM COMMENTS
RESULT:
INPUT
MEMORY
DATA
OUTPUT
MEMORY
DATA
Thus a string of a particular length is moved from source segment to destination segment
18
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
19
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
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 .
20
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
ALGORITHM:
a. Initialize the extra segment .(E S)
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. Store the ASCII code of the character that has to replace the scanned byte in BL
register.
f. Scan for the byte in ES. If the byte is not found, ZF≠1 and repeat scanning.
g. If the byte is found, ZF=1.Move the content of BL register to ES:DI.
START
NO
YES
Move the content of BL
to ES:DI
STOP
21
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
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.
22
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
AIM:
To write an Assembly Language Program (ALP) to sort a given array in
ascending and descending order.
APPARATUS REQUIRED:
PROBLEM STATEMENT:
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) Sorting in descending 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 descending 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.
23
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
FLOWCHART
ASCENDING ORDER DESCENDING ORDER
START
START
FLAG = 0 FLAG = 0
YES
IS POINTER YES IS POINTER
POINTER POINTER
+1 +1
NO
NO
TEMP = POINTER
TEMP = POINTER POINTER = POINTER + 1
POINTER = POINTER + 1 POINTER + 1 = TEMP
POINTER + 1 = TEMP
POINTER = POINTER +1
POINTER = POINTER +1 COUNT = COUNT + 1
COUNT = COUNT + 1
NO NO
IS
IS
COUNT
COUNT
=0 YES
=0 YES
NO
IS FLAG IS FLAG
= 0 = 0
YES
YES
STOP
STOP
24
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
ASCENDING
DESCENDING
25
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
RESULT:.
ASCENDING
MEMORY
DATA
DESCENDING
MEMORY
DATA
Thus given array of numbers are sorted in ascending & descending order.
26
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
LARGEST& SMALLEST
AIM:
To write an Assembly Language Program (ALP) to find the largest and
smallest number in a given array.
APPARATUS REQUIRED:
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. Load the array count in a register C1.
b. Get the first two numbers.
c. Compare the numbers and exchange if the number is small.
d. Get the third number from the array and repeat the process until C1 is 0.
27
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
FLOWCHART
LARGEST NUMBER IN AN ARRAY SMALLEST NUMBER IN AN ARRAY
START START
INITIALIZE
INITIALIZE
COUNT
COUNT
POINTER MAX =
POINTER MIN = 0
0
PONITER = PONITER =
POINTER + 1 POINTER + 1
YES
IS MAX IS MIN
POINTER
YES POINTE ?
R ? NO NO
NO NO
IS COUNT = 0 IS COUNT = 0
? ?
YES
YES
STORE MAXIMUM STORE MINIIMUM
STOP STOP
28
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
LARGEST
SMALLEST
29
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
RESULT:.
LARGEST
MEMORY
DATA
SMALLEST
MEMORY
DATA
30
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
APPARATUS REQUIRED:
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:
31
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 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 ************************
32
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
33
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
34
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
Ram size:
ORG 0000H
CLR PSW3
CLR PSW4
CPL A
ADD A, #01H
MOV A,R3
AGAIN: SJMP AGAIN
RESULT:
Thus the output for the Password checking, Print RAM size and system date was
executed successfully
35
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 SPECIFICATION QUANTITY
1. Microprocessor kit 8086 1
2. Power Supply +5 V, dc,+12 V dc 1
3. Stepper Motor Interface board - 1
4. Stepper Motor - 1
PROGRAM:
.MODEL SMALL
.DATA
.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
36
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
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
END
RESULT:
Thus the output for the Counters and Time Delay was executed successfully
37
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 ITEM SPECIFICATION QUANTITY
1. Microprocessor kit 8086 1
2. Power Supply +5 V, dc,+12 V dc 1
3. Traffic light control Interface - 1
board
PROGRAM:
38
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
39
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:
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:
MEMORY A1 A2 B1 B2 HEX
LOCATION CODE
4500 1 0 0 0 09 H
4501 0 1 0 1 05 H
4502 0 1 1 0 06 H
4503 1 0 1 0 0A H
40
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
FLOWCHART:
START
DELAY
DECREMENT COUNTER
IS B = 0 ?
RESULT: Thus the assembly language program for rotating stepper motor in both clockwise
and anticlockwise directions is written and verified.
41
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
42
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
43
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.
44
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.
0 0 0 1 0 0 0 0
0 0 0 D D K K K
DD
00- 8Bit character display left entry
01- 16Bit character display left entry
10- 8Bit character display right entry
11- 16Bit character display right entry
KKK- Key Board Mode
000-2Key lockout.
2.Clear Display: Control word-DC H
1 1 0 1 1 1 0 0
1 1 0 CD CD CD CF CA
1 0 0 1 0 0 0 0
1 0 0
AI A A A A
Auto increment = 1, the row address selected will be incremented after each of read and
write operation of the display RAM.
FLOWCHART
SEGMENT DEFINITION
DATA BUS D7 D6 D5 D4 D3 D2 D1 D0
SEGMENTS d c b a dp g f e
46
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
PROGRAM TABLE
PROGRAM COMMENTS
START : MOV SI,1200H Initialize array
MOV CX,000FH Initialize array size
MOV AL,10 Store the control word for display mode
OUT C2,AL Send through output port
MOV AL,CC Store the control word to clear display
OUT C2,AL Send through output port
MOV AL,90 Store the control word to write display
OUT C2,AL Send through output port
L1 : MOV AL,[SI] Get the first data
OUT C0,AL Send through output port
CALL DELAY Give delay
INC SI Go & get next data
LOOP L1 Loop until all the data’s have been taken
JMP START Go to starting location
DELAY : MOV DX,0A0FFH Store 16bit count value
LOOP1 : DEC DX Decrement count value
JNZ LOOP1 Loop until count values becomes zero
RET Return to main program
LOOK-UP TABLE:
1200 98 68 7C C8
1204 FF 1C 29 FF
RESULT:
Thus the rolling message “HELP US” is displayed using 8279 interface kit.
47
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
PRINTER STATUS
EXP.NO:11 DATE:
AIM:
To display the Printer Status in the display
APPARATUS REQUIRED:
8086 Microprocessor kit, Power supply, interfacing board.
PROGRAM:
XOR AX, AX
XOR BX, BX
RESULT:
Thus the output for the Move a data block without overlap was executed successfully
48
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
49
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
50
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
51
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.
52
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
NO
IS EOC = 1?
YES
STOP
53
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
PROGRAM TABLE
PROGRAM COMMENTS
Thus the ADC was interfaced with 8086 and the given analog inputs were converted into its
digital equivalent.
54
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
55
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
FLOWCHART:
MEASUREMENT OF ANALOG VOLTAGE SQUARE WAVE FORM
START
START
INTIALISE THE
ACCUMULATOR SEND ACC
SEND THE CONTENT TO DAC
DIGITALVALUE TO
ACCUMULATOR
DELAY
TRANSFER THE
ACCUMULATOR LOAD THE ACC WITH MAX
CONTENTS TO DAC VALUE SEND ACC CONTENT
TO DAC
READ THE CORRESPONDING DELAY
ANALOG VALUE
SEND
ACCUMULATOR
CONTENT TO DAC
IS ACC
YES 00 NO
56
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
PROGRAM COMMENTS
57
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
RESULT:WAVEFORM GENERATION:
Square Waveform
Saw-tooth waveform
Triangular waveform
MODEL GRAPH:
Triangular waveform
Thus the DAC was interfaced with 8085 and different waveforms have been generated.
58
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
8 BIT ADDITION
AIM:
To write a program to add two 8-bit numbers using 8051 microcontroller.
ALGORITHM:
FLOW CHART:
START
Clear PSW
Select Register
Bank
Load A and R 0
with 8- bit datas
Add A & R 0
STOP
59
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
RESULT:
OUTPUT
MEMORY LOCATION DATA
4500
Thus the 8051 ALP for addition of two 8 bit numbers is executed.
60
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 I’ST
OPERAND IN
ACCR
SUBTRACT THE
2’ND OPERAND
FROM ACCR
N
IS CF=1
Y
INCREMENT
THE BORROW
REGISTER
STORE
RESULT IN
MEMORY
STOP
61
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
RESULT:
OUTPUT
MEMORY LOCATION DATA
4500
Thus the 8051 ALP for subtraction of two 8 bit numbers is executed.
62
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
63
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
8 Bit Multiplication
ADDRESS LABEL MNEMONIC OPERAND HEX COMMENTS
CODE
4100 MOV A ,#data1 74, data1 Store data1 in
accumulator
4102 MOV B, #data2 75,data2 Store data2 in B reg
RESULT:
INPUT OUTPUT
MEMORY LOCATION DATA MEMORY LOCATION DATA
4500 4502
4501 4503
Thus the 8051 ALP for multiplication of two 8 bit numbers is executed.
64
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
65
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
8 Bit Division
ADDRESS LABEL MNEMONIC OPERAND HEX COMMENTS
CODE
4100 MOV A, # data1 74,data1 Store data1 in
accumulator
4102 MOV B, # data2 75,data2 Store data2 in B reg
RESULT:
INPUT OUTPUT
MEMORY LOCATION DATA MEMORY LOCATION DATA
4500 (dividend) 4502 (remainder)
Thus the 8051 ALP for division of two 8 bit numbers is executed.
66
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
To write an ALP to perform logical and bit manipulation operations using 8051
microcontroller.
APPARATUS REQUIRED:
8051 microcontroller kit
ALGORITHM:
FLOWCHART:
START
STOP
67
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
PROGRAM TABLE
68
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
RESULT:
4502H (SCON) SM0 SM1 SM2 REN TB8 RB8 TI RI 0FH 20H
69
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
AIM:
To convert Square and Cube program, Find 2’s complement of a number using 8051
micro controller
RESOURCES REQUIERED:
8051 microcontroller kit
Keyboard
Power supply
PROGRAM:
org 0000h; sets the program counter to 0000h
mov a,#n;assign value 'n' in decimal to A which is converted to it's
equivalent hexadecimal value
mov b,#n;assign value 'n' in decimal to B which is converted to it's
equivalent hexadecimal value
mov r0,#n;assign value 'n' in decimal to R0 which is converted to it's
equivalent hexadecimal value
mul ab; multiplying 'A' with 'B'
mov 40h,a; lower byte is stored in address 40h
mov 41h,b; higher byte is stored in address 41h
mov r1,a; move value of 'A' to R1
mov a,b; move value of 'B' to 'A'
mov b,r0; move value of R0 to b
mul ab; multiply 'A' and 'B'
mov b,a; lower byte obtained is moved from 'A' to 'B'
mov r2,b; move value of 'B' to R2
mov a,r1; move value of R1 to 'A'
mov b,r0; move value of R0 to 'B'
mul ab; multiplying 'A' and 'B'
mov 50h,a; Lower byte obtained is stored in address 50h
70
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
71
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
AIM:
To convert BCD number into ASCII by using 8051 micro controller
RESOURCES REQUIERED:
8051 microcontroller kit
Keyboard
Power supply
72
CS6412 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF CSE
FLOWCHART:
RESULT:
The given number is converted into ASCII using 8051 microcontroller kit.
73