Вы находитесь на странице: 1из 36

CHAPTER 5_PART 2

muthmainnah

FACULTY OF MECHANICAL
ENGINEERING

CHAPTER 5: MICROPROCESSOR
SYSTEMS & APPLICATIONS
MEC523
APPLIED ELECTRONICS &
MICROPROCESSOR
Prepared by Nurul Muthmainnah Mohd
Noor

SLIDE 1

1
CHAPTER 5_PART 2
muthmainnah

DIGITAL LOGIC CIRCUITS

Part 1

5.1 Microprocessor architecture and overview.


5.2 Assembly Language programming.

Part 2

5.3 I/O Port programming.


Lecturer: Nurul Muthmainnah Mohd Noor
5.4 Addressing Mode.
Room: A14-6C, Bangunan 1, Kompleks Kejuruteraan,
Phone: 03-55442982
Email: nurul.muth@gmail.com

SLIDE 2

2
CHAPTER 5_PART 2
muthmainnah

PART 2
5.3 I/O Port programming.
5.4 Addressing Mode.

SLIDE 3

3
CHAPTER 5_PART 2
muthmainnah

COURSE OUTCOME

Upon completion of this course, students should be able


to:

CO3 Develop program code based on microprocessor for


engineering application. [PO3, LO3, SS1]{C5}.

SLIDE 4

4
CHAPTER 5_PART 2
muthmainnah

Objectives

◦ To differentiate between
microprocessor and microcontroller
◦ To know the family 8051
◦ To understand and assembly the
programming of 8051

SLIDE 5

5
CHAPTER 5_PART 2
muthmainnah

I/O PORT
PROGRAMMING

SLIDE 6

6
CHAPTER 5_PART 2
muthmainnah

I/O PROGRAMMING

SLIDE 7

7
CHAPTER 5_PART 2
muthmainnah

I/O Port Pins


The most widely used registers

A (Accumulator)
All the
For ports uponand
all arithmetic RESET
logicare configured as input, ready to be used as
instructions
input ports
B, R0, R1, R2,- When theR5,
R3, R4, firstR6,
0 is written
R7 to a port, it becomes an output

DPTR (data- pointer),


To reconfigure it as an input, a 1 must be sent to the port
and PC (program counter)
To use any of these ports as an input port, it must be
programmed

SLIDE 8

8
CHAPTER 5_PART 2
muthmainnah

Port 0
It can be used for input or
output, each pin must be
connected externally to a 10K
ohm pull-up resistor

SLIDE 9

9
CHAPTER 5_PART 2
muthmainnah

Port 0

SLIDE 10

10
CHAPTER 5_PART 2
muthmainnah

