Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

MC 18ec46 Mod1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

B.N.M.

Institute of Technology
Approved by AICTE, Affiliated to VTU, Accredited as Grade A Institution by NAAC.
All UG branches – CSE, ECE, EEE, ISE &Mech.E Accredited by NBA for academic years 2018-19 to 2020-21 & valid upto 30.06.2021
Post box no. 7087, 27th cross, 12th Main, Banashankari 2nd Stage, Bengaluru- 560070, INDIA
Ph: 91-80- 26711780/81/82 Email: principal@bnmit.in, www. bnmit.org

Department: Electronics and Communication Engineering

Course Name: Microcontroller Course Code: 18EC46


Sem: IV

Module 1 - 8051 Microcontroller

Q1. Compare Microprocessors and Microcontrollers


Microprocessor Microcontroller

Arithmetic and Accumulator


Timer/ I/O Ports
logic unit
Counter
Interrupt
Working Register
Working registers
Internal Circuits
Internal RAM ROM
Program Counter Stack Pointer
Stack Pointer Clock Ckt.

Clock Circuit Interrupt circuit


Program Counter UART

Block diagram of microprocessor Block diagram of microcontroller

Microprocessor contains ALU, General purpose Microcontroller contains the circuitry of microprocessor,
registers, stack pointer, program counter, clock and in addition it has built in ROM, RAM, I/O Devices,
timing circuit and interrupt circuit Timers/Counters etc.

It has many instructions to move data between It has few instructions to move data between memory and
memory and CPU CPU

Few bit handling instruction It has many bit handling instructions

Less number of pins are multifunctional More number of pins are multifunctional

Single memory map for data and c Separate


(program) omemory map for data and code (program)
d
e
Access time for memory and IO are more Less access time for built in memory and IO.
Microprocessor based system It requires less additional hardware
requires additional
hardware
More flexible in the design point of view Less flexible since the additional circuits which is residing
inside the microcontroller is fixed for a particular
microcontroller

Large number of instructions with flexible Limited number of instructions with few
addressing modes addressing modes

General purpose device Special purpose device

Example: Intel’s 8085 Microprocessor Example: Intel’s 8051Microcontroller

It has Princeton Architecture It has Harvard Architecture

Q2. Explain Microcontroller for embedded Systems with embedded products.

Microprocessors and microcontrollers are widely used in embedded system products. An


embedded product uses a microprocessor (or microcontroller) do one task and one task only.
For example, A printer is an example of embedded system since the processor inside it performs
only one task; namely getting the data and printing it. Contrast this with a Pentium based PC can
be used for any number of applications such as word processor, print server, bank teller terminal,
video game player, network server or internet terminal. A PC can perform number of tasks because
it RAM memory and an operating system that loads a variety of applications software into RAM
and lets the CPU run them.

In an embedded system, there is only one application software that is typically burned into ROM.
A PC contains or is connected to various embedded products such as keyboard, printer, modem,
disk controller, sound card, CD-ROM driver, mouse and so on. Each one of these peripheral has a
microcontroller inside it that performs only one task. For example inside every mouse the
microcontroller that performs the task of finding the mouse position and sending it to PC.
Some of Embedded Products using Microcontroller are:
Home
Appliances, intercom, telephones, security systems, garage door openers, answering machines, fax
machines, home computers, TVs, cable TV tuner, VCR, camcorder, remote controls, video games,
cellular phones, musical instruments, sewing machines, lighting control, paging, camera, pinball
machines, toys and exercise equipment.
Office
Telephones, computers, security systems, fax, machines, microwave, copier, laser printer, color,
printer and paging
Auto
Trip computer, engine control, air bag, ABS, instrumentation, security system, transmission,
control, entertainment, climate control, cellular, phone and keyless entry.
Q3. Discuss on types of microcontrollers.

