SlideShare a Scribd company logo
I/O PORT
PROGRAMMING
by
E.M.Roopa Devi
Kongu Engineering College
I/O Port Pins
 The four 8-bit I/O ports P0, P1, P2 and
P3 each uses 8 pins
 All the ports upon RESET are
configured as input, ready to be used
as input ports
◦ When the first 0 is written to a port, it
becomes an output
◦ To reconfigure it as an input, a 1 must be
sent to the port
◦ To use any of these ports as an input port,
it must be programmed
Pin 29 (PSEN): This pin is used to enable external program memory.
If we use an external ROM for storing the program, then logic 0
appears on it, which indicates Micro controller to read data from the
memory.
Port 0
 It can be used for input or output
◦ Each pin must be connected externally to
a 10K ohm pull-up resistor
 This is due to the fact that P0 is an open drain,
unlike P1, P2, and P3
 Open drain is a term used for MOS chips in the same
way that open collector is used for TTL chips
Port 0 (cont.)
Port 0 as Input
 In order to make port 0 an input, the
port must be programmed by writing 1
to all the bits
I/O Port Cell
Dual Role of Port 0
 Port 0 is also designated as AD0-AD7
◦ Allowing it to be used for both address
and data
◦ When connecting an 8051/31 to an
external memory, port 0 provides both
address and data
Port 1
 Port 1 can be used as input or output
◦ In contrast to port 0, this port does not
need any pull-up resistors since it already
has pull-up resistors internally
◦ Upon reset, port 1 is configured as an
input port
Port 1 as Input
 To make port 1 an input port, it must
be programmed as such by writing 1
to all its bits
Port 2
 Port 2 can be used as input or output
◦ Just like port 1, port 2 does not need any
pull-up resistors since it already has pull-
up resistors internally
◦ Upon reset, port 2 is configured as an
input port
Port 2 as Input or Dual Role
 To make port 2 an input port, it must
be programmed as such by writing 1
to all its bits
◦ In many 8051-based system, P2 is used
as simple I/O
◦ In 8031-based systems, port 2 must be
used along with P0 to provide the 16-bit
address for the external memory
 Port 2 is also designated as A8 – A15
 Port 0 provides the lower 8 bits via A0 – A7
Port 3
 Port 3 can be used as input or output
◦ Port 3 does not need any pull-up resistors
◦ Port 3 is configured as an input port upon
reset
 This is not the way it is most commonly used
 Port 3 has the additional function of
providing some extremely important
signals
Port 3 (cont.)
Different ways of Accessing
Entire 8 Bits
I/O Ports and Bit Addressability
 Sometimes we need to access only 1
or 2 bits of the port
I/O Ports and Bit Addressability
(cont.)
 Instructions that are used for signal-bit
operations are as following:
Checking an Input Bit
 The JNB and JB instructions are
widely used single-bit operations
◦ They allow you to monitor a bit and make
a decision depending on whether it’s 0 or
1
◦ These two instructions can be used for
any bits of I/O ports 0, 1, 2, and 3
◦ Port 3 is typically not used for any I/O,
either single-bit or byte-wise
7
7
0 0
Reading Input Pins vs. Port
Latch
 In reading a port
◦ Some instructions read the status of port
pins
◦ Others read the status of an internal port
latch
◦ When reading ports there are two
possibilities:
 Read the status of the input pin
 Read the internal latch of the output port
 Confusion between them is a major source of errors in
8051 programming
 Especially where external hardware is concerned
Reading Latch for Output Port
 Some instructions read the contents of
an internal port latch instead of
reading the status of an external pin
◦ For example, look at the ANL P1,A
instruction and the sequence of actions is:
 It reads the internal latch of the port and brings
that data into the CPU
 This data is ANDed with the contents of register
A
 The result is rewritten back to the port latch
 The port pin data is changed and now has the
same value as port latch
Reading Latch for Output Port
(cont.)
 Read-Modify-Write
◦ The instructions read the port latch
normally read a value, perform an
operation then rewrite it back to the port
latch
Read-modify-write Feature
 The ports in 8051 can be accessed by
the Read-modify-write technique
◦ This feature saves many lines of code by
combining in a single instruction all three
actions
 Reading the port
 Modifying it
 Writing to the port

More Related Content

What's hot

I o ports.ppt
I o ports.pptI o ports.ppt
I o ports.ppt
Pradeep V Dev
 
8051 block diagram
8051 block diagram8051 block diagram
8051 block diagram
DominicHendry
 
