Beruflich Dokumente
Kultur Dokumente
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
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.
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.
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:
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:
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:
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
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
; Display 6
; Display 7
; Display 8
; Display 9
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)
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
24
Output:
; 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
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
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