You are on page 1of 16

MICROPROCESSOR AND MICROCONTROLLER

LABORATORY ASSIGNMENT

Addition of two 8 bit numbers using 8051 microcontroller


AIM:Addition of two 8 bit numbers using
8051microcontroller
ALGORITHM:
1. Clear C – register for Carry
2. Get the data immediately .
3. Add the two data
4. Store the result in memory pointed by
DPTR

PROGRAM:

MOVR0,#20H;set source address 20H to R0


MOVR1,#30H;set destination address 30H to R1
MOVA,@R0; take the value from source to register A

MOVR5,A; Move the value from A to R5


MOVR4,#00H; Clear register R4 to store carry
INCR0; Point to the next location
MOVA,@R0; take the value from source to register A
ADDA,R5;Add R5 with A and store to register A
JNC SAVE
INCR4; Increment R4 to get carry
MOVB,R4;Get carry to register B
MOV@R1,B; Store the carry first
INCR1; Increase R1 to point to the next address
SAVE: MOV@R1,A;Store the result
HALT: SJMP HALT ;Stop the program

MANUAL VERIFICATION
Input :
20H - 5FH
21H - D8H
30H - 00H
31H - 00H

Output:
20H - 5FH
21H - D8H
30H - 01H
31H - 37H
RESULT:
Addition of two 8 bit numbers using 8051
microcontroller is done succesfully.

Subtraction of two 8 – bit


numbers using 8051
AIM:
Subtraction of two 8 bit numbers using 8051
microcontroller
ALGORITHM:
1. Clear C – register for Carry
2. Get the data immediately .
3. Subtract the two data
4. Store the result in memory pointed by
DPTR

PROGRAM:

MOVR0,#20H;set source address

20H to R0

MOVR1,#30H;set destination

address 30H to R1

MOVA,@R0;take the value from

source to register A

MOVR5,A; Move the value from A to

R5

MOVR4,#00H; Clear register R4 to

store borrow

INCR0; Point to the next location


MOVA,@R0; take the value from

source to register A
MOVR3,A; store second byte
MOVA,R5;get back the first operand
SUBBA,R3; Subtract R3 from A

JNCSAVE
INCR4; Increment R4 to get borrow
MOVB,R4;Get borrow to register B
MOV@R1,B; Store the borrow first
INCR1; Increase R1 to point to the

next address

SAVE: MOV@R1,A; Store the result


HALT: SJMP HALT ;Stop the program

MANUAL VERIFICATION
Input :
20H - 73H
21H - BDH
30H - 00H
31H - 00H
Output:

20H - 73H
21H - BDH
30H - 01H
31H - B6H
RESULT:
Subtraction of two 8 bit numbers using 8051
microcontroller is done succesfully.

Multiplication of two 8 – bit


numbers using 8051
AIM:
Multiplication of two 8 bit numbers using 8051
microcontroller.
ALGORITHM:
1. Get the data in A – reg.
2. Get the value to be multiplied in B – reg.
3. Multiply the two data
4. The higher order of the result is in B – reg.
5. The lower order of the result is in A – reg.

6. Store the results.

PROGRAM:

MOV R0, #20H;set source address 20H to R0


MOV R1, #30H;set destination address 30H to R1

MOV A, @R0;take the first operand from source to register A


INCR0; Point to the next location
MOV B,@R0;take the second operand from source to register
B

MUL AB ;Multiply A and B


MOV @R1, B; Store higher order byte to 30H
INC R1; Increase R1 to point to the next location
MOV @R1, A;Store lower order byte to 31H
HALT: SJMP HALT ; Stop the program

MANUAL VERIFICATION
Input :

20H - FFH
21H - FFH
30H - 00H
31H - 00H
Output:
20H - FFH
21H - FFH
30H - FEH
31H - 01H
RESULT:
Multiplication of two 8 bit numbers using 8051
microcontroller is done succesfully.

Division of two 8 – bit

numbers using 8051


AIM:
Division of two 8 bit numbers using 8051
microcontroller
ALGORITHM:
1. Get the data in A – reg.
2. Get the value to be divided in B – reg.
3. Divide the two data
4. The quotient is in A – reg.
5. The remainder is in B – reg.
6. Store the results.