Serial Communication
Serial CommunicationSerial Communication
Serial Communication
UshaRani289
 
8086 micro processor
8086 micro processor8086 micro processor
8086 micro processor
Poojith Chowdhary
 
8051 Microcontroller I/O ports
8051 Microcontroller I/O ports8051 Microcontroller I/O ports
8051 Microcontroller I/O ports
anishgoel
 
8051 instruction set
8051 instruction set8051 instruction set
8051 instruction set
Andri Prastiyo
 
Digital electronics logic families
Digital electronics logic familiesDigital electronics logic families
Digital electronics logic families
BLESSINAR0
 
Interfacing Stepper motor with 8051
Interfacing Stepper motor with 8051Interfacing Stepper motor with 8051
Interfacing Stepper motor with 8051
Pantech ProLabs India Pvt Ltd
 
8051 Addressing Modes
8051 Addressing Modes8051 Addressing Modes
8051 Addressing Modes
Senthil Kumar
 
8051 Microcontroller ppt
8051 Microcontroller ppt8051 Microcontroller ppt
8051 Microcontroller ppt
Rahul Kumar
 
LCD Interacing with 8051
LCD Interacing with 8051LCD Interacing with 8051
LCD Interacing with 8051
Sudhanshu Janwadkar
 
Microprocessor 8085 complete
Microprocessor 8085 completeMicroprocessor 8085 complete
Microprocessor 8085 complete
Shubham Singh
 
8051 assembly programming
8051 assembly programming8051 assembly programming
8051 assembly programming
sergeiseq
 
8051 Assembly Language Programming
8051 Assembly Language Programming8051 Assembly Language Programming
8051 Assembly Language Programming
Ravikumar Tiwari
 
Intel 8259 - Programmable Interrupt Controller
Intel 8259 - Programmable Interrupt Controller  Intel 8259 - Programmable Interrupt Controller
Intel 8259 - Programmable Interrupt Controller
Nikhil Baby
 
8086 modes
8086 modes8086 modes
8086 modes
PDFSHARE
 
Keypad Interfacing with 8051 Microcontroller
Keypad Interfacing with 8051 MicrocontrollerKeypad Interfacing with 8051 Microcontroller
Keypad Interfacing with 8051 Microcontroller
Sudhanshu Janwadkar
 
Timer And Counter in 8051 Microcontroller
Timer And Counter in 8051 MicrocontrollerTimer And Counter in 8051 Microcontroller
Timer And Counter in 8051 Microcontroller
Jay Makwana
 
Addressing modes of 8051
Addressing modes of 8051Addressing modes of 8051
Addressing modes of 8051
SARITHA REDDY
 
8255 PPI
8255 PPI8255 PPI
8255 PPI
deval patel
 

What's hot (20)

I o ports.ppt
I o ports.pptI o ports.ppt
I o ports.ppt
 
8051 block diagram
8051 block diagram8051 block diagram
8051 block diagram
 
Serial Communication
Serial CommunicationSerial Communication
Serial Communication
 
8086 micro processor
8086 micro processor8086 micro processor
8086 micro processor
 
8051 Microcontroller I/O ports
8051 Microcontroller I/O ports8051 Microcontroller I/O ports
8051 Microcontroller I/O ports
 
8051 instruction set
8051 instruction set8051 instruction set
8051 instruction set
 
Digital electronics logic families
Digital electronics logic familiesDigital electronics logic families
Digital electronics logic families
 
Interfacing Stepper motor with 8051
Interfacing Stepper motor with 8051Interfacing Stepper motor with 8051
Interfacing Stepper motor with 8051
 
8051 Addressing Modes
8051 Addressing Modes8051 Addressing Modes
8051 Addressing Modes
 
8051 Microcontroller ppt
8051 Microcontroller ppt8051 Microcontroller ppt
8051 Microcontroller ppt
 
LCD Interacing with 8051
LCD Interacing with 8051LCD Interacing with 8051
LCD Interacing with 8051
 
Microprocessor 8085 complete
Microprocessor 8085 completeMicroprocessor 8085 complete
Microprocessor 8085 complete
 
8051 assembly programming
8051 assembly programming8051 assembly programming
8051 assembly programming
 
8051 Assembly Language Programming
8051 Assembly Language Programming8051 Assembly Language Programming
8051 Assembly Language Programming
 
Intel 8259 - Programmable Interrupt Controller
Intel 8259 - Programmable Interrupt Controller  Intel 8259 - Programmable Interrupt Controller
Intel 8259 - Programmable Interrupt Controller
 