Port 0 as Input
Value (proceeded with #) can be loaded directly to
registers A, B, or R0 – R7

SLIDE 11

11
CHAPTER 5_PART 2
muthmainnah

Dual Role of Port 0


Port 0 is also designated as AD0-AD7, allowing it to be
used for both address and data

When connecting an 8051/31 to an external memory,


port 0 provides both address and data

SLIDE 12

12
CHAPTER 5_PART 2
muthmainnah

Port 1
Port 1 can be used as input or output
◦ In contrast to port 0, this port
does not need any pull-up
resistors since it already has
pull-up resistors internally
◦ Upon reset, port 1 is
configured as an input port

SLIDE 13

13
CHAPTER 5_PART 2
muthmainnah

Port 1 as Input

SLIDE 14

14
CHAPTER 5_PART 2
muthmainnah

Port 2
Port 2 can be used as input or output

Just like P1, port 2 does not need any pullup


resistors since it already has pull-up resistors
internally
Upon reset, port 2 is configured as an input port

SLIDE 15

15
CHAPTER 5_PART 2
muthmainnah

Port 2 as Input or Dual Role


To make port 2 an input port, it must be programmed as such
by writing 1 to all its bits
In many 8051-based system, P2 is used as simple I/O
In 8031-based systems, port 2 must be used along with P0 to
provide the 16- bit address for the external memory
* Port 2 is also designated as A8 – A15, indicating its dual
function
* Port 0 provides the lower 8 bits via A0 – A7

SLIDE 16

16
CHAPTER 5_PART 2
muthmainnah

Port 3
Port 3 can be used as input or output
* Port 3 does not need any pull-up
resistors
* Port 3 is configured as an input port
upon reset, this is not the way it is
most commonly used
* Port 3 has the additional function of
providing some extremely important
signals

SLIDE 17

17
CHAPTER 5_PART 2
muthmainnah

Port 3

SLIDE 18

18
CHAPTER 5_PART 2
muthmainnah

Different ways of Accessing Entire 8 Bits

SLIDE 19

19
CHAPTER 5_PART 2
muthmainnah

I/O Ports and Bit Addressability


Sometimes we need to access
only 1 or 2 bits of the port

SLIDE 20

20
CHAPTER 5_PART 2
muthmainnah

I/O Ports and Bit Addressability

SLIDE 21

21
CHAPTER 5_PART 2
muthmainnah

ADDRESSING
MODES

SLIDE 22

22
CHAPTER 5_PART 2
muthmainnah

IMMEDIATE ADDRESSING MODE


The source operand is a constant

* The immediate data must be preceded by the pound sign, “#”


* Can load information into any registers, including 16-bit DPTR register
- DPTR can also be accessed as two 8-bit registers, the high byte DPH and low
byte DPL

SLIDE 23

23
CHAPTER 5_PART 2
muthmainnah

REGISTER ADDRESSING MODE


Use registers to hold the data to
be manipulated

The movement of data between Rn


registers is not allowed
MOV R4,R7 is invalid
The source and destination registers must
match in size
MOV DPTR,A will give an error

SLIDE 24

24
CHAPTER 5_PART 2
muthmainnah

ACCESSING MEMORY
Use registers to hold the data to
be manipulated
It is most often used the direct addressing mode to
access RAM locations 30 – 7FH
The entire 128 bytes of RAM can be accessed
The register bank locations are accessed by the
register names

SLIDE 25

25
CHAPTER 5_PART 2
muthmainnah

ACCESSING MEMORY
Contrast this with immediate addressing mode

There is no “#” sign in the operand

SLIDE 26

26
CHAPTER 5_PART 2
muthmainnah

SFR Registers and Their Addresses


The SFR (Special Function Register) can be accessed by their names or
by their addresses

The SFR registers have addresses between 80H and FFH


Not all the address space of 80 to FF is used by SFR
The unused locations 80H to FFH are reserved and must not be used
by the 8051 programmer

SLIDE 27

27
CHAPTER 5_PART 2
muthmainnah

SFR Registers and Their Addresses

SLIDE 28

28
CHAPTER 5_PART 2
muthmainnah

Stack and Direct Addressing Mode

Only direct addressing mode is


allowed for pushing or popping the
stack
PUSH A is invalid
Pushing the accumulator onto
the stack must be coded as PUSH
0E0H

SLIDE 29

29
CHAPTER 5_PART 2
muthmainnah

Register Indirect Addressing Mode


A register is used as a pointer to the data

Only register R0 and R1 are used for this purpose


R2 – R7 cannot be used to hold the address of an operand located in RAM

When R0 and R1 hold the addresses of RAM locations, they must be preceded by the
“@” sign

SLIDE 30

30
CHAPTER 5_PART 2
muthmainnah

Register Indirect Addressing Mode

SLIDE 31

31
CHAPTER 5_PART 2
muthmainnah

Register Indirect Addressing Mode


The advantage is that it makes accessing data dynamic rather than static as in direct
addressing mode
Looping is not possible in direct addressing mode

SLIDE 32

32
CHAPTER 5_PART 2
muthmainnah

Register Indirect Addressing Mode


◦ R0 and R1 are the only registers that can be used for pointers in
register indirect addressing mode
◦ Since R0 and R1 are 8 bits wide, their use is limited to access any
information in the internal RAM
◦ Whether accessing externally connected RAM or on-chip ROM, we
need 16-bit pointer
In such case, the DPTR register is used

SLIDE 33

33
CHAPTER 5_PART 2
muthmainnah

Indexed Addressing Mode and On-chip ROM Access


◦ Indexed addressing mode is widely used in accessing data
elements of look-up table entries located in the program
ROM
◦ The instruction used for this purpose is MOVC
A,@A+DPTR
- Use instruction MOVC, “C” means code

- The contents of A are added to the 16-bit register DPTR to


form the 16-bit address of the needed data

SLIDE 34

34
CHAPTER 5_PART 2
muthmainnah

Indexed Addressing Mode and On-chip ROM Access

SLIDE 35

35
CHAPTER 5_PART 2
muthmainnah

END of PART 2
Let's do exercises

SLIDE 36

36

Вам также может понравиться