PROGRAM:

MOV R0, #20H;set source address 20H to R0


MOV R1, #30H;set destination address 30H to R1

MOV A, @R0;take the first operand from source to register A


INC R0; Point to the next location
MOV B, @R0; take the second operand from source to
register B

DIV AB ; Divide A by B

MOV @R1, A; Store Quotient to 30H


INC R1; Increase R1 to point to the next location
MOV @R1, B; Store Remainder to 31H
HALT: SJMP HALT ;Stop the program

MANUAL VERIFICATION
Input :
20H - 0EH
21H - 03H
30H - 00H
31H - 00H
Output:

20H - 0EH
21H - 03H

30H - 04H
31H - 02H
RESULT:
Division of two 8 bit numbers using 8051
microcontroller is done succesfully.

Interfacing stepper motor


with 8085, 8086, and 8051
AIM:
Interfacing stepper motor with 8085, 8086,
and 8051

PROGRAM(8051)
Main : MOV A,#0FF H ;
Initializationof Port 1
MOV P1, A ;
MOV A,#77 H ;
Codefor the Phase 1
MOV P1, A ;
ACALL DELAY ; Delay

subroutine
MOV A, #BB H ;
Codefor the Phase II
MOV P1,A ;
ACALL DELAY ;
Delay subroutine.
MOV A, #DD H ;
Codefor the Phase III
MOV P1, A ;
ACALL DELAY ;
Delaysubroutine
MOV A, #EE H ;
Code for the Phase 1
MOV P1,A ;
ACALL DELAY ;
Delay subroutine
SJMP MAIN; Keepthe motor rotating
continuously.
DELAY Subroutine
MOV R4, #0FF H
; Load R4 with FF
MOV R5, #0FF
; Load R5 with FF
LOOP1: DJNZ R4, LOOP1 ;
Decrement R4 until zero,wait
LOOP2: DJNZ R5, LOOP2 ;
Decrement R5 until zero,wait

RET ; Return to
main program .

PROGRAM(8085)
Main : MVI A, 80 ; 80H →Control word
to configure PA,PB,PC in O/P
OUT CWR_Address ;Write control word in CWR of
8255
MVIA,77 ; Codefor the Phase 1
OUT PortA_Address ; sent to motor via port A of
8255;
CALL DELAY ; Delay subroutine
MVIA, BB ; Codefor the Phase II
OUT PortA_Address ; sent to motor via port A of 8255
CALL DELAY ; Delay subroutine.
MVIA, DD ; Codefor the Phase III
OUT PortA_Address ; sent to motor via port A of 8255
;CALL DELAY ; Delaysubroutine
MVIA, EE H ; Code for the Phase 1
OUT PortA_Address ; sent to motor via port A of 8255;
CALL DELAY ; Delay subroutine
JMP MAIN ; Keepthe motor rotating
continuously.
DELAY Subroutine
MVIC, FF ;Load Cwith FF--
Change it for the speed variation
LOOP1: MVI D,FF ;Load Dwith FF
LOOP2: DCR D
JNZ LOOP2
DCR C
JNZ LOOP1
RET ; Return to main program
Interfacing to 8086 and programming to control
stepper motor.
1. To rotate stepper motor in clock direction
Program:
.OUTPUT 2500AD
;EQUATES
PORT_C .EQUAL FFC4H ;PORT C ADDRESS
CTL_PORT .EQUAL FFC6H ;CONTROL PORT ADDRESS
CTL_BYTE .EQUAL 80H ;CONTROL BYTE FOR C PORT
= ON
PHASE_A .EQUAL 0cH ;BYTE TO SWTICH ON A PHASE
PHASE_B .EQUAL 06H ;BYTE TO SWTICH ON B
PHASE
PHASE_C .EQUAL 03H ;BYTE TO SWTICH ON C
PHASE
PHASE_D .EQUAL 0DH ;BYTE TO SWTICH ON D
PHASE
DSEG SEGMENT
org 0000 : 3000H
DELAY_COUNT DW 0
DSEG ENDS
CSEG SEGMENT
ASSUME CS : CSEG, DS : DSEG
ORG 0000 : 4000H
;Start of Test Program
MOV AL, CTL_BYTE ;8255 INITIALISATION

