Sie sind auf Seite 1von 29

MICROPROCESSORS & MICROCONTROLLERS

LABORATORY (CSE) MANUAL


Prepared by
SYED.SHAMEEM Assoc.prof[ECE],
(COURSE COORDINATOR)

SCHOOL OF ELECTRICAL SCIENCES

KONERU LAKSHMAIAH UNIVERSITY


2014-15.

List of Experiments
1. Programs Involving Arithmetic Instructions to
a. Addition, Subtraction, Multiplication and Division of 8-bit data
b. Addition of array of elements of 8-bit data
2. Programs Involving Bit Manipulations to
a. Toggle a LED with random delay (using Set, Clear and Complement)
b. Creating Patterns using 8 LED's
c. Display Numbers using 7-Segment Display
3. Programs involving Study of 8051 Timer/Counter operation
4. Program to Interface 8051 to LCD Display
5. Program to receive data from keyboard and print on display using 8086 interrupts
Experiments to be done in open labs
1. Interfacing A/D & D/A to 8051.
2. Interfacing of Binary Counter 8051
3. Interfacing Stepper Motor 8051/8086.
4. Data Transfer between two PCs using RS.232 C Serial Port.
Softwares used: Keil-uV4, proteus 8 professional

1) Programming Arithmetic using 8051 Microcontroller


a)Addition
org 00h
ljmp start
org 100h
start:
mov dptr,#num2 ; Load Address of Second Operand
clr a
movc a,@a+dptr ; Load the value stored in Address available in DPTR
mov b,a ; Create a backup of a as we need to replace it with next value
mov dptr,#num1 ; Load Address of First Operand
clr a
movc a,@a+dptr ; Load the value stored in Address available in DPTR
add a,b ; Adds contents of a,b and stores it in a
here: sjmp here
org 200h
num1: db 25h
num2: db 30h
end
Output:

Inputs: Num1=25h
Num2=30h
Result: The addition of two 8-bit numbers is performed and the result found in A Register.

1b)Subtraction
org 00h
ljmp start
org 100h
start:
mov dptr,#num2
clr a
movc a,@a+dptr
mov b,a
mov dptr,#num1
clr a
movc a,@a+dptr
subb a,b ; Does a-b-Carry and stores in a
here: sjmp here
org 200h
num1: db 25h
num2: db 30h
5

end
Output:

Inputs: Num1=25h
Num2=30h
Result: The subtraction of two 8-bit numbers is performed and the result found in A Register.

1c)Programming Arithmetic using 8051 Microcontroller


Multiplication
org 00h
ljmp start
org 100h
start:
mov dptr,#num2
clr a
movc a,@a+dptr
mov b,a
mov dptr,#num1
clr a
movc a,@a+dptr
6

mul ab ; Does a*b , Stores Lower byte in a, Higher byte in b (8 bit mul may result 16 bit
output)
here: sjmp here
org 200h
num1: db 5h
num2: db 3h
end
Output:

Inputs: Num1=3Bh
Num2=20h
Result: The multiplication of two 8-bit numbers is performed and the result is 16-bit,the Lower byte
in stored in A register, Higher byte in B register .

1d)Division
org 00h
ljmp start
org 100h
start:
mov dptr,#num2
clr a
movc a,@a+dptr
mov b,a
7

mov dptr,#num1
clr a
movc a,@a+dptr
div ab ; Does a/b , Quotient stored in a, Remainder in b
here: sjmp here
org 200h
num1: db 5h
num2: db 3h
end
Output:

Inputs: Num1=4Ch
Num2=31h
Result: The division of two 8-bit numbers is performed and the Quotient is stored in A register,

Remainder in B register.

Programming Arithmetic using 8051 Microcontroller


1e)Addition of Array of Numbers
org 00h
ljmp start ; Upon Reset the following line is executed, program shifts to "start" Label
org 100h
8

