0% found this document useful (0 votes)
97 views66 pages

MP & MC Chap3

The document discusses the architecture of the 8051 microcontroller. It includes a basic block diagram showing the main components of the 8051 including CPU, program memory, data memory, I/O ports, timers, and interrupts. It also provides the pin diagram and describes some of the key features of the 8051 such as its memory sizes, I/O lines, timers, and interrupt structure.

Uploaded by

njytarqbe
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)
97 views66 pages

MP & MC Chap3

The document discusses the architecture of the 8051 microcontroller. It includes a basic block diagram showing the main components of the 8051 including CPU, program memory, data memory, I/O ports, timers, and interrupts. It also provides the pin diagram and describes some of the key features of the 8051 such as its memory sizes, I/O lines, timers, and interrupt structure.

Uploaded by

njytarqbe
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/ 66

Chapter-3

8051 Microcontroller Architecture

Dr. Mukesh M Bhesaniya


Department of Electrical Engineering
G H Patel College of Engineering and Technology
Vallabh Vidyanagar, Gujarat, India

3160914:MP & MC DR. MUKESH M BHESANIYA 1


Content
Introduction to MCS -51 Family microcontrollers

Architectural block Diagram

Pin diagram and Pin Functions

General Purpose and Special Function Registers

Oscillator and clock circuit

Reset circuit

I/O Port circuits

Memory organization, Internal program and data memory

3160914:MP & MC DR. MUKESH M BHESANIYA 2


Microcontrollers
The microcontrollers are the microprocessors designed especially for control
applications.

Microcontrollers contain memory units and I/O ports inside a chip in addition to
the CPU part.

Some of the machines using microcontrollers are microwave ovens, washing


machines, sewing machines, automobile ignition systems, computer printers and
fax machines etc.

Lots of semiconductor companies are in the market of microcontrollers and any


application development engineer is flooded with the variety of microcontrollers
as the choice.

3160914:MP & MC DR. MUKESH M BHESANIYA 3


Microprocessor vs. Microcontroller
Microprocessor Microcontroller

CPU RAM ROM

Serial
I/O Port Timer COM Port

• Microprocessor is heart of Computer • Micro Controller is a heart of embedded


system. system.
• It is just a processor. Memory and I/O
• Micro controller has a processor along with
components have to be connected
internal memory and i/O components
externally
• Since memory and I/O has to be
• Since memory and I/O are present internally,
connected externally, the circuit becomes
the circuit is small.
large.
• Cost of the entire system increases • Cost of the entire system is low
• It is suitable for processing information in • It is suitable for control of various devices
computers. requiring minimum component count.
3160914:MP & MC DR. MUKESH M BHESANIYA 4
Microprocessor vs. Microcontroller
Microprocessor Microcontroller
• Due to external components, the entire • Since external components are low, total
power consumption is high. Hence it is not power consumption is less and can be used
suitable to used with devices running on with devices running on stored power like
stored power like batteries. batteries.
• Most of the micro controllers have power
• Most of the microprocessors do not have saving modes like idle mode and power
power saving features. saving mode. This helps to reduce power
consumption even further.
• Instruction sets focus on processing- • Instruction sets focus on control and bit-level
intensive operations operations
• Microprocessor have less number of • Micro controller have more number of
registers, hence more operations are registers, hence the programs are easier to
memory based. write.
• Microprocessors are based on von
• Micro controllers are based on Harvard
Neumann model/architecture where
architecture where program memory and
program and data are stored in same
Data memory are separate
memory module
• Used mainly in control applications e.g.
• Mainly used in personal computers
washing machine, MP3 players
3160914:MP & MC DR. MUKESH M BHESANIYA 5
Criteria for Choosing a Microcontroller
Followings are the main point to consider before choosing a microcontroller for
projects. To choose microcontroller one should consider following points :

✓ Microcontroller should meet the computing requirement like speed of


processing, ability of handle multiple tasks efficiently and effectively.
✓ Cost also plays an important role to choose microcontroller. Because cost of per
unit of each microcontroller also plays an important role in cost of product.
✓ Software availability should be considered while choosing microcontroller.
Software tools like compilers, assemblers and simulators should be easily
available.
✓ Help resources should be available from manufacturer.
✓ Online source code libraries and help forums should also available.
✓ How many tasks you need to perform? Either you are performing multiple tasks
or single task.
✓ Others requirements (features):
Number of I/O ports and timers, size, packaging, power consumption

