2. What is I/O Operation ?
I/O operation defined as a set of collection of end users where
microprocessor or microcontroller read and write data and communicate
each other.
Every microcontroller I/O operation or programming are different. We will
see there 8051 microcontroller I/O programming.
This is actually figure of I/O programming.
There was various I/O commands go to I/O
devices and fetch data from memory either it
Is read operation either write operation.
3. 8051 Microcontroller !
In 8051, I/O operations are done using four ports and 40 pins. The following pin diagram
shows the details of the 40 pins. I/O operation port reserves 32 pins where each port has 8
pins. The other 8 pins are designated as 𝑽𝒄𝒄
There are four port name as 𝑷𝟎, 𝑷𝟏, 𝑷𝟐 and 𝑷𝟑.
Each port has 8-pins so 4 port has 32-pins.
We know microprocessor has two buses.
Address Bus and Data Bus . It can be 8-bit, 16-bit
Or 32-bit. 8051 consisting with 16-bit
Address bus and 8-bit data bus.
𝑷𝟎
𝑷𝟐
𝑷𝟏
𝑷𝟑
4. Address Bus and Data Bus !
Address bus carries memory addresses from the processor to other
components such as primary storage and input/output devices. Address bus
is unidirectional.
Data bus carries the data between the processor and other components.
The data bus is bidirectional .
There is also control bus. Control bus is
Bi-directional it transmit command signals from
The CPU and response signals from the
Hardware.
5. I/O Ports !
In 8051 microcontroller the ports are act as data bus. They can send or
receive data between them.
They carry data from one port and transfer to another unit of
microcontroller. The data size must be 8-bit.
Microcontroller can communicate one port to another unit at a time. It can
not communicate parallel to multiple ports at a time, But microcontroller
8051 can communicate 4 units at a time because of it has 4 ports named as
𝑷𝟎, 𝑷𝟏, 𝑷𝟐 and 𝑷𝟑. That’s why this port are say as data bus. Technically they
are not data bus ,they are ports
When we turn on microcontroller 8051 then every ports was configured as
input port. They are ready for take input.
6. I/O Ports !
Every ports are able to use as input or output port of microcontroller 8051.
But we have to defined as the state by code.
When the first 0 is written to a port. It becomes an output.
When the first 1 is written to a port. It becomes an input.
To use any of these ports as an input or output port it must be
programmed. Because initial state it act as input port.
When all the ports as input port look like (This is initial state after ON):
𝑷𝟎 = 𝟏 𝑷𝟏 = 𝟏 𝑷𝟐 = 𝟏 𝑷𝟑 = 𝟏
When all the ports as output port look like:
𝑷𝟎 = 𝟎 𝑷𝟏 = 𝟎 𝑷𝟐 = 𝟎 𝑷𝟑 = 𝟎
7. 𝑃0 Port of Microcontroller 8051 !
It can be used for input or output port. 𝑷𝟎 has 8-pins.
Each pins must be connected
to a 10K ohm pull-up resistor.
This is due to the fact that 𝑷𝟎 is an
Open drain unlike 𝑷𝟏 ,𝑷𝟐 𝒂𝒏𝒅 𝑷𝟑
Open drain is term used for MOS
chips in the same way that open
collector is used for TTL chips.
8. 𝑃0 Port of Microcontroller 8051 !
Port 𝑷𝟎 also act as a address bus. Sometimes when we wanted to read data
from memory that why the memory address need to know ,by this time port
𝑷𝟎 act as a address bus.
Addresses are 16-bit but 𝑃0 has 8-bit only. How the address will know ?
For this another port also used as a address bus. 𝑷𝟎 and 𝑷𝟐 act as a address
bus those time. AD means there address. It was known as DUAL-Role
𝑷𝟎 port has 𝐴𝐷0 − 𝐴𝐷7
𝑷𝟐 port has 𝐴𝐷8 − 𝐴𝐷15
By combining these two ports it was act as address bus. By using two ports
it can know addresses of memory location and able to read data in memory.
9. 𝑃1 Port of Microcontroller 8051 !
Port 𝑷𝟏 can be used as input or output. In contrast to port 𝑷𝟎 ,this need to
pull-up resistors for connecting with port pins. But port 𝑃1 does not need
any pull-up resistors since it was already has pull-up resistors internally.
𝑷𝟏 has 8-pins.
Upon reset ,port 𝑷𝟏 is configured as an input port. The port 𝑷𝟏 is only used
for exchanging the data between units. It has no more operations. It was only
used for data exchange.
10. 𝑃2 Port of Microcontroller 8051 !
Port 𝑷𝟐 can be used as input and output also. Just like port 𝑷𝟏 ,port 𝑷𝟐
does not need any pull-up resistors since it was already has pull-up resistors
internally. 𝑷𝟐 has 8-pins.
Upon reset, port 𝑷𝟐 is configured as an input port.
By Combining with port 𝑷𝟎 it was act as a address bus.
When the 8051 is connected to an external memory, it provides path for
upper 8-bits of 16-bits address, and it cannot be used as I/O.
11. 𝑃3 Port of Microcontroller 8051 !
Port 𝑷𝟑 can be used as input and output by considering its state.
Port 𝑷𝟑 does not need any pull-up resistors.
Port 𝑷𝟑 is configured as an input port upon reset.
Port 𝑷𝟑 has the additional function of providing some extremely important
signal’s.
Just like 𝑷𝟏 ,port 𝑷𝟑 also exchanging data between units but it has some
additional function’s also.
12. 𝑃3 Port of Microcontroller 8051 !
Without exchanging data ,port
𝑷𝟑 also works with some
additional program’s.
In port 𝑷𝟑 the P3.0 and P3.1
are used for serial communica-
tion’s
P3.0 RxD is used for receiving
data from other units.
P3.1 TxD is used for transmitting
data to other units.
13. 𝑃3 Port of Microcontroller 8051 !
In port 𝑷𝟑 the P3.2 and P3.3
are used for interrupt processes.
Interrupt defined as, when
microcontroller executes any
program and other programs are
interrupt it. Like a Hardware
Failure, Power failure.
To get the interrupts from other
unit microcontroller 8051 used these
two pins.
This two pins are active on low. 𝑰𝑵𝑻𝟎 is used for output
Interrupts on other units and 𝑰𝑵𝑻𝟏 is used for take input
Interrupts from other units.
14. 𝑃3 Port of Microcontroller 8051 !
Microcontroller 8051 has two
timers for maintaining the
processing time.
P3.4 and P3.5 are used count
time of processes. This two are
counters. T0 is for timer 0 and T1
is for timer 1.
15. 𝑃3 Port of Microcontroller 8051 !
P3.6 and P3.7 pins of port
𝑷𝟑 was used for read and write
operations of memory .
If it need to write in memory
then P3.6 𝑾𝑹 signal will be
generated and the particular
location of memory was written.
16. 𝑃3 Port of Microcontroller 8051 !
If it need to read data in
memory then P3.7 𝑹𝑫 signal will
be generated and the particular
location of memory was read.
Both of pins are active on low.
17. 𝑃3 Port of Microcontroller 8051 !
We know microcontroller 8051 has 128-bytes of RAM and 4-Kbytes of
ROM.
It has limited memory. If a greater memory size required for some
program for execute it then microcontroller 8051 must be add an external
memory with it. Like Hard Disk(HD), Solid State Drive (SSD).
How microcontroller 8051 read or write in external memory?
Sol: When it want to write in memory then low signal generates from 𝑾𝑹 , then it will be
active because it will active on low by this time 𝑹𝑫 pin will get the high signal because now it
is write operation that’s why it will standby. Then the memory address generated where the
data will be written. Then the microcontroller write the data using 8-bit data bus on particular
location. The read operation is the reverse of write operation.