MOV DX, CTL_PORT


OUT DX, AL ;
START:
MOV AL, PHASE_A ;PHASE A OF BOTH
MOTORS ON
MOV DX, PORT_C
OUT DX, AL
CALL DELAY1 ;DELAY BET.
SWITCHING OF PHASES
MOV AL, PHASE_C
MOV DX, PORT_C
OUT DX, AL ;PHASE B OF BOTH MOTORS
ON
CALL DELAY1 ;DELAY BET.
SWTICHING OF PHASES
MOV AL, PHASE_B
MOV DX, PORT_C
OUT DX, AL ;PHASE C OF BOTH MOTORS
ON
CALL DELAY1 ;DELAY BET.
SWTICHING OF PHASES

MOV AL, PHASE_D


MOV DX, PORT_C
OUT DX, AL ;PHASE D OF BOTH MOTORS
ON
CALL DELAY1 ;DELAY BET.
SWTCHING OF PHASES
JMP START ;PROGRAMS LOOPS FROM
HERE
;Delay subroutine
DELAY1: MOV CX, OFFSET DELAY_COUNT
DL1: LOOP DL1
RET
CSEG ENDS
.END
Result:
stepper motor is interfaced to 8086 and rotated
in clockwise direction.

2. To rotate stepper motor in


anticlockwise direction.
Program:

.OUTPUT 2500AD
; EQUATES
PORT_C .EQUAL FFC4H; PORT C
ADDRESS
CTL_PORT .EQUAL FFC6H; CONTROL
PORT ADDRESS
CTL_BYTE .EQUAL 80H ; CONTROL
BYTE FOR C PORT = ON
PHASE_A .EQUAL 0CH ; BYTE TO
SWTICH ON A PHASE
PHASE_B .EQUAL 06H ; BYTE TO
SWTICH ON B PHASE
PHASE_C .EQUAL 03H ; BYTE TO
SWTICH ON C PHASE
PHASE_D .EQUAL 0DH ;BYTE TO
SWTICH ON D PHASE
DSEG SEGMENT
org 0000 : 3000H
DELAY_COUNT DW 0
DSEG ENDS
; In a one-phase on scheme (anti
clockwise) half step
CSEG SEGMENT
ASSUME CS : CSEG, DS : DSEG

ORG 0000 : 4000H

;Start of Test Program

MOV AL, CTL_BYTE ;8255

INITIALISATION
MOV DX, CTL_PORT
OUT DX, AL

START: MOV AL, 77H


;PHASE_D ;PHASE A OF BOTH
MOTORS ON

MOV DX, PORT_C


OUT DX, AL
CALL DELAY1 ; DELAY BET.

SWITCHING OF PHASES
MOV AL, BBH ;PHASE_B
MOV DX, PORT_C

OUT DX, AL ;PHASE B OF


BOTH MOTORS ON

CALL DELAY
;DELAY BET. SWTICHING OF
PHASES

MOV AL, DDH ;PHASE_C


MOV DX, PORT_C
OUT DX, AL ;PHASE C OF
BOTH MOTORS ON

CALL DELAY1 ;DELAY BET.


SWTICHING OF PHASES
MOV AL, EEH ;PHASE_A
MOV DX, PORT_C
OUT DX, AL ;PHASE D OF
BOTH MOTORS ON
CALL DELAY1 ;DELAY
BET. SWTCHING OF PHASES

JMP STAR ;PROGRAMS


LOOPS FROM HERE

;Delay subroutine
DELAY1:

MOV CX, OFFSET


DELAY_COUNT
DL1: LOOP DL1

RET

CSEG ENDS

.END

Result:
stepper motor is interfaced to 8086 and
rotated in anticlockwise direction.

END RESULT:
Interfacing stepper motor with 8085, 8086,
and 8051 is done succesfully

You might also like