3160914:MP & MC DR. MUKESH M BHESANIYA 6


MCS-51 Family
MCS-51 is family of 8-bit microcontrollers.

On chip On chip
data program No. of 16-bit No. of
Device Serial I/O
memory memory Timer/Counter Interrupts
(Byte) (Byte)

8031 128 None 2 5 1

8032 256 None 3 6 1

8051 128 4K ROM 2 5 1

8052 256 8K ROM 3 6 1

8751 128 4K EPROM 2 5 1

8752 256 8K EPROM 3 6 1

3160914:MP & MC DR. MUKESH M BHESANIYA 7


Basic Block Diagram of 8051
External Interrupts

Interrupt 4k 128 bytes Timer 1


Control ROM RAM Timer 2

CPU

OSC Bus
4 I/O Ports Serial
Control

P0 P2 P1 P3 TXD RXD
Addr/Data

3160914:MP & MC DR. MUKESH M BHESANIYA 8


Features of the 8051
The 8051 is the original member of the MCS-51 family, and is the core for all
MCS-51 devices. The features of the 8051 core are:

✓ 8-bit CPU optimized for control applications


✓ Extensive Boolean processing (Single-bit logic) capabilities
✓ 64K Program Memory address space
✓ 64K Data Memory address space
✓ 4K bytes of on-chip Program Memory
✓ 128 bytes of on-chip Data RAM
✓ 32 bidirectional and individually addressable I/0 lines
✓ Two 16-bit timer/counters
✓ Full duplex UART
✓ 6-source/5-vector interrupt structure with two priority levels
✓ On-chip clock oscillator

3160914:MP & MC DR. MUKESH M BHESANIYA 9


Pin Diagram of the 8051
P1.0 1 40 Vcc
P1.1 2 39 P0.0(AD0)
P1.2 3 38 P0.1(AD1)
P1.3 4 37 P0.2(AD2)
P1.4 5 36 P0.3(AD3)
P1.5
P1.6
6
7
8 35
34
P0.4(AD4)
P0.5(AD5)
8
P1.7
RST 9 0 33
32
P0.6(AD6)
P0.7(AD7)
(RXD)P3.0 10 31 EA/Vpp
(TXD)P3.1
(INT0)P3.2
11
12
5 30 ALE
29 PSEN
13
(INT1)P3.3
(T0)P3.4 14 1 28
27
P2.7(A15)
P2.6(A14)
(T1)P3.5 15 26 P2.5(A13)
(WR)P3.6 16 25 P2.4(A12)
(RD)P3.7 17 24 P2.3(A11)
XTAL2 18 23 P2.2(A10)
XTAL1 19 22 P2.1(A9)
Vss 20 21 P2.0(A8)

3160914:MP & MC DR. MUKESH M BHESANIYA 10


Pin Description
Name Type Function

Supply Voltage during Normal, Idle or Power Down


Vcc I
operation.

Vss / GND I Circuit Ground. 0V Reference.

Dual function 8-bit bidirectional I/O port.


As general purpose I/O port.
Port 0 I/O
As Multiplexed low order add/data bus while
accessing external program or data memory.

Dedicated 8-bit Bi-directional I/O port. The pins in the


Port 1 I/O port are solely for the interfacing with external
devices.

3160914:MP & MC DR. MUKESH M BHESANIYA 11


Pin Description
Name Type Function

Dual function 8-bit bidirectional I/O port.


As general purpose bi-directional I/O port.
Port 2 I/O
As High Order address bus while fetching external
program and accessing data memory of 16-Bit address.

Dual function 8-bit bidirectional I/O port.


Port 3 I/O As general bi-directional I/O port.
It also serves functions of special features

3160914:MP & MC DR. MUKESH M BHESANIYA 12


Pin Description

3160914:MP & MC DR. MUKESH M BHESANIYA 13


Pin Description

Name Type Function

Program Strobe ENable.