Microcontrollers can be classified on the basis of internal bus width, architecture, memory and
instruction set as 4-bit, 8-bit,16-bit and 32-bit microcontrollers.
4-bit Microcontrollers:
These 4-bit microcontrollers are small size, minimum pin count and low cost controllers which are
widely used for low end applications like LED & LCD display drivers, portable battery chargers
etc.. Their power consumption is also low. The popular 4-bit controllers are Renasa M34501 which
is a 20 pin DIP chip with 4kB of ROM, 256 Bytes of RAM,2-Counters and 14 I/O Pins. Similarly
ATAM862 series from ATMEL.
8-bit Microcontrollers:
These are the most popular and widely used microcontrollers .About 55% of all CPUs sold in the
world are 8-bit microcontrollers only. The 8-bit microcontroller has 8-bitinternal bus and the ALU
performs all the arithmetic and logical operations on a byte instruction. The well known 8-bit
microcontroller is 8051 which was designed by Intel in the year 1980 for the use in embedded
systems. Other 8-bit microcontrollers are Intel 8031/8052 and Motorola MC68HC11 and AVR
Microcontrollers, Microchip’s PIC Microcontrollers 12C5XX ,16C5X and 16C505 etc...
16-bit Microcontrollers:
When the microcontroller performs 16-bit arithmetic and logical operations at an instruction, the
microcontroller is said to be a 16-bit microcontroller. The internal bus width of 16-bit
microcontroller is of 16-bit. These microcontrollers are having increased memory size and speed
of operation when compared to 8-bit microcontrollers. These are most suitable for Department of
ECE Unit 3 - RGCET ECT53 - Microprocessors and Microcontrollers 6 programming in High
level languages like C or C++ .They find applications in disk drivers, modems, printers, scanners
and servomotor control. Examples of 16-bit microcontrollers are Intel 8096 family and Motorola
MC68HC12 and MC68332 families, the performance and computing capability of 16 bit
microcontrollers are enhanced with greater precision as compared to the 8-bit microcontrollers.
32-Bit Microcontrollers:
These microcontrollers used in high end applications like Automotive control, Communication
networks, Robotics, Cell phones ,GPRS & PDAs etc..For EX: PIC32, ARM 7, ARM9, SHARP
LH79520, ATMEL 32 (AVR), Texas Instrument’s –. TMS320F2802x/2803x etc.. are some of the
popular 32-bit microcontrollers.

Q4. List the salient features of 8051 microcontroller


Salient features of 8051 microcontroller are given below:
 Eight bit CPU with registers A (Accumulator) and B (Special function)
 Sixteen bit Program counter (PC) and a data pointer (DPTR)
 8 Bit Program Status Word (PSW)
 8 Bit Stack Pointer (SP)
 8-bit Data bus
 16 bit Address bus
 4Kbytes of internal program memory (code memory) [ROM]
 128 bytes of internal data memory [RAM] which is divided into
o Four register banks, each containing eight registers [working register] [00 –
1F]
o Sixteen bytes, Bit addressable memory area [20 – 2F]
o Eighty bytes of general purpose memory area (Scratch pad memory) [30-7F]

 64 Kbytes of external program memory


 64 Kbytes of external data memory
 32 bi directional I/O pins arranged as four 8-bit ports: P0-P3
 Two 16 Bit Timer/Counter :T0 and T1
 Full Duplex serial data receiver/transmitter : SBUF
 Five vector interrupt structure and RESET.
 Oscillator and clock circuits

Q5. Draw and explain the block diagram of 8051 Microcontroller.


 Program Counter (PC) – 16 bit PC contains the address of next instruction to be executed. On reset
PC will set to 0000. After fetching every instruction PC will increment by one.
 8051 has 4 K Bytes of internal ROM. The address space is from 0000 to 0FFFh. If the program size
is more than 4 K Bytes 8051 will fetch the code automatically from external memory.
 Accumulator is an 8 bit register widely used for all arithmetic and logical operations. Accumulator
is also used to transfer data between external memory. B register is used along with Accumulator
for multiplication and division. A and B registers together is also called MATH registers.

 PSW (Program Status Word). This is an 8 bit register which contains the arithmetic
status of ALU and the bank select bits of register banks.

CY AC F0 RS1 RS0 OV - P

CY - Carry flag
AC - Auxiliary carry flag
F0 - Available to the user for general purpose
RS1, RS0 -Register bank select bits
OV - Overflow
P - Parity

 Stack Pointer (SP) – it contains the address of the data item on the top of the
stack. Stack may reside anywhere on the internal RAM. On reset, SP is
initialized to 07 so that the default stack will start from address 08 onwards.
 Data Pointer (DPTR) – DPH (Data pointer higher byte), DPL (Data pointer
lower byte). This is a 16 bit register which is used to furnish address
information for internal and external program memory and for external data
memory.
Q6. Draw the pin diagram of 8051 Microcontroller and explain the operation of pins.