start:
mov b,#00h
mov dptr,#num1 ; Loading Address of array
back:
clr a
movc a,@a+dptr ; Loading the value stored in address available in dptr
inc dptr
cjne a,#'$',next ; Compares a with $ and if not equal moves to label "next"
sjmp here ; If compare results equal move to label "here"
next:
add a,b
mov b,a ; Backup of a, as new value is to be loaded into a
sjmp back ; Repeat the operation from "back"
here:
sjmp here ; Wait here
org 200h
num1: db 1h,2h,3h,4h,5h,'$' ; $ is used in this case as end of array, Anything can be used
end
Output:

Input: array values: 1h,2h,3h,4h,5h


Result: The addition of array elements is performed and the result was found in B register.

2a)Bit Manipulation Programs


Aim:To Perform bit manipulation programs
9

Software Used:
Keil uVision4
Program:
a) Toggling Pin
clr p1.0
back:setb p1.0
acall delay
clr p1.0
acall delay
sjmp back
delay: mov r0,#5d
here1:mov r1,#2d
here:djnz r1,here
djnz r0,here1
ret
end
Output:

Toggling pin:

After some delay

After some delay

RESULT: The toggling of pin p1.0 is performed.

2b) Toggling Port


10

mov p1,#00h
mov a,#55h
back:mov p1,a
acall delay
cpl a
sjmp back
delay: mov r0,#5d
here1:mov r1,#2d
here:djnz r1,here
djnz r0,here1
ret
end
Output:

Toggling port:

After some delay

After some delay

RESULT: The toggling of port1 is performed.


Bit Manipulation Programs
2c) Pattern Generation(Sending values individually)
mov p1,#00h
back:mov p1,#01h
acall delay
mov p1,#03h
acall delay
mov p1,#07h
acall delay
mov p1,#0Fh
11

acall delay
mov p1,#1Fh
acall delay
mov p1,#3Fh
acall delay
mov p1,#7Fh
acall delay
mov p1,#0FFh
acall delay
mov p1,#7Fh
acall delay
mov p1,#3Fh
acall delay
mov p1,#1Fh
acall delay
mov p1,#0Fh
acall delay
mov p1,#07h
acall delay
mov p1,#03h
acall delay
mov p1,#01h
acall delay
mov p1,#00h
acall delay
sjmp back
delay: mov r0,#5d
here1:mov r1,#2d
here:djnz r1,here
djnz r0,here1
ret
end
Output:

Pattern generation:

12

13

14

Result: The pattern is generated in port1 from right to left.


Bit Manipulation Programs
2d) Pattern Generation using Rotate Instruction
mov p1,#00h
back:clr a
lsbtomsb: acall delay
setb c
mov p1,a
rlc a
cjne a,#0FFh,lsbtomsb
mov a,#0FFh
msbtolsb: acall delay
clr c
mov p1,a
rrc a
cjne a,#00h,msbtolsb
sjmp back
delay: mov r0,#5d
here1:mov r1,#2d
here:djnz r1,here
djnz r0,here1
ret
end
e) 7 Segment Display(Sending values individually)
mov p1,#00h
back:
mov a,#00111111b ; Display 0
mov p1,a
acall delay
mov a,#00000110b ; Display 1
mov p1,a
acall delay
mov a,#01011011b ; Display 2
15

mov p1,a
acall delay
mov a,#01001111b ; Display 3
mov p1,a
acall delay
mov a,#01100110b ; Display 4
mov p1,a
acall delay
Bit Manipulation Programs
mov a,#01101101b ; Display 5
mov p1,a
acall delay
mov a,#01111101b ; Display 6
mov p1,a
acall delay
mov a,#00000111b ; Display 7
mov p1,a
acall delay
mov a,#01111111b ; Display 8
mov p1,a
acall delay
mov a,#01101111b ; Display 9
mov p1,a
acall delay
sjmp back
delay: mov r0,#5d
here1:mov r1,#2d
here:djnz r1,here
djnz r0,here1
ret
end
2e) 7 Segment Display(using Dptr and Lookup Table)
mov p1,#00h
main:
mov dptr,#codes
back: clr a
movc a,@a+dptr
jz next
mov p1,a
acall delay
inc dptr
sjmp back
next: sjmp main
delay: mov r0,#5d
here1:mov r1,#2d
here:djnz r1,here
16