It is a READ strobe output when the device fetches codes
PSEN O from external program memory.
When the device is executing codes from internal memory,
it is inactive.
External Access.
This pin must be strapped low in order to enable the
device to fetch codes from external program memory with
EA/Vpp I addresses from 0000H to FFFFH.
It must be strapped High for internal program execution.
This pin also receives programming enable voltage (12V)
during flash programming.

3160914:MP & MC DR. MUKESH M BHESANIYA 14


Pin Description
Name Type Function

Input to inverting oscillator amplifier, and input to internal


XTAL1 I
clock generator circuit.

XTAL2 O Output from the inverting oscillator amplifier.

Address Latch Enable:


ALE O When port 0 is used as address/data bus to external
memory, the ALE output is used to latch the low order byte
of the address.

Reset Input
RST I High logic “1” on this pin for two machine cycles while the
oscillator is running will reset the device

3160914:MP & MC DR. MUKESH M BHESANIYA 15


XTAL2 and XTAL1 (18 and 19 pins)
The 8051 has an on-chip oscillator circuit but requires an external clock to run it
✓ A quartz crystal oscillator is connected to inputs XTAL1 (pin19) and XTAL2
(pin18)
✓ The quartz crystal oscillator also needs two capacitors of 33 pF value
✓ The speed of 8051 refers to the maximum oscillator frequency connected to
XTAL.
✓ We can observe the frequency on the XTAL2 pin using the oscilloscope.
✓ If you use a frequency source other than a crystal oscillator, such as a TTL
oscillator then it will be connected to XTAL1 and XTAL2 is left unconnected.
Not XTAL2
Connected
EXTERNAL
OSCILLATOR XTAL1
SIGNAL
GND

3160914:MP & MC DR. MUKESH M BHESANIYA 16


RST (Pin 9)
RESET pin is an input and is active high (normally low)
Upon applying a high pulse to this pin, the microcontroller will reset and
terminate all activities
This is often referred to as a power-on reset which ensures that the device starts
operating in a known state.
In order for the RESET input to be effective, it must have a minimum duration of
two machine cycles.
Activating a power-on reset will cause all values in the registers to be lost

3160914:MP & MC DR. MUKESH M BHESANIYA 17


8051 Basic Circuit that makes it Work

3160914:MP & MC DR. MUKESH M BHESANIYA 18


8051 Basic Circuit that makes it Work

3160914:MP & MC DR. MUKESH M BHESANIYA 19


8051 LED Circuit

3160914:MP & MC DR. MUKESH M BHESANIYA 20


8051 LED Circuit

3160914:MP & MC DR. MUKESH M BHESANIYA 21


8051 Architecture
Arithmetic and Logic Unit (ALU):
✓ As you may know that ALU is the brain of any processing device.
✓ It monitors and controls all operations that are performed in the
Microcontroller.
✓ It reads program written in ROM memory and executes them and do the
expected task.

3160914:MP & MC DR. MUKESH M BHESANIYA 22


CPU Registers (A & B)
Register A and B hold the results of many instructions, particularly math and
logical operations, of 8051 CPU.
The A is most versatile of the CPU registers and used in many operations
including Addition, Subtraction, integer multiplication and division, and Boolean
bit manipulation.
✓ ADD A,R0
✓ SUBB A,#18H
The B is used in multiplication and division operation with register A.
✓ MUL AB
✓ DIV AB

3160914:MP & MC DR. MUKESH M BHESANIYA 23


Program Status Word
The program status word (PSW) register is an 8-bit register.
It is also referred to as the flag register.
Although the PSW register is 8 bits wide, only 6 bits of it are used by 8051. The
two unused bits are user-definable flags.
Four of the flags are called conditional flags, meaning that they indicate some
conditions that result after an instruction is executed. These four are CY (carry),
AC (auxiliary carry), P (parity), and OV (overflow).
As seen from below figure, the bits PSW.3 and PSW.4 are designated as RS0 and
RS1 as register selection bit, respectively, and are used to change the bank
registers.

3160914:MP & MC DR. MUKESH M BHESANIYA 24


Program Status Word

BIT SYMBOL FUNCTION


PSW.7 CY Carry flag.
PSW.6 AC Auxiliary Carry flag. (For BCD operations.)
PSW.5 F0 Flag 0. (Available to the user for general purposes.)
PSW.4 RS1 Register bank select control bit 1.
PSW.3 RS0 Register bank select control bit 0.
PSW.2 OV Overflow flag.
PSW.1 — Reserved for future use/User flag.
PSW.0 P Parity flag.