Pin Description
Pins 1-8 PORT 1. Each of these pins can be configured as an input or an output.
Pin 9 RESET. A logic one on this pin disables the microcontroller and clears the contents of
most registers. In other words, the positive voltage on this pin resets the microcontroller. By
applying logic zero to this pin, the program starts execution from the beginning.

Pins10-17 PORT 3. Similar to port 1, each of these pins can serve as general input or output. Besides,
all of them have alternative functions

Pin 10 RXD. Serial asynchronous communication input or Serial synchronous communication


output.
Pin 11 TXD. Serial asynchronous communication output or Serial synchronous
communication clock output.
Pin 12 INT0.External Interrupt 0 input
Pin 13 INT1. External Interrupt 1 input
Pin 14 T0. Counter 0 clock input
Pin 15 T1. Counter 1 clock input
Pin 16 WR. Write to external (additional) RAM
Pin 17 RD. Read from external RAM
Pin 18, 19 XTAL2, XTAL1. Internal oscillator input and output. A quartz crystal which specifies
operating frequency is usually connected to these pins.
Pin 20 GND. Ground.
Pin 21-28 Port 2. If there is no intention to use external memory then these port pins are configured as
general inputs/outputs. In case external memory is used, the higher address byte, i.e.
addresses A8-A15 will appear on this port. Even though memory with capacity of 64Kb is
not used, which means that not all eight port bits are used for its addressing, the rest of them
are not available as inputs/outputs.
Pin 29 PSEN. If external ROM is used for storing program then a logic zero (0) appears on it every
time the microcontroller reads a byte from memory.
Pin 30 ALE. Prior to reading from external memory, the microcontroller puts the lower address
byte (A0-A7) on P0 and activates the ALE output. After receiving signal from the ALE pin,
the external latch latches the state of P0 and uses it as a memory chip address. Immediately
after that, the ALE pin is returned its previous logic state and P0 is now used as a Data Bus.

Pin 31 EA. By applying logic zero to this pin, P2 and P3 are used for data and address
transmission with no regard to whether there is internal memory or not. It means that even
there is a program written to the microcontroller, it will not be executed. Instead, the
program written to external ROM will be executed. By applying logic one to the EA pin,
the microcontroller will use both memories, first internal then external (if exists).
Pin 32-39 PORT 0. Similar to P2, if external memory is not used, these pins can be used as general
inputs/outputs. Otherwise, P0 is configured as address output (A0-A7) when the ALE pin is
driven high (1) or as data output (Data Bus) when the ALE pin is driven low (0).

Pin 40 VCC. +5V power supply.

Q7. Explain 8051 Flag Bits and PSW Register with example.

Flag register in 8051 is called as program status word (PSW) used to indicate the Arithmetic
condition of ACC. This special function register PSW is also bit addressable and 8 bit wide means
each bit can be set or reset independently.
The meaning of various bits of PSW register is shown below.
CY PSW0.7 Carry Flag
AC PSW0.6 Auxiliary Carry Flag
F0 PSW0.5 Flag 0 available for general purpose.
RS1 PSW0.4 Register Bank select bit 1
RS0 PSW0.3 Register bank select bit 0
OV PSW0.2 Overflow flag
PSW0.1 User definable flag
P PSW0.0 Parity flag .set/cleared by hardware.
P → Parity flag → PSW 0.0
Odd number of 1 in ACC, P=1
Even number of 1 in ACC, P=0
• OV (PSW 0.2) → overflow flag → this is used to detect error in signed arithmetic operation.
The bits PSW3 and PSW4 are denoted as RS0 and RS1 and these bits are used to select the bank
registers of the RAM location.
The selection of the register Banks and their addresses are given below.

Initially by default always Bank 0 is selected.


• F0 → user definable bit
• AC → Auxiliary carry flag → when carry is generated from D3 to D4, it is set to 1 and it is used
in BCD arithmetic.

Since carry is generated from D3 to D4, so AC is set.


•CY → carry flag → Affected after 8 bit addition and subtraction. It is used to detect error in
unsigned arithmetic operation. We can also use it as single bit storage.
SETB C → for cy = 1
CLR C → for cy = 0
Q8. Draw and explain the memory organization of 8051 Microcontroller.