djnz r0,here1
ret
codes: db 3Fh,06h,5Bh,4Fh,66h,6Dh,7Dh,07h,7Fh,6Fh,0
end
Result: Bit manipulation programs are performed

7-segment LED display


mov p1,#00h
back:
mov a,#00111111b ; Display 0
mov p1,a
acall delay
mov a,#00000110b ; Display 1
mov p1,a
acall delay
mov a,#01011011b ; Display 2
mov p1,a
acall delay
mov a,#01001111b ; Display 3
mov p1,a
acall delay
mov a,#01100110b ; Display 4
mov p1,a
acall delay
mov a,#01101101b ; Display 5
mov p1,a
acall delay
mov a,#01111101b
mov p1,a
acall delay
mov a,#00000111b
mov p1,a
acall delay
mov a,#01111111b
mov p1,a
acall delay
mov a,#01101111b
mov p1,a
acall delay
sjmp back
delay: mov r0,#5d
here1:mov r1,#2d
here:djnz r1,here
djnz r0,here1
ret
end

; Display 6

; Display 7

; Display 8

; Display 9

7segment display: Output:


17

Result: The numbers from 0 to 9 are displayed on 7-segment display.


3.)Programming involving Timer/Counter operation:
ORG 00H
RPT: MOV TMOD,#15H
SETB P3.4
MOV TL0,#00H
MOV TH0,#00H
SETB TR0
MOV R0,#28
AGAIN:

MOV TL1,#00H

MOV TH1,#00H
SETB TR1
BACK:

JNB TF1,BACK

CLR TF1
CLR TR1
DJNZ R0,AGAIN
MOV A,TL0
18

MOV P2,A
MOV A,TH0
MOV P1,A
SJMP RPT
END
Counter : Output:

Result: The pin p3.4 is pressed for 2 times in a second.(counter value is 2 with in an second)

4.)Program to interface 8051 to LCD:


ORG 0H
MOV A,#38H
ACALL CMD
ACALL DELAY
MOV A,#0EH
19

ACALL CMD
ACALL DELAY
MOV A,#01H
ACALL CMD
ACALL DELAY
MOV A,#06H
ACALL CMD
ACALL DELAY
MOV A,#80H
ACALL CMD
ACALL DELAY
MOV A,#1CH
ACALL CMD
ACALL DELAY
MOV A,#'0'
ACALL DUMP
ACALL DELAY
MOV A,#'1'
ACALL DUMP
ACALL DELAY
MOV A,#'2'
ACALL DUMP
ACALL DELAY
MOV A,#'3'
ACALL DUMP
ACALL DELAY
MOV A,#'4'
ACALL DUMP
ACALL DELAY
20

MOV A,#'5'
ACALL DUMP
ACALL DELAY
MOV A,#'6'
ACALL DUMP
ACALL DELAY
MOV A,#'7'
ACALL DUMP
ACALL DELAY
MOV A,#'8'
ACALL DUMP
ACALL DELAY
MOV A,#'9'
ACALL DUMP
ACALL DELAY
MOV A,#'A'
ACALL DUMP
ACALL DELAY
MOV A,#'B'
ACALL DUMP
ACALL DELAY
MOV A,#'C'
ACALL DUMP
ACALL DELAY
MOV A,#'D'
ACALL DUMP
ACALL DELAY
MOV A,#'E'
ACALL DUMP
21

ACALL DELAY
MOV A,#'F'
ACALL DUMP
ACALL DELAY
MOV A,#0C0H
ACALL CMD
ACALL DELAY
MOV A,#07H
ACALL CMD
ACALL DELAY
MOV A,#'0'
ACALL DUMP
ACALL DELAY
MOV A,#'1'
ACALL DUMP
ACALL DELAY
MOV A,#'2'
ACALL DUMP
ACALL DELAY
MOV A,#'3'
ACALL DUMP
ACALL DELAY
MOV A,#'4'
ACALL DUMP
ACALL DELAY
MOV A,#'5'
ACALL DUMP
ACALL DELAY
MOV A,#'6'
22

