CE324 Lec7 IO Port Programming SP25
CE324 Lec7 IO Port Programming SP25
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
5
I/O port pins
6
Port 0
7
Port 0 (Contd)
8
Port 0 as an input
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
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
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
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
35
Read-Modify-Write feature
36
Read-Modify-Write feature (Contd)
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