Working Registers
Register Banks: 00h to 1Fh. The 8051 uses 8 general-purpose registers R0 through
R7 (R0, R1, R2, R3, R4, R5, R6, and R7). There are four such register banks.
Selection of register bank can be done through RS1,RS0 bits of PSW. On reset, the
default Register Bank 0 will be selected.
Bit Addressable RAM: 20h to 2Fh . The 8051 supports a special feature which allows
access to bit variables. This is where individual memory bits in Internal RAM can be set or
cleared. In all there are 128 bits numbered 00h to 7Fh. Being bit variables any one variable
can have a value 0 or 1. A bit variable can be set with a command such as SETB and cleared
with a command such as CLR.
Internal RAM organization
R7 1F
R6 1E
R5 1D
BANK 3

7F 78 7F
R4 1C
R3 1B
2F
77 70 7E
2E
R2 1A
6F 68 .
R1 19 2D
R0 18 67 60 .
.
2C
R7 17 5F 58
R6 16 2B
57 50
.
R5 15
BANK 2

R4 14
2A
4F 48
.
R3 13
29
47 40
.
R2 12
28
3F 38
.
R1 11 27
.
R0 10 26
37 30
R7 0F 2F 28 32
R6 0E 25

R5 0D 24
27 20 31
BANK 1

R4 0C 23 1F 18 30
R3 0B 17 10
R2 0A 22

R1 09 21 0F 08
R0 08 20 07 00 General purpose memory
R7 07
R6 06
R5 05
BANK 0

R4 04
R3 03 Bit addressable memory
R2 02
R1 01
R0 00
Example instructions are:
SETB 25h ; sets the bit 25h (becomes 1)
CLR 25h ; clears bit 25h (becomes 0)
Note, bit 25h is actually bit 5 of Internal RAM location 24h.
The Bit Addressable area of the RAM is just 16 bytes of Internal RAM located between 20h
and 2Fh.
General Purpose RAM: 30h to 7Fh. Even if 80 bytes of Internal RAM
memory are available for general-purpose data storage, user should take care
while using the memory location from 00 -2F. since these locations are also the
default register space, stack space, and bit addressable space. It is a good
practice to use general purpose memory from 30 – 7Fh. The general purpose
RAM can be accessed using direct or indirect addressing modes.
Q9. Interfacing of 16 K Byte of RAM and 32 K Byte of EPROM to 8051

Number of address lines required for 16 Kbyte memory is 14 lines and that of
32Kbytes of memory is 15 lines.

The connections of external memory is shown below.

PSEN PSEN
A14 A14
A13 A13
A13
A12 A12
A12
… .. 32
A9 .
A8
A8
. Kbyte
WE
WR
OE
16 .
RAM
RD
AL A7 Kbyte A3
LE A2
8051 A0-A7
.. RAM A0-A7 A1
A1
A0
A0
LOWER BYTE
EA ADDRESS
GND [AD0 – AD7] DAT DAT
A A
O/P O/P

AD0
- DATA BUS [AD0 –
AD7 AD7]

The lower order address and data bus are multiplexed. De-multiplexing is done by the
latch. Initially the address will appear in the bus and this latched at the output of latch
using ALE signal. The output of the latch is directly connected to the lower byte
address lines of the memory. Later data will be available in this bus. Still the latch
output is address itself. The higher byte of address bus is directly connected to the
memory. The number of lines connected depends on the memory size.

The RD and WR (both active low) signals are connected to RAM for reading and writing the data.

PSEN of microcontroller is connected to the output enable of the ROM to read the data
from the memory.

EA (active low) pin is always grounded if we use only external memory. Otherwise,
once the program size exceeds internal memory the microcontroller will automatically
switch to external memory.

Q10. What is STACK explain with an example

A stack is a last in first out memory. In 8051 internal RAM space can be used as stack. The
address of the stack is contained in a register called stack pointer. Instructions PUSH and
POP are used for stack operations. When a data is to be placed on the stack, the stack
pointer increments before storing the data on the stack so that the stack grows up as data is
stored (pre-increment). As the data is retrieved from the stack the byte is read from the
stack, and then SP decrements to point the next available byte of stored data (post
decrement). The stack pointer is set to 07 when the 8051 resets. So that default stack
memory starts from address location 08 onwards (to avoid overwriting the default register
bank ie., bank 0).

Eg; Show the stack and SP for the following.

[SP]=07 //CONTENT OF SP IS 07 (DEFAULT VALUE)