8086 modes
8086 modes8086 modes
8086 modes
 
Keypad Interfacing with 8051 Microcontroller
Keypad Interfacing with 8051 MicrocontrollerKeypad Interfacing with 8051 Microcontroller
Keypad Interfacing with 8051 Microcontroller
 
Timer And Counter in 8051 Microcontroller
Timer And Counter in 8051 MicrocontrollerTimer And Counter in 8051 Microcontroller
Timer And Counter in 8051 Microcontroller
 
Addressing modes of 8051
Addressing modes of 8051Addressing modes of 8051
Addressing modes of 8051
 
8255 PPI
8255 PPI8255 PPI
8255 PPI
 

Similar to I/O port programming in 8051

I o ports and timers of 8051
I o ports and timers of 8051I o ports and timers of 8051
I o ports and timers of 8051
SARITHA REDDY
 
SE PAI Unit 5_IO programming in 8051
SE PAI Unit 5_IO programming in 8051SE PAI Unit 5_IO programming in 8051
SE PAI Unit 5_IO programming in 8051
KanchanPatil34
 
8051 book
8051 book8051 book
MICROCONTROLLER .pptx
MICROCONTROLLER .pptxMICROCONTROLLER .pptx
MICROCONTROLLER .pptx
ArulMozhie1
 
Port Organization of 8051 .pdf
Port Organization of 8051 .pdfPort Organization of 8051 .pdf
Port Organization of 8051 .pdf
Srikrishna Thota
 
Embedded System Microcontroller 8051
Embedded System Microcontroller 8051Embedded System Microcontroller 8051
Embedded System Microcontroller 8051
ShawnIslam20150022
 
8051 i o port circuit
8051 i o port circuit8051 i o port circuit
8051 i o port circuit
dharmendrawaghjipur007
 
8051 i/o port circuit
8051 i/o port circuit8051 i/o port circuit
8051 i/o port circuit
dharmendrawaghjipur007
 
Embedded systems io programming
Embedded systems   io programmingEmbedded systems   io programming
Embedded systems io programming
imtiazalijoono
 
Microcontroller (1).pptx
Microcontroller (1).pptxMicrocontroller (1).pptx
Microcontroller (1).pptx
ITPradiptaRoy
 
EMBEDDED SYSTEMS 5
EMBEDDED SYSTEMS 5EMBEDDED SYSTEMS 5
EMBEDDED SYSTEMS 5
PRADEEP
 
Hardware View of Intel 8051
Hardware View of Intel 8051Hardware View of Intel 8051
Hardware View of Intel 8051
Sudhanshu Janwadkar
 
Hardware interfacing basics using AVR
Hardware interfacing basics using AVRHardware interfacing basics using AVR
Hardware interfacing basics using AVR
Mohamed Abdallah
 
8255_Ppi new
8255_Ppi new8255_Ppi new
8255_Ppi new
Monica Gunjal
 
8051 architecture
8051 architecture8051 architecture
8051 architecture
sb108ec
 
Ch3 ppt
Ch3 pptCh3 ppt
Ch3 ppt
wasz123
 
8051 Microcontroller -1.pptx
8051 Microcontroller -1.pptx8051 Microcontroller -1.pptx
8051 Microcontroller -1.pptx
veeramaniks
 
At89 s8252
At89 s8252At89 s8252
8051 microcontroller
8051 microcontroller8051 microcontroller
8051 microcontroller
Thirunavakkarasu kannusamy
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
Rashmi
 

Similar to I/O port programming in 8051 (20)

I o ports and timers of 8051
I o ports and timers of 8051I o ports and timers of 8051
I o ports and timers of 8051
 
SE PAI Unit 5_IO programming in 8051
SE PAI Unit 5_IO programming in 8051SE PAI Unit 5_IO programming in 8051
SE PAI Unit 5_IO programming in 8051
 
8051 book
8051 book8051 book
8051 book
 
MICROCONTROLLER .pptx
MICROCONTROLLER .pptxMICROCONTROLLER .pptx
MICROCONTROLLER .pptx
 
Port Organization of 8051 .pdf
Port Organization of 8051 .pdfPort Organization of 8051 .pdf
Port Organization of 8051 .pdf
 
Embedded System Microcontroller 8051
Embedded System Microcontroller 8051Embedded System Microcontroller 8051
Embedded System Microcontroller 8051
 
8051 i o port circuit
8051 i o port circuit8051 i o port circuit
8051 i o port circuit
 