3160914:MP & MC DR. MUKESH M BHESANIYA 25


Program Status Word

(RS1, RS0) Bank


(0,0)— Bank 0 (00H–07H)
(0,1)— Bank 1 (08H–0fH)
(1,0)— Bank 2 (10H–17H)
(1,1)— Bank 3 (18H–17H)

3160914:MP & MC DR. MUKESH M BHESANIYA 26


Program Status Word
CY, the carry flag
✓ This flag is set whenever there is a carry out from the D7 bit.
✓ This flag bit is affected after an 8-bit addition or subtraction.
✓ It can also be set to 1 or 0 directly by an instruction such as “SETB C” and
“CLR C” where “SETB C” stands for “set bit carry” and “CLR C” for “clear
carry”.

AC, the auxiliary carry flag


✓ If there is a carry from D3 to D4 during an ADD or SUB operation, this bit is
set; otherwise, it is cleared.
✓ This flag is used by instructions that perform BCD (binary coded decimal)
arithmetic.

3160914:MP & MC DR. MUKESH M BHESANIYA 27


Program Status Word
P, the parity flag
✓ The parity flag reflects the number of 1 s in the A (accumulator) register
only.
✓ If the A register contains an odd number of 1’s, then P = 1 and P = 0 if A has
an even number of 1s.

OV, the overflow flag


✓ If in signed arithmetic operations result exceeds more than 7 bit than OV
flag sets else resets. It is used in signed arithmetic operations only.

3160914:MP & MC DR. MUKESH M BHESANIYA 28


8051 instructions that affects flag

3160914:MP & MC DR. MUKESH M BHESANIYA 29


Program Status Word
Example:
Show the status of the CY, AC and P flag after the addition of 38H and 2FH in the
following instructions.
MOV A, #38H
ADD A, #2FH ;after the addition A=67H, CY=0
Solution:
38 00111000
+ 2F 00101111
67 01100111
✓ CY = 0 since there is no carry beyond the D7 bit
✓ AC = 1 since there is a carry from the D3 to the D4 bit
✓ P = 1 since the accumulator has an odd number of 1s (it has five 1s)

3160914:MP & MC DR. MUKESH M BHESANIYA 30


Program Status Word
Example:
Show the status of the CY, AC and P flag after the addition of 9CH
and 64H in the following instructions.
MOV A, #9CH
ADD A, #64H ;after the addition A=00H, CY=1
Solution:
9C 10011100
+ 64 01100100
100 00000000
✓ CY = 1 since there is a carry beyond the D7 bit
✓ AC = 1 since there is a carry from the D3 to the D4 bit
✓ P = 0 since the accumulator has an even number of 1s (it has zero 1s)

3160914:MP & MC DR. MUKESH M BHESANIYA 31


Program Status Word
Example:
Show the status of the CY, AC and P flag after the addition of 88H
and 93H in the following instructions.
MOV A, #88H
ADD A, #93H ;after the addition A=1BH, CY=1
Solution:
88 10001000
+ 93 10010011
11B 00011011
✓ CY = 1 since there is a carry beyond the D7 bit
✓ AC = 0 since there is no carry from the D3 to the D4 bit
✓ P = 0 since the accumulator has an even number of 1s (it has four 1s)

3160914:MP & MC DR. MUKESH M BHESANIYA 32


Program Counter
Program counter(PC):
✓ The Program Counter (PC) is a 16-bit register which tells the 8051 where the
next instruction to execute is found in memory.
✓ It is used to hold 16 bit address of internal RAM, external RAM or external
ROM locations.
✓ When the 8051 is initialized PC always starts at 0000h and is incremented
each time an instruction is executed.
✓ The PC is the only internal register that does not have an internal address.

3160914:MP & MC DR. MUKESH M BHESANIYA 33


