You are on page 1of 22

The 8051 C

Port Internal
Structure

Lecture 5

1 of 21
Block Diagram

2 of 21
PORT INTERNAL STRUCTURE
Theportstructureisshownbelow.

Theportconsistsofalatch,atransistorandtwotristate buffersTB1and
TB2.
3 of 21
PORT INTERNAL STRUCTURE

4 of 21
Output(High)
Thefollowingshowstheworkingofaportwhensendinga
Highoutput

Anopentransistorensuresthatnocurrentflowsthuspingets
aHighValue.
5 of 21
Output(Low)
Theclosedstateoftransistor,bringsalowvalueonportpinand
consequentlythecurrentflowsfromnodeAtonodeBviatheload.

6 of 21
HowtomakePortInput

The port is made


input by writing a 1
on the internal CPU
bus initially. This
switches off(opens)
the transistor thus
transferring the
logic from the port
pin to the internal
CPU bus via TB1.

7 of 21
Input(High)

8 of 21
Input(Low)

9 of 21
NeverUseaPortforInputwithout
WritingaHighValueFirst!!
Why?

10 of 21
NeverUseaPortforInputwithout
WritingaHighValueFirst!!

11 of 21
AvoidDamagingthePORT(1)

InputSwitchwithnoVcc

Node A

12 of 21
AvoidDamagingthePORT(2)
InputSwitchwithPullUpResistor

Node A

13 of 21
AvoidDamagingthePORT(3)
InputSwitchwithTristateBuffer

Node A

14 of 21
Readinginputpinsvs.portlatch
Someinstructionsreadthestatusofportpins
whileothersreadthestatusofaninternalport
latch.
Whenreadingportstherearetwopossibilities:
Readthestatusoftheinputpin.
Readtheinternallatchoftheoutputport.

15
15 of 21
ReadingtheStatusofPin
InstructionsReadingtheStatusofInputPort

16 of 21
ReadingLatchInsteadofReadingPin
Considerthecaseofreadingtheportwhereitreadstheinternalport
latch.
"ANLPI,A"isanexampleofaninstructionthatreadsthelatch
insteadoftheinputpin.Lookatthesequenceofactionstakingplace
whenaninstructionsuchas"ANLPI,A"isexecuted. Thereadlatch
activatesthetristatebufferofTB2andbringsthedatafromtheQ
latchintotheCPU.ThisdataisANDedwiththecontentsofregisterA.
Theresultisrewrittentothelatch.

17 of 21
ReadingLatchInsteadofReadingPin
The instruction that reads the latch normally reads a value,
performs an operation (possibly changing the value), and
rewrites the value to the latch. This is often called "read-modify-
write. Table below provides a list of read-modify-write
instructions. Notice from table that all the read-modify-write
instructions use the port as the destination operand (OUTPUT).
These inst will only be used when port is configured as output.

18 of 21
ReadingLatchInsteadofReadingPin

When we set the port bits to high, that doesn't mean that the processor actually
manages to hold them high. If the port pin is connected to the output of another
chip, that other chip may drive the signal low.
19 of 21
PullupresistorbankforPort0
P0 is open drain. (Open drain is a term used for MOS chips in the same way that
open collector is used for TTL chips)

The pullup resistor is absent on Port 0.

When a "0" is written to a bit in port 0, the pin is pulled low. But when a "1" is
written to it, it is in high impedance (disconnected) state.

20 of 21
PullupresistorbankforPort0
when using port 0 for output, an external pullup resistor may be needed,

depending on the input characteristics of the device driven by the port pin.

21 of 21
PullupresistorbankforPort0
Typical values for pullups might be 470 ohm to drive a LED, and 4.7K or higher to

drive logic circuits .

Youcanuseaportforoutputanytime.Butforinput,theFETmustbeoff.

1shouldbewrittentothepinifyouwanttouseitasinput,especiallywhen

youhaveuseditforoutputbefore.Thelatchissethighonresetsoyoudon't

needtowrite.

22 of 21

You might also like