8051 i/o port circuit
8051 i/o port circuit8051 i/o port circuit
8051 i/o port circuit
 
Embedded systems io programming
Embedded systems   io programmingEmbedded systems   io programming
Embedded systems io programming
 
Microcontroller (1).pptx
Microcontroller (1).pptxMicrocontroller (1).pptx
Microcontroller (1).pptx
 
EMBEDDED SYSTEMS 5
EMBEDDED SYSTEMS 5EMBEDDED SYSTEMS 5
EMBEDDED SYSTEMS 5
 
Hardware View of Intel 8051
Hardware View of Intel 8051Hardware View of Intel 8051
Hardware View of Intel 8051
 
Hardware interfacing basics using AVR
Hardware interfacing basics using AVRHardware interfacing basics using AVR
Hardware interfacing basics using AVR
 
8255_Ppi new
8255_Ppi new8255_Ppi new
8255_Ppi new
 
8051 architecture
8051 architecture8051 architecture
8051 architecture
 
Ch3 ppt
Ch3 pptCh3 ppt
Ch3 ppt
 
8051 Microcontroller -1.pptx
8051 Microcontroller -1.pptx8051 Microcontroller -1.pptx
8051 Microcontroller -1.pptx
 
At89 s8252
At89 s8252At89 s8252
At89 s8252
 
8051 microcontroller
8051 microcontroller8051 microcontroller
8051 microcontroller
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
 

More from ssuser3a47cb

BCT.pptx
BCT.pptxBCT.pptx
BCT.pptx
ssuser3a47cb
 
Uunit 5-xml&web security
Uunit 5-xml&web securityUunit 5-xml&web security
Uunit 5-xml&web security
ssuser3a47cb
 
Unit 4-SOA governance
Unit 4-SOA governanceUnit 4-SOA governance
Unit 4-SOA governance
ssuser3a47cb
 
Unit 3-SOA Technologies
Unit 3-SOA TechnologiesUnit 3-SOA Technologies
Unit 3-SOA Technologies
ssuser3a47cb
 
Unit 2 -SOA design
Unit 2 -SOA designUnit 2 -SOA design
Unit 2 -SOA design
ssuser3a47cb
 
Soa 1 7.ppsx
Soa 1 7.ppsxSoa 1 7.ppsx
Soa 1 7.ppsx
ssuser3a47cb
 
Java swing
Java swingJava swing
Java swing
ssuser3a47cb
 
Java networking
Java networkingJava networking
Java networking
ssuser3a47cb
 
Interfacing external memory in 8051
Interfacing external memory in 8051Interfacing external memory in 8051
Interfacing external memory in 8051
ssuser3a47cb
 
Interrupt in 8051
Interrupt in 8051Interrupt in 8051
Interrupt in 8051
ssuser3a47cb
 

More from ssuser3a47cb (10)

BCT.pptx
BCT.pptxBCT.pptx
BCT.pptx
 
Uunit 5-xml&web security
Uunit 5-xml&web securityUunit 5-xml&web security
Uunit 5-xml&web security
 
Unit 4-SOA governance
Unit 4-SOA governanceUnit 4-SOA governance
Unit 4-SOA governance
 
Unit 3-SOA Technologies
Unit 3-SOA TechnologiesUnit 3-SOA Technologies
Unit 3-SOA Technologies
 
Unit 2 -SOA design
Unit 2 -SOA designUnit 2 -SOA design
Unit 2 -SOA design
 
Soa 1 7.ppsx
Soa 1 7.ppsxSoa 1 7.ppsx
Soa 1 7.ppsx
 
Java swing
Java swingJava swing
Java swing
 
Java networking
Java networkingJava networking
Java networking
 
Interfacing external memory in 8051
Interfacing external memory in 8051Interfacing external memory in 8051
Interfacing external memory in 8051
 
Interrupt in 8051
Interrupt in 8051Interrupt in 8051
Interrupt in 8051
 

Recently uploaded

Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
Mahmoud Morsy
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
co23btech11018
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
171ticu
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
gowrishankartb2005
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
Prakhyath Rai
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
21UME003TUSHARDEB
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
ElakkiaU
 
Applications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdfApplications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdf
Atif Razi
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
cnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classicationcnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classication
SakkaravarthiShanmug
 
Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
Divyanshu
 
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURSCompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
RamonNovais6
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
TaghreedAltamimi
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
Data Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason WebinarData Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason Webinar
UReason
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
Data Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptxData Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptx
ramrag33
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 