MOV R6, #25H [R6]=25H //CONTENT OF R6 IS 25H
MOV R1, #12H [R1]=12H //CONTENT OF R1 IS 12H
MOV R4, [R4]=F3H //CONTENT OF R4 IS F3H
#0F3H
PUSH 6 [SP]=08 [08]=[06]=25H //CONTENT OF 08 IS 25H
PUSH 1 [SP]=09 [09]=[01]=12H //CONTENT OF 09 IS 12H
PUSH 4 [SP]=0A [0A]=[04]=F3H //CONTENT OF 0A IS F3H

POP 6 [06]=[0A]=F3H [SP]=09 //CONTENT OF 06 IS F3H


POP 1 [01]=[09]=12H [SP]=08 //CONTENT OF 01 IS 12H
POP 4 [04]=[08]=25H [SP]=07 //CONTENT OF 04 IS 25H
Q11. Explain Port-0 of 8051 Microcontroller.

Port-0 Pin Structure:

Port 0 has 8 pins (P0.0-P0.7).


The structure of a Port-0 pin is shown in figure below.

Each port of 8051 has bidirectional capability. Port 0 is called 'true bidirectional port' as it floats
(tristated) when configured as input. Port -1, 2, 3 are called 'quasi bidirectional port'.

Port-0 can be configured 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 normal bidirectional I/O 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 floats. This high impedance
pin can be pulled up or low by an external source. When the port is used as an output port, a '1'
written to the latch again turns 'off' both the output MOSFETs and causes the output pin to float. An
external pull-up is required to output a '1'. But when '0' is written to the latch, the pin is pulled down
by the lower MOSFET. Hence the output becomes zero.

When the control is '1', address/data bus controls the output driver MOSFETs. If the address/data bus
(internal) is '0', the upper MOSFET is 'off' and the lower MOSFET is 'on'. The output becomes '0'. If
the address/data bus is '1', the upper transistor is 'on' and the lower transistor is 'off'. Hence the
output is '1'. Hence for normal address/data interfacing (for external memory access) no pull-up
resistors are required.

Port-0 latch is written to with 1's when used for external memory access.
Q12. Explain Port-1 of 8051 Microcontroller.
Port-1 Pin Structure
Port-1 has 8 pins (P1.1-P1.7) .The structure of a port-1 pin is shown in figure below.

Port-1 does not have any alternate function i.e. it is dedicated solely for I/O interfacing. When
used as output port, the pin is pulled up or down through internal pull-up. To use port-1 as input
port, '1' has to be written to the latch. In this input mode when '1' is written to the pin by the
external device then it read 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.

Q13. Explain Port-2 of 8051 Microcontroller.


PORT 2 Pin Structure
Port-2 has 8-pins (P2.0-P2.7) . The structure of a port-2 pin is shown in figure below.
Port-2 is used for higher external address byte or a normal input/output port. The I/O operation is
similar to Port-1. Port-2 latch remains stable when Port-2 pin are used for external memory access.
Here again due to internal pull-up there is limited current driving capability.

Q14. Explain Port-3 of 8051 Microcontroller.


PORT 3 Pin Structure
Port-3 has 8 pin (P3.0-P3.7) . Port-3 pins have alternate functions. The structure of a port-3 pin is

shown in figure below.

Each pin of Port-3 can be individually programmed for I/O operation or for alternate function. The
alternate function can be activated only if the corresponding latch has been written to '1'. To use the
port as input port, '1' should be written to the latch. This port also has internal pull-up and limited
current driving capability.

Alternate functions of Port-3 pins are

P3.0 RxD
P3.1 TxD
P3.2
P3.3
P3.4 T0
P3.5 T1
P3.6
P3.7

Port 1, 2, 3 each can drive 4 LS TTL inputs.

Port-0 can drive 8 LS TTL inputs in address /data mode. For digital output port, it needs external
pull-up resistors.

Ports-1,2and 3 pins can also be driven by open-collector or open-drain outputs.

Each Port 3 bit can be configured either as a normal I/O or as a special function bit.

Q. 15. Reading a port (port-pins) versus reading a latch


There is a subtle difference between reading a latch and reading the output port pin.

The status of the output port pin is sometimes dependant on the connected load. For instance if a
port is configured as an output port and a '1' is written to the latch, the output pin should also show
'1'. If the output is used to drive the base of a transistor, the transistor turns 'on'.

If the port pin is read, the value will be '0' which is corresponding to the base-emitter voltage of
the transistor.

Reading a latch: Usually the instructions that read the latch, read a value, possibly change it, and
then rewrite it to the latch. These are called "read-modify-write" instructions. Examples of a few
instructions are-
ORL P2, A; P2 <-- P2 or A

