0% found this document useful (0 votes)
6 views39 pages

CE324 Lec7 IO Port Programming SP25

This chapter covers the I/O ports of the 8051 microcontroller, detailing the four ports (P0, P1, P2, and P3) and their functionalities, including bit-addressability. It explains the dual roles of ports, particularly P0 and P2, and provides examples of assembly language coding for input and output operations. Additionally, it discusses the Read-Modify-Write feature and the configuration of ports upon reset.

Uploaded by

BeastX
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views39 pages

CE324 Lec7 IO Port Programming SP25

This chapter covers the I/O ports of the 8051 microcontroller, detailing the four ports (P0, P1, P2, and P3) and their functionalities, including bit-addressability. It explains the dual roles of ports, particularly P0 and P2, and provides examples of assembly language coding for input and output operations. Additionally, it discusses the Read-Modify-Write feature and the configuration of ports upon reset.

Uploaded by

BeastX
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

C E 3 2 4 : M I C R O P R O C E S S O R I N T E R FA C I N G

1
Objectives
After completing this chapter of the book, you would be able to:
List the four ports of the 8051
Describe the dual role of port 0 in providing both data and addresses
Code Assembly language to use the ports for input or output
Explain the dual role of port 0 and port 2
Code I/O bit manipulation programs for the 8051

2
Outlines
8051 I/O programming
I/O bit manipulation programming

3
8051 I/O programming
I/O access using byte-size data is discussed in this section

4
I/O programming

• 32 out of the 40 pins


set aside for the four
I/O ports that are
discussed here
• The rest of the pins
are discussed later

5
I/O port pins

6
Port 0

7
Port 0 (Contd)

By sending 55H (01010101) and AAH (10101010)


continuously, we toggle all the bits of port 0

8
Port 0 as an input

Note that port 0 is configured as an input by


default on power up

9
Dual role of port 0

10
Port 1

11
Port 1 as input

12
Port 2

13
Port 2 as input or dual role

14
Port 3: Introduction
From the discussion so far, we can conclude that
in systems based on 8751, 89C51 or DS589C4x0
microcontrollers, we have three ports P0, P1 and
P2 for I/O operations
This should be enough for most microcontroller
applications which leaves the port 3 for interrupts
as well as other signals

15
Port 3

16
Port 3 (Contd)

17
Example 4-1

• Crystal frequency of
11.0592 MHz considered
which corresponds to a
clock duration of 90ns

• Mind that the maximum


value taken by any
register is 255 and we use
nested loops to induce
greater delay (depending
on the MC and clk)

18
Different ways of accessing the
entire 8 bits

19
Ports status upon reset
Upon reset, all ports have the value FFH as tabulated below
This makes them input ports upon reset

Register Reset value (binary)


P0 11111111
P1 11111111
P2 11111111
P3 11111111

20
I/O bit manipulation
programming
A discussion on bit manipulation of the I/O ports in 8051 is
performed i.e. all the I/O ports are bit-addressable

21
I/O ports and bits addressability

22
Example 4-2

23
Single-bit instructions

24
Checking an input bit

CY – Carry flag bit


of the PSW reg to
indicate carry out
from the D7 bit

25
Example 4-3: Checking an input bit

26
Example 4-4: Checking an input bit

27
Example 4-5: Checking an input bit

28
Example 4-5: Checking an input bit

29
Example 4-6: Reading single bit into
carry flag

30
Example 4-6: Reading single bit into
carry flag

31
Example 4-6: Reading single bit into
carry flag

32
Reading input pins vs. port latch

33
Instructions for reading input
ports
As stated earlier, to make any bit of 8051
port an input, we need to write 1 (logic
HIGH) to that bit e.g. SETB P0.1
After the port bits are configured as input,
we can only use certain instructions to get
the external data present at the pins into the
CPU

34
Reading latch for output port

Instructions reading the port latch normally read a value, perform an


operation and rewrite it back to the port latch – “Read-Modify-Write”

35
Read-Modify-Write feature

36
Read-Modify-Write feature (Contd)

55H ⨁ FFH = 10101010 i.e. AAH

37
Summary
This chapter focused on the I/O ports of 8051
The four ports i.e. P0, P1, P2 and P3 are all bit-addressable
and can be used for input or output
P0 can be used for either address or data while P3 provides
different signals e.g. interrupts and serial communication
signals
The I/O instructions of 8051 were explained and numerous
examples were solved as well
We also showed the bit-addressability of 8051 ports

38
Next time

39

You might also like