Data Pointer (DPTR) Register
Data pointer register(DTPR):
✓ It is a 16 bit register used to hold address of external or internal RAM where
data is stored or result is to be stored.
✓ It is used to store 16 bit data. It is divided into two 8-bit registers, DPH-data
pointer higher order (83H) and DPL-data pointer lower order (82H).
✓ Each register can be used as general purpose register to store 8 bit data and
can also be used as memory location.
✓ DPTR does not have single internal address.
Ex:
MOV DPTR,#200H
MOVX A,@DPTR
MOV R0,DPL
MOV R1,DPH
3160914:MP & MC DR. MUKESH M BHESANIYA 34
The Stack and the Stack Pointer (SP)
Stack pointer(SP):
✓ A stack is nothing but the portion of RAM (Random access memory).
✓ Stack pointer is an 8-bit register which is used as a memory pointer for stack
memory.
✓ When the 8051 is powered up, the SP register contains value 07H.
✓ RAM location 08 is the first location begin used for the stack by the 8051.
✓ When the data is to be placed on stack by push instruction, the content of
stack pointer is incremented by 1, and when data is retrieved from stack,
content of stack of stack pointer is decremented by 1.

The storing of a CPU register in the stack is called a PUSH


Loading the contents of the stack back into a CPU register is called a POP

3160914:MP & MC DR. MUKESH M BHESANIYA 35


The Stack and the Stack Pointer (SP)
Example:
Show the stack and stack pointer from the following. Assume the default stack
area.

MOV R6, #25H


MOV R1, #12H
MOV R4, #0F3H
PUSH 6
PUSH 1
PUSH 4

Solution:

3160914:MP & MC DR. MUKESH M BHESANIYA 36


The Stack and the Stack Pointer (SP)
Example:
Examining the stack, show the contents of the register and SP after execution of
the following instructions. All value are in hex.

POP 3 ; POP stack into R3


POP 5 ; POP stack into R5
POP 2 ; POP stack into R2

Solution:

3160914:MP & MC DR. MUKESH M BHESANIYA 37


Memory Organization
The 8051 microcontroller's memory is divided into
✓ Program Memory and
✓ Data Memory
Program Memory (ROM) is used for permanent saving program being executed.
While Data Memory (RAM) is used for temporarily storing and keeping
intermediate results and variables.

Device On chip data memory (Byte) On chip program memory (Byte)

8031 128 None


8032 256 None
8051 128 4K ROM
8052 256 8K ROM

3160914:MP & MC DR. MUKESH M BHESANIYA 38


8051 Internal Data Memory (RAM)

3160914:MP & MC DR. MUKESH M BHESANIYA 39


8051 Internal Data Memory (RAM)
In the 8051 family, 8051 has total 128 bytes of internal data
RAM and we can interface external data memory up to 64K.

Hence, total size of data memory in 8051 can be up-to


external 64K + internal 128 bytes.

Internal RAM of 8051 is divided into 3 parts:-

1) Register banks

2) Bit addressable area

3) Scratch pad area

3160914:MP & MC DR. MUKESH M BHESANIYA 40


8051 Internal Data Memory (RAM)
Register Banks:

✓ There are four register banks from 00H to 1FH. On power-up, registers R0 to
R7 are located at 00H to 07H.

✓ However, this can be changed so that the register set points to any of the
other three banks (if you change to Bank 2, for example, R0 to R7 is now
located at 10H to 17H).

RS1 RS0
[PSW.4] [PSW.3]
BANK 0 0 0
BANK 1 0 1
BANK 2 1 0
BANK 3 1 1

3160914:MP & MC DR. MUKESH M BHESANIYA 41


8051 Internal Data Memory (RAM)
Bit-addressable Locations:

✓ The 8051 contains 210 bit-


addressable locations of which
128 are at locations 20H to 2FH
while the rest are in the SFRs.

✓ Each of the 128 bits from 20H to


2FH have a unique number
(address) attached to them, as
shown in the table.

✓ The 8051 instruction set allows


you to set or reset any single bit
in this section of RAM.
3160914:MP & MC DR. MUKESH M BHESANIYA 42
8051 Internal Data Memory (RAM)
General purpose RAM:

✓ 80 bytes from 30H to 7FH locations are used for read and write storage; it is
called as scratch pad. These 80 locations RAM are widely used for the purpose of
storing data and parameters by 8051 programmers.