MOV P2.1, C; Move carry bit to PX.Y bit.


In this the latch value of P2 is read, is modified such that P2.1 is the same as Carry and is then
written back to P2 latch.
Reading a Pin: Examples of a few instructions that read port pin, are-

MOV A, P0 ; Move port-0 pin values to A

MOV A, P1; Move port-1 pin values to A


Q16. Explain special function registers in 8051 Microcontroller

In 8051 microcontroller there certain registers which uses the RAM addresses from 80h to FFh and
they are meant for certain specific operations .These registers are called Special function registers
(SFRs).Some of these registers are bit addressable also. The list of SFRs and their functional names
are given below. In these SFRs some of them are related to I/O ports (P0,P1,P2 and P3) and some of
them are meant for control operations (TCON,SCON, PCON..) and remaining are the auxiliary
SFRs, in the sense that they don't directly configure the 8051.
Q. 17 Write a note on ports of 8051 Microcontroller.

The 8051 microcontroller has four parallel I/O ports , each of 8-bits .So, it provides the user 32 I/O
lines for connecting the microcontroller to the peripherals. The four ports are P0 (Port 0), P1(Port1)
,P2(Port 2) and P3 (Port3). Upon reset all the ports are output ports. In order to make them input, all
the ports must be set i.e a high bit must be sent to all the port pins. This is normally done by the
instruction “SETB”.

Ex: MOV A,#0FFH ; A = FF

MOV P0, A ; make P0 an input port

PORT 0:
Port 0 is an 8-bit I/O port with dual purpose. If external memory is used, these port pins are used for
the lower address byte address/data (AD0-AD7), otherwise all bits of the port are either input or
output. Unlike other ports, Port 0 is not provided with pull-up resistors internally ,so for PORT0
pull-up resistors of nearly 10k are to be connected externally as shown in the fig.2.
Dual role of port 0:
Port 0 can also be used as address/data bus (AD0-AD7), allowing it to be used for both address and
data. When connecting the 8051 to an external memory, port 0 provides both address and data. The
8051 multiplexes address and data through port 0 to save the pins. ALE indicates whether P0 has
address or data. When ALE = 0, it provides data D0-D7, and when ALE =1 it provides address and
data with the help of a 74LS373 latch.
Port 1:
Port 1 occupies a total of 8 pins (pins 1 through 8). It has no dual application and acts only as input
or output port. In contrast to port 0, this port does not need any pull-up resistors since pull-up
resistors connected internally. Upon reset, Port 1 is configured as an output port. To configure it as
an input port, port bits must be set i.e a high bit must be sent to all the port pins. This is normally
done by the instruction “SETB”.
For Ex: MOV A, #0FFH ; A=FF HEX
MOV P1, A ; make P1 an input port by writing 1’s to all of its pins
Port 2 :
Port 2 is also an eight bit parallel port. (pins 21- 28). It can be used as input or output port. As this
port is provided with internal pull-up resistors it does not need any external pull-up resistors. Upon
reset, Port 2 is configured as an output port. If the port is to be used as input port, all the port bits
must be made high by sending FF to the port. For ex, MOV A, #0FFH ; A=FF hex MOV P2, A ;
make P2 an input port by writing all 1’s to it .

Dual role of port 2:


Port2 lines are also associated with the higher order address lines A8-A15. In systems based on the
8751, 8951, and DS5000, Port2 is used as simple I/O port.. But, in 8031-based systems, port 2 is
used along with P0 to provide the 16-bit address for the external memory. Since an 8031 is capable
of accessing 64K bytes of external memory, it needs a path for the 16 bits of the address. While P0
provides the lower 8 bits via A0-A7, it is the job of P2 to provide bits A8-A15 of the address. In
other words, when 8031 is connected to external memory, Port 2 is used for the upper 8 bits of the
16 bit address, and it cannot be used for I/O operations.

PORT 3:
Port3 is also an 8-bit parallel port with dual function.( pins 10 to 17). The port pins can be used for
I/O operations as well as for control operations. The details of these additional operations are given
below in the table. Port 3 also do not need any external pull-up resistors as they are provided
internally similar to the case of Port2 & Port 1. Upon reset port 3 is configured as an output port . If
the port is to be used as input port, all the port bits must be made high by sending FF to the port.
For ex, MOV A, #0FFH ; A= FF hex MOV P3, A ; make P3 an input port by writing all 1’s to it
Alternate Functions of Port 3:

You might also like