Recently uploaded (20)

Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
 
Applications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdfApplications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdf
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
cnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classicationcnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classication
 
Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
 
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURSCompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
Data Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason WebinarData Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason Webinar
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
Data Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptxData Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptx
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 

I/O port programming in 8051

  • 2. I/O Port Pins  The four 8-bit I/O ports P0, P1, P2 and P3 each uses 8 pins  All the ports upon RESET are configured as input, ready to be used as input ports ◦ When the first 0 is written to a port, it becomes an output ◦ To reconfigure it as an input, a 1 must be sent to the port ◦ To use any of these ports as an input port, it must be programmed
  • 3.
  • 4. Pin 29 (PSEN): This pin is used to enable external program memory. If we use an external ROM for storing the program, then logic 0 appears on it, which indicates Micro controller to read data from the memory.
  • 5. Port 0  It can be used for input or output ◦ Each pin must be connected externally to a 10K ohm pull-up resistor  This is due to the fact that P0 is an open drain, unlike P1, P2, and P3  Open drain is a term used for MOS chips in the same way that open collector is used for TTL chips
  • 7. Port 0 as Input  In order to make port 0 an input, the port must be programmed by writing 1 to all the bits
  • 9. Dual Role of Port 0  Port 0 is also designated as AD0-AD7 ◦ Allowing it to be used for both address and data ◦ When connecting an 8051/31 to an external memory, port 0 provides both address and data
  • 10. Port 1  Port 1 can be used as input or output ◦ In contrast to port 0, this port does not need any pull-up resistors since it already has pull-up resistors internally ◦ Upon reset, port 1 is configured as an input port
  • 11. Port 1 as Input  To make port 1 an input port, it must be programmed as such by writing 1 to all its bits
  • 12. Port 2  Port 2 can be used as input or output ◦ Just like port 1, port 2 does not need any pull-up resistors since it already has pull- up resistors internally ◦ Upon reset, port 2 is configured as an input port
  • 13. Port 2 as Input or Dual Role  To make port 2 an input port, it must be programmed as such by writing 1 to all its bits ◦ In many 8051-based system, P2 is used as simple I/O ◦ In 8031-based systems, port 2 must be used along with P0 to provide the 16-bit address for the external memory  Port 2 is also designated as A8 – A15  Port 0 provides the lower 8 bits via A0 – A7
  • 14. Port 3  Port 3 can be used as input or output ◦ Port 3 does not need any pull-up resistors ◦ Port 3 is configured as an input port upon reset  This is not the way it is most commonly used  Port 3 has the additional function of providing some extremely important signals
  • 16.
  • 17. Different ways of Accessing Entire 8 Bits
  • 18. I/O Ports and Bit Addressability  Sometimes we need to access only 1 or 2 bits of the port
  • 19.
  • 20.
  • 21. I/O Ports and Bit Addressability (cont.)  Instructions that are used for signal-bit operations are as following:
  • 22. Checking an Input Bit  The JNB and JB instructions are widely used single-bit operations ◦ They allow you to monitor a bit and make a decision depending on whether it’s 0 or 1 ◦ These two instructions can be used for any bits of I/O ports 0, 1, 2, and 3 ◦ Port 3 is typically not used for any I/O, either single-bit or byte-wise
  • 23.
  • 24.
  • 25. 7
  • 26. 7
  • 27. 0 0
  • 28. Reading Input Pins vs. Port Latch  In reading a port ◦ Some instructions read the status of port pins ◦ Others read the status of an internal port latch ◦ When reading ports there are two possibilities:  Read the status of the input pin  Read the internal latch of the output port  Confusion between them is a major source of errors in 8051 programming  Especially where external hardware is concerned
  • 29. Reading Latch for Output Port  Some instructions read the contents of an internal port latch instead of reading the status of an external pin ◦ For example, look at the ANL P1,A instruction and the sequence of actions is:  It reads the internal latch of the port and brings that data into the CPU  This data is ANDed with the contents of register A  The result is rewritten back to the port latch  The port pin data is changed and now has the same value as port latch
  • 30. Reading Latch for Output Port (cont.)  Read-Modify-Write ◦ The instructions read the port latch normally read a value, perform an operation then rewrite it back to the port latch
  • 31. Read-modify-write Feature  The ports in 8051 can be accessed by the Read-modify-write technique ◦ This feature saves many lines of code by combining in a single instruction all three actions  Reading the port  Modifying it  Writing to the port