You are on page 1of 17

Electrical Engineering Department

Benha Faculty of Engineering


Benha University

Microprocessors and
Microcontrollers E1328
#Lecture_7
Dr. Mahmoud Adel Hassan,
Ph.D. Degree in Engineering Sciences in
Electrical Engineering,
Email: m_adel25@bhit.bu.edu.eg
# 8th Semester 2022/2023
Outline
➢Instruction Types
▪ Arithmetic Instructions.
▪ Logical Instructions.
▪ Boolean Instructions.

➢ Example ( Start/ Stop with Push Button)


Instruction Types
• Arithmetic Instructions

Since four addressing modes are possible, the ADD A instruction can be written in different way

ADD A,7PH (direct addressing)

ADD A,@R0 (indirect addressing)

ADD A,R7 (register addressing)

ADD A,#35H (immediate addressing)


ADD Res : 101101101
Carry : 1
Result: 101101110
Example : Illustrate how to add two 4-digit binary-coded decimal numbers. The first is in internal
memory locations 40H and 41H, and the second is in locations 42H and 43H. The most significant
digits are in locations 40H and 42H. Place the BCD result in locations 40H and 41H.

Solution
MOVA,41H

ADDA,43H

DAA

MOV41H,A

MOVA,42H

ADDCA,40H

DAA

MOV40H,A
• Logical Instructions

01010011
00010001
00010001
• Boolean Instructions

SETB P1.7 , CLR Pl.7


Example
Using Microcontroller 8051 design a control circuit to start and stop a
LED with using two push buttons normally open.

What will be added if we need to replace the LED with DC Motor?


Hardware wiring

C1
U1
19 39
XTAL1 P0.0/AD0
22p 38
P0.1/AD1
X1 P0.2/AD2
37
CRYSTAL 18 36
C2 XTAL2 P0.3/AD3
35
P0.4/AD4
34
P0.5/AD5
33
P0.6/AD6
22p 9 32
RST P0.7/AD7
21
P2.0/A8
22
P2.1/A9
VCC 23
P2.2/A10
29 24
PSEN P2.3/A11
30 25
ALE P2.4/A12
31 26
EA P2.5/A13
27
Start P2.6/A14
P2.7/A15
28

1 10
P1.0 P3.0/RXD
C3 2
P1.1 P3.1/TXD
11
1u 3 12
P1.2 P3.2/INT0
4 13
P1.3 P3.3/INT1
5 14
P1.4 P3.4/T0
6 15
P1.5 P3.5/T1
Stop 7
8
P1.6
P1.7
P3.6/WR
P3.7/RD
16
17
R1
8k2 AT89C51

D1
LED-RED

GND
Flowchart Start

Identify
I/O pins

N Start PB
is pressed

Y Start PB N
is pressed

Motor Motor
Stop Run
Software Program
org 00h L2: JB P1.1,Run
setb P1.0 clr P1.2
setb P1.1 sjmp L1
clr P1.2 Run: setb P1.2
L1: jnb P1.0,L2 sjmp L2
sjmp L1 end
After pressing on start PB
C1
U1
19 39
XTAL1 P0.0/AD0
22p 38
P0.1/AD1
X1 P0.2/AD2
37
CRYSTAL 18 36
C2 XTAL2 P0.3/AD3
35
P0.4/AD4
34
P0.5/AD5
33
P0.6/AD6
22p 9 32
RST P0.7/AD7
21
P2.0/A8
22
P2.1/A9
VCC 23
P2.2/A10
29 24
PSEN P2.3/A11
30 25
ALE P2.4/A12
31 26
EA P2.5/A13
27
P2.6/A14
28
Start
P2.7/A15
1 10
P1.0 P3.0/RXD
C3 2
P1.1 P3.1/TXD
11
1u 3 12
P1.2 P3.2/INT0
4 13
P1.3 P3.3/INT1
5 14
P1.4 P3.4/T0
6 15
P1.5 P3.5/T1
Stop 7
8
P1.6 P3.6/WR
16
17
P1.7 P3.7/RD
R1
8k2 AT89C51

D1
LED-RED

GND
After pressing on Stop PB

C1
U1
19 39
XTAL1 P0.0/AD0
22p 38
P0.1/AD1
X1 P0.2/AD2
37
CRYSTAL 18 36
C2 XTAL2 P0.3/AD3
35
P0.4/AD4
34
P0.5/AD5
33
P0.6/AD6
22p 9 32
RST P0.7/AD7
21
P2.0/A8
22
P2.1/A9
VCC 23
P2.2/A10
29 24
PSEN P2.3/A11
30 25
ALE P2.4/A12
31 26
EA P2.5/A13
27
P2.6/A14
Start P2.7/A15
28

1 10
P1.0 P3.0/RXD
C3 2
P1.1 P3.1/TXD
11
1u 3 12
P1.2 P3.2/INT0
4 13
P1.3 P3.3/INT1
5 14
P1.4 P3.4/T0
6 15
Stop 7
8
P1.5
P1.6
P3.5/T1
P3.6/WR
16
17
P1.7 P3.7/RD
R1
8k2 AT89C51

D1
LED-RED

GND
After adding DC Motor
Vm
C1
U1
19 39
XTAL1 P0.0/AD0
22p 38
P0.1/AD1
X1 P0.2/AD2
37
CRYSTAL 18 36
C2 XTAL2 P0.3/AD3
35
P0.4/AD4
34 12VDC
P0.5/AD5
33
P0.6/AD6
22p 9 32
RST P0.7/AD7
21
P2.0/A8
22
P2.1/A9
VCC 23
P2.2/A10
29 24
PSEN P2.3/A11
30 25
ALE P2.4/A12
31 26
EA P2.5/A13
27
Start P2.6/A14
P2.7/A15
28

1 10
P1.0 P3.0/RXD
C3 2
P1.1 P3.1/TXD
11 RL1
1u 3 12 OMI-SH-105D
P1.2 P3.2/INT0
4 13
P1.3 P3.3/INT1
5 14
P1.4 P3.4/T0
6 15
Stop 7
8
P1.5
P1.6
P3.5/T1
P3.6/WR
16
17
P1.7 P3.7/RD
R1
8k2 AT89C51

R2 Q1
2N2222
10k

GND

GND1

You might also like