FF FF
INDIRECT DIRECT SPECIAL
UPPER
ADDRESSING ADDRESSING FUNCTION
128
FOR 8052
REGISTERS
80 80
7F
DIRECT/
LOWER
INDIRECT
128
ADDRESSI
NG
00
RAM
3160914:MP & MC DR. MUKESH M BHESANIYA 43
Special Function Registers (SFRs)
The second 128 bytes are used to store Special Function Registers (SFR) that 8051
program can configure and control the ports, timer, interrupts, serial
communication, and other tasks.
Special Function Registers (SFRs) are used for running and monitoring the
operation of the microcontroller.
Each of these registers as well as each bit they include, has its name, address in
the scope of RAM and precisely defined purpose such as timer control, interrupt
control, serial communication control etc.
Even though there are 128 memory locations intended to be occupied by them,
the basic core, shared by all types of 8051 microcontrollers, has only 21 such
registers.
Each register of SFR has one byte address. Some of the registers are both byte and
bit addressable (The registers whose address ends with 0H or 8H are bit
addressable).

3160914:MP & MC DR. MUKESH M BHESANIYA 44


Special Function Registers (SFRs)

3160914:MP & MC DR. MUKESH M BHESANIYA 45


8051 Internal Data Memory (RAM)
Register Banks:

Example1 : Move 25H and 30H into the registers R0 and R1 of bank2.

✓ In order to select bank2 we need to make RS0=0 and RS1=1 i.e psw.3=0 and
psw.4=1
CLR PSW.3 ;CLR means clear psw.3 i.e RS0=0
SETB PSW.4 ;RS1=1, now bank2 is selected
MOV R0,#25H ;move 25H in R0
MOV R1,#30H ; move 30H in R1

Example2 : Move 10H and 12H into the registers R3 and R4 of bank3.
SETB RS0 ; PSW.3 =1
SETB RS1 ; PSW.4 =1, now bank3 have been selected
MOV R3,#10H ;move 10H in R3
MOV R4,#12H ; move 12H in R4
3160914:MP & MC DR. MUKESH M BHESANIYA 46
8051 Internal Data Memory (RAM)
Register Banks:

Example3 : Move 02H and 12H into the registers R0 of Bank0 and R4 of bank2
respectively.

✓ As default Bank0 will be selected.

MOV R0,#02H ; we are moving 2 into R0 of bank0


SETB PSW.4 ; It is not necessary to clear the psw.3 because its already
zero so we set psw.4 to select bank2
MOV R4,#12H ; moving 12h into r4 of bank2

3160914:MP & MC DR. MUKESH M BHESANIYA 47


8051 Internal Data Memory (RAM)
Bit-addressable Locations:
Find out to which byte each of the following bits belongs. Give the address of the
RAM byte in hex
(a) SETB 42H, (b) CLR 67H, (c) CLR 0FH (d) SETB 28H, (e) CLR 12, (f) SETB 05

3160914:MP & MC DR. MUKESH M BHESANIYA 48


8051 Program Memory (ROM)
Internal ROM occupies the code address space from 0000H to 0FFFH (Size = 4K
byte)

Program addresses higher than 0FFFH will automatically fetch code bytes from
external program memory

Code bytes can also be fetched exclusively from an external memory by


connecting the external access pin (EA) to ground

3160914:MP & MC DR. MUKESH M BHESANIYA 49


8051 Program Memory (ROM)

3160914:MP & MC DR. MUKESH M BHESANIYA 50


8051 External Memory Interface

3160914:MP & MC DR. MUKESH M BHESANIYA 51


8051 Input/output Ports
Name Type Function
Dual function 8-bit bidirectional I/O port.
As general purpose I/O port.
Port 0 I/O
As Multiplexed low order add/data bus while accessing
external program or data memory.
Dedicated 8-bit Bi-directional I/O port. The pins in the
Port 1 I/O
port are solely for the interfacing with external devices.

Dual function 8-bit bidirectional I/O port.


As general purpose bi-directional I/O port.
Port 2 I/O
As High Order address bus while fetching external
program and accessing data memory of 16-Bit address.

Dual function 8-bit bidirectional I/O port.


Port 3 I/O As general bi-directional I/O port.
It also serves functions of special features

3160914:MP & MC DR. MUKESH M BHESANIYA 52