ACALL DUMP
ACALL DELAY
MOV A,#'7'
ACALL DUMP
ACALL DELAY
MOV A,#'8'
ACALL DUMP
ACALL DELAY
MOV A,#'9'
ACALL DUMP
ACALL DELAY
MOV A,#'A'
ACALL DUMP
ACALL DELAY
MOV A,#'B'
ACALL DUMP
ACALL DELAY
MOV A,#'C'
ACALL DUMP
ACALL DELAY
MOV A,#'D'
ACALL DUMP
ACALL DELAY
MOV A,#'E'
ACALL DUMP
ACALL DELAY
MOV A,#'F'
ACALL DUMP
ACALL DELAY
23

AGAIN: SJMP AGAIN


CMD: MOV P3,A
CLR P2.0
CLR P2.1
SETB P2.2
ACALL DELAY
CLR P2.2
RET

DUMP: MOV P3,A


SETB P2.0
CLR P2.1
SETB P2.2
ACALL DELAY
CLR P2.2
RET

DELAY: MOV R3,#255


LOOP2: MOV R4,#255
LOOP1: DJNZ R4,LOOP1
DJNZ R3,LOOP2
RET
END

24

Output:

Result : the numbers and letters are displayed in LCD.

5. Program to receive data from keyboard and print on display


ORG 0H
;; lcd initialize program
MOV R0,#00H

; COUNTER

MOV A,#38H
ACALL CMD
ACALL DELAY
25

MOV A,#0EH
ACALL CMD
ACALL DELAY
MOV A,#01H
ACALL CMD
ACALL DELAY
MOV A,#06H
ACALL CMD
ACALL DELAY
GO:

MOV A,#80H
ACALL CMD
ACALL DELAY
;; keypad program starts
MOV P3,#0FFH

K1:

MOV P1,#0
MOV A,P3
ANL A,#00001111B
CJNE A,#00001111B,K1

K2:

ACALL DELAY
MOV A,P3
ANL A,#00001111B
CJNE A,#00001111B,OVER
SJMP K2

OVER:

ACALL DELAY
MOV A,P3
ANL A,#00001111B
CJNE A,#00001111B,OVER1
SJMP K2

OVER1: MOV P1,#11111110B


26

MOV A,P3
ANL A,#00001111B
CJNE A,#00001111B, ROW0
MOV P1,#11111101B
MOV A,P3
ANL A,#00001111B
CJNE A,#00001111B, ROW1
MOV P1,#11111011B
MOV A,P3
ANL A,#00001111B
CJNE A,#00001111B, ROW2
MOV P1,#11110111B
MOV A,P3
ANL A,#00001111B
CJNE A,#00001111B, ROW3
LJMP K2
ROW0: MOV DPTR,#KCODE0
SJMP FIND
ROW1: MOV DPTR,#KCODE1
SJMP FIND
ROW2: MOV DPTR,#KCODE2
SJMP FIND
ROW3: MOV DPTR,#KCODE3
SJMP FIND
FIND:

RRC A
JNC MATCH
INC DPTR
SJMP FIND

MATCH: CLR A
27

MOVC A,@A+DPTR
MOV P2,A
ACALL DUMP
ACALL DELAY
INC R0
CJNE R0,#10H,LAST
MOV A,#0C0H
ACALL CMD
ACALL DELAY

LAST:

LJMP K1

CMD:

MOV P2,A
CLR P0.0
CLR P0.1
SETB P0.2
ACALL DELAY
CLR P0.2
RET

DUMP: MOV P2,A


SETB P0.0
CLR P0.1
SETB P0.2
ACALL DELAY
CLR P0.2
RET

DELAY: MOV R3,#0FH


28

LOOP2: MOV R4,#0FH


LOOP1: DJNZ R4,LOOP1
DJNZ R3,LOOP2
RET

ORG 0300H
KCODE0:

DB '3','2','1','0' ;ROW0

KCODE1:

DB '7','6','5','4' ;ROW1

KCODE2:

DB 'B','A','9','8'

;ROW2

KCODE3:

DB 'F','E','D','C'

;ROW3

END

Output:

Result: Keyboard interfacing is done and the keys pressed are displayed on LCD.

29

Das könnte Ihnen auch gefallen