Basic Input / Output Operation
Input/Output (I/O) pin:
✓ Figure illustrates a simplified schematic of all
circuits within the microcontroller connected to
one of its pins. It refers to all the pins except
those of the P0 port which do not have pull-up
resistors built-in.
Output pin:
✓ A logic zero (0) is applied to a bit of the P
register. The output FE transistor is turned on,
thus connecting the appropriate pin to ground.
Input pin:
✓ A logic one (1) is applied to a bit of the P
register. The output FE transistor is turned off
and the appropriate pin remains connected to
the power supply voltage over a pull-up resistor
of high resistance.
3160914:MP & MC DR. MUKESH M BHESANIYA 53
Basic Input / Output Operation

3160914:MP & MC DR. MUKESH M BHESANIYA 54


Circuit of I/O PORT 0
Port-0 can be used as a normal bidirectional I/O port or it can be used for
address/data interfacing for accessing external memory.
When control is '1', the port is used for address/data interfacing. When the
control is '0', the port can be used as a bidirectional I/O port.

3160914:MP & MC DR. MUKESH M BHESANIYA 55


PORT 0 as an Input Port
Let us assume that control is '0'. When the port is used as an input port, '1' is
written to the latch. In this situation both the output MOSFETs are 'off'.
Hence the output pin have floats hence whatever data written on pin is directly
read by read pin.

3160914:MP & MC DR. MUKESH M BHESANIYA 56


PORT 0 as an Output Port
Suppose we want to write 1 on pin of Port 0, a '1' written to the latch which
turns 'off' the lower FET while due to '0' control signal upper FET also turns off as
shown in figure.
Here the pin is floating, hence to get the logic 0 or 1 we need to connect the pull
up resistor parallel to upper FET . This is the reason why we needed to connect
pull up resistor to port 0 when we want to initialize port 0 as an output port .

3160914:MP & MC DR. MUKESH M BHESANIYA 57


PORT 0 as an Output Port
If we write ‘1' on pin of port 0, the lower FET is off and the pin is connect to Vcc
through the pull up resistor. Hence the output becomes high.
If we write '0' on pin of port 0, the pin is pulled down by the lower FET. Hence
the output becomes zero.

3160914:MP & MC DR. MUKESH M BHESANIYA 58


Circuit of I/O PORT 1
Port-1 is dedicated only for I/O interfacing. When used as output port, no need
to connect additional pull-up resistor like port 0.
Due to internal pull-up resistor as shown in figure, the pin is pulled up or down
through internal pull-up when we initialize as an output port.

3160914:MP & MC DR. MUKESH M BHESANIYA 59


I/O PORT 1
To use port-1 as input port, '1' has to be written to the latch.

Ex:
SETB P1.0
MOV P1,#0xFF

In this input mode when '1' is written to the pin by the external device then it
reads fine.

But when '0' is written to the pin by the external device then the external source
must sink current due to internal pull-up.

If the external device is not able to sink the current the pin voltage may rise,
leading to a possible wrong reading.

3160914:MP & MC DR. MUKESH M BHESANIYA 60


Circuit of I/O PORT 2
Port-2 is used for higher external address byte or a normal input/output port.
The I/O operation is similar to Port-1.
Here again due to internal pull-up there is limited current driving capability.

3160914:MP & MC DR. MUKESH M BHESANIYA 61


Circuit of I/O PORT 3
It work as an IO port same like Port 1 and port 2.
Only alternate function of port 3 makes its architecture different than other
ports.

3160914:MP & MC DR. MUKESH M BHESANIYA 62


PORT 3 Alternate Functions

3160914:MP & MC DR. MUKESH M BHESANIYA 63


3160914:MP & MC DR. MUKESH M BHESANIYA 64
Reference
The 8051 Microcontroller and Embedded Systems Using Assembly and C
By Muhammad Ali Mazidi, Janice Gillispie Mazidi and Rolin McKinlay
Pearson Education

The 8051 Microcontroller & Embedded Systems using Assembly and C


By K. J. Ayala, D. V. Gadre
Cengage Learning , India Edition

Using the MCS-51 Microcontrollers


By Han Way Huang
Oxford Uni Press

Programming and Customizing the 8051 Microcontroller


By Myke Predko
Tata Mcgraw Hill

3160914:MP & MC DR. MUKESH M BHESANIYA 65


Thank you

3160914:MP & MC DR. MUKESH M BHESANIYA 66

You might also like