SlideShare una empresa de Scribd logo
1 de 7
Descargar para leer sin conexión
Embedded Systems - I/O Programming
Embedded Systems - I/O Programming
In 8051, I/O operations are done using four ports and 40 pins. The following pin diagram shows the details
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
of the 40 pins. I/O operation port reserves 32 pins where each port has 8 pins. The other 8 pins are
designated as V
designated as V , GND, XTAL1, XTAL2, RST, EA (bar), ALE/PROG (bar), and PSEN (bar).
, GND, XTAL1, XTAL2, RST, EA (bar), ALE/PROG (bar), and PSEN (bar).
It is a 40 Pin PDIP (Plastic Dual Inline Package)
It is a 40 Pin PDIP (Plastic Dual Inline Package)
Note
Note − In a DIP package, you can recognize the first pin and the last pin by the cut at the middle of the IC.
− In a DIP package, you can recognize the first pin and the last pin by the cut at the middle of the IC.
The first pin is on the left of this cut mark and the last pin (i.e. the 40
The first pin is on the left of this cut mark and the last pin (i.e. the 40 pin in this case) is to the right of the
pin in this case) is to the right of the
cut mark.
cut mark.
I/O Ports and their Functions
I/O Ports and their Functions
The four ports P0, P1, P2, and P3, each use 8 pins, making them 8-bit ports. Upon RESET, all the ports
The four ports P0, P1, P2, and P3, each use 8 pins, making them 8-bit ports. Upon RESET, all the ports
are configured as inputs, ready to be used as input ports. When the first 0 is written to a port, it becomes
are configured as inputs, 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 a port.
an output. To reconfigure it as an input, a 1 must be sent to a port.
Port 0 (Pin No 32 – Pin No 39)
Port 0 (Pin No 32 – Pin No 39)
It has 8 pins (32 to 39). It can be used for input or output. Unlike P1, P2, and P3 ports, we normally
It has 8 pins (32 to 39). It can be used for input or output. Unlike P1, P2, and P3 ports, we normally
connect P0 to 10K-ohm pull-up resistors to use it as an input or output port being an open drain.
connect P0 to 10K-ohm pull-up resistors to use it as an input or output port being an open drain.
cc
cc
th
th
It is also designated as AD0-AD7, allowing it to be used as both address and data. In case of 8031 (i.e.
It is also designated as AD0-AD7, allowing it to be used as both address and data. In case of 8031 (i.e.
ROMless Chip), when we need to access the external ROM, then P0 will be used for both Address and
ROMless Chip), when we need to access the external ROM, then P0 will be used for both Address and
Data Bus. ALE (Pin no 31) indicates if P0 has address or data. When ALE = 0, it provides data D0-D7, but
Data Bus. ALE (Pin no 31) indicates if P0 has address or data. When ALE = 0, it provides data D0-D7, but
when ALE = 1, it has address A0-A7. In case no external memory connection is available, P0 must be
when ALE = 1, it has address A0-A7. In case no external memory connection is available, P0 must be
connected externally to a 10K-ohm pull-up resistor.
connected externally to a 10K-ohm pull-up resistor.
MOV A,#0FFH ;(comments: A=FFH(Hexadecimal i.e. A=1111 1111)
MOV A,#0FFH ;(comments: A=FFH(Hexadecimal i.e. A=1111 1111)
MOV P0,A ;(Port0 have 1's on every pin so that it works as Input)
MOV P0,A ;(Port0 have 1's on every pin so that it works as Input)
Port 1 (Pin 1 through 8)
Port 1 (Pin 1 through 8)
It is an 8-bit port (pin 1 through 8) and can be used either as input or output. It doesn't require pull-up
It is an 8-bit port (pin 1 through 8) and can be used either as input or output. It doesn't require pull-up
resistors because they are already connected internally. Upon reset, Port 1 is configured as an input port.
resistors because they are already connected internally. Upon reset, Port 1 is configured as an input port.
The following code can be used to send alternating values of 55H and AAH to Port 1.
The following code can be used to send alternating values of 55H and AAH to Port 1.
;Toggle all bits of continuously
;Toggle all bits of continuously
MOV A,#55
MOV A,#55
BACK:
BACK:
MOV P2,A
MOV P2,A
ACALL DELAY
ACALL DELAY
CPL A ;complement(invert) reg. A
CPL A ;complement(invert) reg. A
SJMP BACK
SJMP BACK
If Port 1 is configured to be used as an output port, then to use it as an input port again, program it by
If Port 1 is configured to be used as an output port, then to use it as an input port again, program it by
writing 1 to all of its bits as in the following code.
writing 1 to all of its bits as in the following code.
;Toggle all bits of continuously
;Toggle all bits of continuously
MOV A ,#0FFH ;A = FF hex
MOV A ,#0FFH ;A = FF hex
MOV P1,A ;Make P1 an input port
MOV P1,A ;Make P1 an input port
MOV A,P1 ;get data from P1
MOV A,P1 ;get data from P1
MOV R7,A ;save it in Reg R7
MOV R7,A ;save it in Reg R7
ACALL DELAY ;wait
ACALL DELAY ;wait
MOV A,P1 ;get another data from P1
MOV A,P1 ;get another data from P1
MOV R6,A ;save it in R6
MOV R6,A ;save it in R6
ACALL DELAY ;wait
ACALL DELAY ;wait
MOV A,P1 ;get another data from P1
MOV A,P1 ;get another data from P1
MOV R5,A ;save it in R5
MOV R5,A ;save it in R5
Port 2 (Pins 21 through 28)
Port 2 (Pins 21 through 28)
Port 2 occupies a total of 8 pins (pins 21 through 28) and can be used for both input and output
Port 2 occupies a total of 8 pins (pins 21 through 28) and can be used for both input and output
operations. Just as P1 (Port 1), P2 also doesn't require external Pull-up resistors because they are
operations. Just as P1 (Port 1), P2 also doesn't require external Pull-up resistors because they are
already connected internally. It must be used along with P0 to provide the 16-bit address for the external
already connected internally. It must be used along with P0 to provide the 16-bit address for the external
memory. So it is also designated as (A0–A7), as shown in the pin diagram. When the 8051 is connected
memory. So it is also designated as (A0–A7), as shown in the pin diagram. 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.
to an external memory, it provides path for upper 8-bits of 16-bits address, and it cannot be used as I/O.
Upon reset, Port 2 is configured as an input port. The following code can be used to send alternating
Upon reset, Port 2 is configured as an input port. The following code can be used to send alternating
values of 55H and AAH to port 2.
values of 55H and AAH to port 2.
;Toggle all bits of continuously
;Toggle all bits of continuously
MOV A,#55
MOV A,#55
BACK:
BACK:
MOV P2,A
MOV P2,A
ACALL DELAY
ACALL DELAY
CPL A ; complement(invert) reg. A
CPL A ; complement(invert) reg. A
SJMP BACK
SJMP BACK
If Port 2 is configured to be used as an output port, then to use it as an input port again, program it by
If Port 2 is configured to be used as an output port, then to use it as an input port again, program it by
writing 1 to all of its bits as in the following code.
writing 1 to all of its bits as in the following code.
;Get a byte from P2 and send it to P1
;Get a byte from P2 and send it to P1
MOV A,#0FFH ;A = FF hex
MOV A,#0FFH ;A = FF hex
MOV P2,A ;make P2 an input port
MOV P2,A ;make P2 an input port
BACK:
BACK:
MOV A,P2 ;get data from P2
MOV A,P2 ;get data from P2
MOV P1,A ;send it to Port 1
MOV P1,A ;send it to Port 1
SJMP BACK ;keep doing that
SJMP BACK ;keep doing that
Port 3 (Pins 10 through 17)
Port 3 (Pins 10 through 17)
It is also of 8 bits and can be used as Input/Output. This port provides some extremely important signals.
It is also of 8 bits and can be used as Input/Output. This port provides some extremely important signals.
P3.0 and P3.1 are RxD (Receiver) and TxD (Transmitter) respectively and are collectively used for Serial
P3.0 and P3.1 are RxD (Receiver) and TxD (Transmitter) respectively and are collectively used for Serial
Communication. P3.2 and P3.3 pins are used for external interrupts. P3.4 and P3.5 are used for timers T0
Communication. P3.2 and P3.3 pins are used for external interrupts. P3.4 and P3.5 are used for timers T0
and T1 respectively. P3.6 and P3.7 are Write (WR) and Read (RD) pins. These are active low pins, means
and T1 respectively. P3.6 and P3.7 are Write (WR) and Read (RD) pins. These are active low pins, means
they will be active when 0 is given to them and these are used to provide Read and Write operations to
they will be active when 0 is given to them and these are used to provide Read and Write operations to
External ROM in 8031 based systems.
External ROM in 8031 based systems.
P3 Bit
P3 Bit Function
Function Pin
Pin
P3.0
P3.0 RxD
RxD 10
10
P3.1 <
P3.1 < TxD
TxD 11
11
P3.2 <
P3.2 < Complement of INT0
Complement of INT0 12
12
P3.3 <
P3.3 < INT1
INT1 13
13
P3.4 <
P3.4 < T0
T0 14
14
P3.5 <
P3.5 < T1
T1 15
15
P3.6 <
P3.6 < WR
WR 16
16
P3.7 <
P3.7 < Complement of RD
Complement of RD 17
17
Dual Role of Port 0 and Port 2
Dual Role of Port 0 and Port 2
Dual role of Port 0
Dual role of Port 0 − Port 0 is also designated as AD0–AD7, as it can be used for both data and
− Port 0 is also designated as AD0–AD7, as it can be used for both data and
address handling. While connecting an 8051 to external memory, Port 0 can provide both
address handling. While connecting an 8051 to external memory, Port 0 can provide both
address and data. The 8051 microcontroller then multiplexes the input as address or data in
address and data. The 8051 microcontroller then multiplexes the input as address or data in
order to save pins.
order to save pins.
Dual role of Port 2
Dual role of Port 2 − Besides working as I/O, Port P2 is also used to provide 16-bit address bus
− Besides working as I/O, Port P2 is also used to provide 16-bit address bus
for external memory along with Port 0. Port P2 is also designated as (A8– A15), while Port 0
for external memory along with Port 0. Port P2 is also designated as (A8– A15), while Port 0
provides the lower 8-bits via A0–A7. In other words, we can say that when an 8051 is connected
provides the lower 8-bits via A0–A7. In other words, we can say that when an 8051 is connected
to an external memory (ROM) which can be maximum up to 64KB and this is possible by 16 bit
to an external memory (ROM) which can be maximum up to 64KB and this is possible by 16 bit
address bus because we know 216 = 64KB. Port2 is used for the upper 8-bit of the 16 bits
address bus because we know 216 = 64KB. Port2 is used for the upper 8-bit of the 16 bits
address, and it cannot be used for I/O and this is the way any Program code of external ROM is
address, and it cannot be used for I/O and this is the way any Program code of external ROM is
addressed.
addressed.
Hardware Connection of Pins
Hardware Connection of Pins
V
V − Pin 40 provides supply to the Chip and it is +5 V.
− Pin 40 provides supply to the Chip and it is +5 V.
Gnd
Gnd − Pin 20 provides ground for the Reference.
− Pin 20 provides ground for the Reference.
XTAL1, XTAL2 (Pin no 18 & Pin no 19)
XTAL1, XTAL2 (Pin no 18 & Pin no 19) − 8051 has on-chip oscillator but requires external clock
− 8051 has on-chip oscillator but requires external clock
to run it. A quartz crystal is connected between the XTAL1 & XTAL2 pin of the chip. This crystal
to run it. A quartz crystal is connected between the XTAL1 & XTAL2 pin of the chip. This crystal
also needs two capacitors of 30pF for generating a signal of desired frequency. One side of each
also needs two capacitors of 30pF for generating a signal of desired frequency. One side of each
capacitor is connected to ground. 8051 IC is available in various speeds and it all depends on
capacitor is connected to ground. 8051 IC is available in various speeds and it all depends on
cc
cc
this Quartz crystal, for example, a 20 MHz microcontroller requires a crystal with a frequency no
this Quartz crystal, for example, a 20 MHz microcontroller requires a crystal with a frequency no
more than 20 MHz.
more than 20 MHz.
RST (Pin No. 9)
RST (Pin No. 9) − It is an Input pin and active High pin. Upon applying a high pulse on this pin,
− It is an Input pin and active High pin. Upon applying a high pulse on this pin,
that is 1, the microcontroller will reset and terminate all activities. This process is known as
that is 1, the microcontroller will reset and terminate all activities. This process is known as
Power-On Reset
Power-On Reset. Activating a power-on reset will cause all values in the register to be lost. It will
. Activating a power-on reset will cause all values in the register to be lost. It will
set a program counter to all 0's. To ensure a valid input of Reset, the high pulse must be high for
set a program counter to all 0's. To ensure a valid input of Reset, the high pulse must be high for
a minimum of two machine cycles before it is allowed to go low, which depends on the capacitor
a minimum of two machine cycles before it is allowed to go low, which depends on the capacitor
value and the rate at which it charges. (
value and the rate at which it charges. (Machine Cycle
Machine Cycle is the minimum amount of frequency a
is the minimum amount of frequency a
single instruction requires in execution).
single instruction requires in execution).
EA or External Access (Pin No. 31)
EA or External Access (Pin No. 31) − It is an input pin. This pin is an active low pin; upon
− It is an input pin. This pin is an active low pin; upon
applying a low pulse, it gets activated. In case of microcontroller (8051/52) having on-chip ROM,
applying a low pulse, it gets activated. In case of microcontroller (8051/52) having on-chip ROM,
the EA (bar) pin is connected to V
the EA (bar) pin is connected to V . But in an 8031 microcontroller which does not have an on-
. But in an 8031 microcontroller which does not have an on-
chip ROM, the code is stored in an external ROM and then fetched by the microcontroller. In this
chip ROM, the code is stored in an external ROM and then fetched by the microcontroller. In this
case, we must connect the (pin no 31) EA to Gnd to indicate that the program code is stored
case, we must connect the (pin no 31) EA to Gnd to indicate that the program code is stored
externally.
externally.
cc
cc
PSEN or Program store Enable (Pin No 29)
PSEN or Program store Enable (Pin No 29) − This is also an active low pin, i.e., it gets
− This is also an active low pin, i.e., it gets
activated after applying a low pulse. It is an output pin and used along with the EA pin in 8031
activated after applying a low pulse. It is an output pin and used along with the EA pin in 8031
based (i.e. ROMLESS) Systems to allow storage of program code in external ROM.
based (i.e. ROMLESS) Systems to allow storage of program code in external ROM.
ALE or (Address Latch Enable)
ALE or (Address Latch Enable) − This is an Output Pin and is active high. It is especially used
− This is an Output Pin and is active high. It is especially used
for 8031 IC to connect it to the external memory. It can be used while deciding whether P0 pins
for 8031 IC to connect it to the external memory. It can be used while deciding whether P0 pins
will be used as Address bus or Data bus. When ALE = 1, then the P0 pins work as Data bus and
will be used as Address bus or Data bus. When ALE = 1, then the P0 pins work as Data bus and
when ALE = 0, then the P0 pins act as Address bus.
when ALE = 0, then the P0 pins act as Address bus.
I/O Ports and Bit Addressability
I/O Ports and Bit Addressability
It is a most widely used feature of 8051 while writing code for 8051. Sometimes we need to access only 1
It is a most widely used feature of 8051 while writing code for 8051. Sometimes we need to access only 1
or 2 bits of the port instead of the entire 8-bits. 8051 provides the capability to access individual bits of the
or 2 bits of the port instead of the entire 8-bits. 8051 provides the capability to access individual bits of the
ports.
ports.
While accessing a port in a single-bit manner, we use the syntax "SETB X. Y" where X is the port number
While accessing a port in a single-bit manner, we use the syntax "SETB X. Y" where X is the port number
(0 to 3), and Y is a bit number (0 to 7) for data bits D0-D7 where D0 is the LSB and D7 is the MSB. For
(0 to 3), and Y is a bit number (0 to 7) for data bits D0-D7 where D0 is the LSB and D7 is the MSB. For
example, "SETB P1.5" sets high bit 5 of port 1.
example, "SETB P1.5" sets high bit 5 of port 1.
The following code shows how we can toggle the bit P1.2 continuously.
The following code shows how we can toggle the bit P1.2 continuously.
AGAIN:
AGAIN:
SETB P1.2
SETB P1.2
ACALL DELAY
ACALL DELAY
CLR P1.2
CLR P1.2
ACALL DELAY
ACALL DELAY
SJMP AGAIN
SJMP AGAIN
Single-Bit Instructions
Single-Bit Instructions
Instructions
Instructions Function
Function
SETB bit
SETB bit Set the bit (bit = 1)
Set the bit (bit = 1)
CLR bit
CLR bit clear the bit (bit = 0)
clear the bit (bit = 0)
CPL bit
CPL bit complement the bit (bit = NOT bit)
complement the bit (bit = NOT bit)
JB bit, target
JB bit, target jump to target if bit = 1 (jump if bit)
jump to target if bit = 1 (jump if bit)
JNB bit, target
JNB bit, target jump to target if bit = 0 (jump if no bit)
jump to target if bit = 0 (jump if no bit)
JBC bit, target
JBC bit, target jump to target if bit = 1, clear bit (jump if bit, then clear)
jump to target if bit = 1, clear bit (jump if bit, then clear)

Más contenido relacionado

La actualidad más candente

Ei502microprocessorsmicrtocontrollerspart4 8051 Microcontroller
Ei502microprocessorsmicrtocontrollerspart4 8051 MicrocontrollerEi502microprocessorsmicrtocontrollerspart4 8051 Microcontroller
Ei502microprocessorsmicrtocontrollerspart4 8051 MicrocontrollerDebasis Das
 
8051 Microcontroller I/O ports
8051 Microcontroller I/O ports8051 Microcontroller I/O ports
8051 Microcontroller I/O portsanishgoel
 
1347 Assembly Language Programming Of 8051
1347 Assembly Language Programming Of 80511347 Assembly Language Programming Of 8051
1347 Assembly Language Programming Of 8051techbed
 
Embedded Systems Project Based Training|Engineering Projects,Summer Training
Embedded Systems Project Based Training|Engineering Projects,Summer TrainingEmbedded Systems Project Based Training|Engineering Projects,Summer Training
Embedded Systems Project Based Training|Engineering Projects,Summer TrainingTechnogroovy
 
The 8051 microcontroller
The 8051  microcontroller The 8051  microcontroller
The 8051 microcontroller Avinash Mishra
 
8051 basic programming
8051 basic programming8051 basic programming
8051 basic programmingANJUSHA R
 
Microcontroller 8051 training
Microcontroller 8051 trainingMicrocontroller 8051 training
Microcontroller 8051 trainingPradip Bhandari
 
Intro2 Robotic With Pic18
Intro2 Robotic With Pic18Intro2 Robotic With Pic18
Intro2 Robotic With Pic18Moayadhn
 
8051 assembly programming
8051 assembly programming8051 assembly programming
8051 assembly programmingsergeiseq
 
Introduction to pic
Introduction to picIntroduction to pic
Introduction to picPRADEEP
 
8051 microcontroller
8051 microcontroller8051 microcontroller
8051 microcontrollerJhemi22
 
Microcontroller 8051 By Mitesh kumar
Microcontroller 8051 By Mitesh kumarMicrocontroller 8051 By Mitesh kumar
Microcontroller 8051 By Mitesh kumarMitesh Kumar
 
Chp2 introduction to the 68000 microprocessor copy
Chp2 introduction to the 68000 microprocessor   copyChp2 introduction to the 68000 microprocessor   copy
Chp2 introduction to the 68000 microprocessor copymkazree
 
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 8051SARITHA REDDY
 

La actualidad más candente (20)

Microcontroller 8051 basics (part I)
Microcontroller 8051 basics (part I)Microcontroller 8051 basics (part I)
Microcontroller 8051 basics (part I)
 
AT89C52 Data sheet
AT89C52 Data sheetAT89C52 Data sheet
AT89C52 Data sheet
 
Ei502microprocessorsmicrtocontrollerspart4 8051 Microcontroller
Ei502microprocessorsmicrtocontrollerspart4 8051 MicrocontrollerEi502microprocessorsmicrtocontrollerspart4 8051 Microcontroller
Ei502microprocessorsmicrtocontrollerspart4 8051 Microcontroller
 
8051 Microcontroller I/O ports
8051 Microcontroller I/O ports8051 Microcontroller I/O ports
8051 Microcontroller I/O ports
 
1347 Assembly Language Programming Of 8051
1347 Assembly Language Programming Of 80511347 Assembly Language Programming Of 8051
1347 Assembly Language Programming Of 8051
 
Embedded Systems Project Based Training|Engineering Projects,Summer Training
Embedded Systems Project Based Training|Engineering Projects,Summer TrainingEmbedded Systems Project Based Training|Engineering Projects,Summer Training
Embedded Systems Project Based Training|Engineering Projects,Summer Training
 
The 8051 microcontroller
The 8051  microcontroller The 8051  microcontroller
The 8051 microcontroller
 
8051 basic programming
8051 basic programming8051 basic programming
8051 basic programming
 
8051 book
8051 book8051 book
8051 book
 
Microcontroller 8051 training
Microcontroller 8051 trainingMicrocontroller 8051 training
Microcontroller 8051 training
 
Intro2 Robotic With Pic18
Intro2 Robotic With Pic18Intro2 Robotic With Pic18
Intro2 Robotic With Pic18
 
8051 full ppt
8051 full ppt8051 full ppt
8051 full ppt
 
8051 assembly programming
8051 assembly programming8051 assembly programming
8051 assembly programming
 
Introduction to pic
Introduction to picIntroduction to pic
Introduction to pic
 
Emb day2 8051
Emb day2 8051Emb day2 8051
Emb day2 8051
 
8051 microcontroller
8051 microcontroller8051 microcontroller
8051 microcontroller
 
Microcontroller 8051 By Mitesh kumar
Microcontroller 8051 By Mitesh kumarMicrocontroller 8051 By Mitesh kumar
Microcontroller 8051 By Mitesh kumar
 
8051 Microcontroller
8051 Microcontroller8051 Microcontroller
8051 Microcontroller
 
Chp2 introduction to the 68000 microprocessor copy
Chp2 introduction to the 68000 microprocessor   copyChp2 introduction to the 68000 microprocessor   copy
Chp2 introduction to the 68000 microprocessor copy
 
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
 

Similar a Embedded systems io programming

MICROCONTROLLER .pptx
MICROCONTROLLER .pptxMICROCONTROLLER .pptx
MICROCONTROLLER .pptxArulMozhie1
 
Port Organization of 8051 .pdf
Port Organization of 8051 .pdfPort Organization of 8051 .pdf
Port Organization of 8051 .pdfSrikrishna Thota
 
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 8051KanchanPatil34
 
I/O port programming in 8051
I/O port programming in 8051I/O port programming in 8051
I/O port programming in 8051ssuser3a47cb
 
8051 Microcontroller -1.pptx
8051 Microcontroller -1.pptx8051 Microcontroller -1.pptx
8051 Microcontroller -1.pptxveeramaniks
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051Rashmi
 
Embedded System Microcontroller 8051
Embedded System Microcontroller 8051Embedded System Microcontroller 8051
Embedded System Microcontroller 8051ShawnIslam20150022
 
Unit iv introduction to 8051 microcontroller ppts
Unit iv introduction to 8051 microcontroller pptsUnit iv introduction to 8051 microcontroller ppts
Unit iv introduction to 8051 microcontroller pptsSreenivas Hanumandla
 
EMBEDDED SYSTEMS 5
EMBEDDED SYSTEMS 5EMBEDDED SYSTEMS 5
EMBEDDED SYSTEMS 5PRADEEP
 
Io (2)
Io (2)Io (2)
Io (2)Aisu
 
8051 architecture
8051 architecture8051 architecture
8051 architecturesb108ec
 
Hardware interfacing basics using AVR
Hardware interfacing basics using AVRHardware interfacing basics using AVR
Hardware interfacing basics using AVRMohamed Abdallah
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051Sadiq Rahim
 
Embedded system (Chapter 3) io_port_programming
Embedded system (Chapter 3) io_port_programmingEmbedded system (Chapter 3) io_port_programming
Embedded system (Chapter 3) io_port_programmingIkhwan_Fakrudin
 

Similar a Embedded systems io programming (20)

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
 
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
 
I/O port programming in 8051
I/O port programming in 8051I/O port programming in 8051
I/O port programming in 8051
 
Class7
Class7Class7
Class7
 
8051 Microcontroller -1.pptx
8051 Microcontroller -1.pptx8051 Microcontroller -1.pptx
8051 Microcontroller -1.pptx
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
 
Microcontroller 8051 third
Microcontroller 8051  thirdMicrocontroller 8051  third
Microcontroller 8051 third
 
Embedded System Microcontroller 8051
Embedded System Microcontroller 8051Embedded System Microcontroller 8051
Embedded System Microcontroller 8051
 
Unit iv introduction to 8051 microcontroller ppts
Unit iv introduction to 8051 microcontroller pptsUnit iv introduction to 8051 microcontroller ppts
Unit iv introduction to 8051 microcontroller ppts
 
8051 pin description
8051 pin description 8051 pin description
8051 pin description
 
8051 microcontroller
8051 microcontroller8051 microcontroller
8051 microcontroller
 
EMBEDDED SYSTEMS 5
EMBEDDED SYSTEMS 5EMBEDDED SYSTEMS 5
EMBEDDED SYSTEMS 5
 
Io (2)
Io (2)Io (2)
Io (2)
 
8051 architecture
8051 architecture8051 architecture
8051 architecture
 
Intel 8051 - pin description
Intel 8051  - pin descriptionIntel 8051  - pin description
Intel 8051 - pin description
 
Hardware interfacing basics using AVR
Hardware interfacing basics using AVRHardware interfacing basics using AVR
Hardware interfacing basics using AVR
 
12906245.ppt
12906245.ppt12906245.ppt
12906245.ppt
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
 
Embedded system (Chapter 3) io_port_programming
Embedded system (Chapter 3) io_port_programmingEmbedded system (Chapter 3) io_port_programming
Embedded system (Chapter 3) io_port_programming
 

Más de imtiazalijoono

Embedded systems tools & peripherals
Embedded systems   tools & peripheralsEmbedded systems   tools & peripherals
Embedded systems tools & peripheralsimtiazalijoono
 
Importance of reading and its types.
Importance of reading and its types.Importance of reading and its types.
Importance of reading and its types.imtiazalijoono
 
Negative amplifiers and its types Positive feedback and Negative feedback
Negative amplifiers and its types Positive feedback  and Negative feedbackNegative amplifiers and its types Positive feedback  and Negative feedback
Negative amplifiers and its types Positive feedback and Negative feedbackimtiazalijoono
 
Multistage amplifiers and Name of coupling Name of multistage amplifier
Multistage amplifiers and Name of coupling Name of multistage amplifierMultistage amplifiers and Name of coupling Name of multistage amplifier
Multistage amplifiers and Name of coupling Name of multistage amplifierimtiazalijoono
 
Loop Introduction for Loop while Loop do while Loop Nested Loops Values of...
Loop Introduction for Loop  while Loop do while Loop  Nested Loops  Values of...Loop Introduction for Loop  while Loop do while Loop  Nested Loops  Values of...
Loop Introduction for Loop while Loop do while Loop Nested Loops Values of...imtiazalijoono
 
Programming Fundamentals and basic knowledge
Programming Fundamentals and basic knowledge Programming Fundamentals and basic knowledge
Programming Fundamentals and basic knowledge imtiazalijoono
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and typesimtiazalijoono
 
Software Development Software development process
Software Development Software development processSoftware Development Software development process
Software Development Software development processimtiazalijoono
 
Programming Fundamentals Decisions
Programming Fundamentals  Decisions Programming Fundamentals  Decisions
Programming Fundamentals Decisions imtiazalijoono
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings imtiazalijoono
 
Programming Fundamentals and Programming Languages Concepts Translators
Programming Fundamentals and Programming Languages Concepts TranslatorsProgramming Fundamentals and Programming Languages Concepts Translators
Programming Fundamentals and Programming Languages Concepts Translatorsimtiazalijoono
 
Programming Fundamentals and Programming Languages Concepts
Programming Fundamentals and Programming Languages ConceptsProgramming Fundamentals and Programming Languages Concepts
Programming Fundamentals and Programming Languages Conceptsimtiazalijoono
 
Programming Global variable
Programming Global variableProgramming Global variable
Programming Global variableimtiazalijoono
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayimtiazalijoono
 
NTRODUCTION TO COMPUTER PROGRAMMING Loop as repetitive statement,
NTRODUCTION TO COMPUTER PROGRAMMING Loop as repetitive statement,NTRODUCTION TO COMPUTER PROGRAMMING Loop as repetitive statement,
NTRODUCTION TO COMPUTER PROGRAMMING Loop as repetitive statement,imtiazalijoono
 
Arithmetic and Arithmetic assignment operators
Arithmetic and Arithmetic assignment operatorsArithmetic and Arithmetic assignment operators
Arithmetic and Arithmetic assignment operatorsimtiazalijoono
 
INTRODUCTION TO COMPUTER PROGRAMMING
INTRODUCTION TO COMPUTER PROGRAMMINGINTRODUCTION TO COMPUTER PROGRAMMING
INTRODUCTION TO COMPUTER PROGRAMMINGimtiazalijoono
 

Más de imtiazalijoono (20)

Embedded systems tools & peripherals
Embedded systems   tools & peripheralsEmbedded systems   tools & peripherals
Embedded systems tools & peripherals
 
Importance of reading and its types.
Importance of reading and its types.Importance of reading and its types.
Importance of reading and its types.
 
Negative amplifiers and its types Positive feedback and Negative feedback
Negative amplifiers and its types Positive feedback  and Negative feedbackNegative amplifiers and its types Positive feedback  and Negative feedback
Negative amplifiers and its types Positive feedback and Negative feedback
 
Multistage amplifiers and Name of coupling Name of multistage amplifier
Multistage amplifiers and Name of coupling Name of multistage amplifierMultistage amplifiers and Name of coupling Name of multistage amplifier
Multistage amplifiers and Name of coupling Name of multistage amplifier
 
Loop Introduction for Loop while Loop do while Loop Nested Loops Values of...
Loop Introduction for Loop  while Loop do while Loop  Nested Loops  Values of...Loop Introduction for Loop  while Loop do while Loop  Nested Loops  Values of...
Loop Introduction for Loop while Loop do while Loop Nested Loops Values of...
 
Programming Fundamentals and basic knowledge
Programming Fundamentals and basic knowledge Programming Fundamentals and basic knowledge
Programming Fundamentals and basic knowledge
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and types
 
Software Development Software development process
Software Development Software development processSoftware Development Software development process
Software Development Software development process
 
Programming Fundamentals Decisions
Programming Fundamentals  Decisions Programming Fundamentals  Decisions
Programming Fundamentals Decisions
 
C Building Blocks
C Building Blocks C Building Blocks
C Building Blocks
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
 
Programming Fundamentals and Programming Languages Concepts Translators
Programming Fundamentals and Programming Languages Concepts TranslatorsProgramming Fundamentals and Programming Languages Concepts Translators
Programming Fundamentals and Programming Languages Concepts Translators
 
Programming Fundamentals and Programming Languages Concepts
Programming Fundamentals and Programming Languages ConceptsProgramming Fundamentals and Programming Languages Concepts
Programming Fundamentals and Programming Languages Concepts
 
Programming Global variable
Programming Global variableProgramming Global variable
Programming Global variable
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 
NTRODUCTION TO COMPUTER PROGRAMMING Loop as repetitive statement,
NTRODUCTION TO COMPUTER PROGRAMMING Loop as repetitive statement,NTRODUCTION TO COMPUTER PROGRAMMING Loop as repetitive statement,
NTRODUCTION TO COMPUTER PROGRAMMING Loop as repetitive statement,
 
Arithmetic and Arithmetic assignment operators
Arithmetic and Arithmetic assignment operatorsArithmetic and Arithmetic assignment operators
Arithmetic and Arithmetic assignment operators
 
INTRODUCTION TO COMPUTER PROGRAMMING
INTRODUCTION TO COMPUTER PROGRAMMINGINTRODUCTION TO COMPUTER PROGRAMMING
INTRODUCTION TO COMPUTER PROGRAMMING
 
COMPUTER PROGRAMMING
COMPUTER PROGRAMMINGCOMPUTER PROGRAMMING
COMPUTER PROGRAMMING
 
COMPUTER PROGRAMMING
COMPUTER PROGRAMMINGCOMPUTER PROGRAMMING
COMPUTER PROGRAMMING
 

Último

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 

Último (20)

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 

Embedded systems io programming

  • 1. Embedded Systems - I/O Programming Embedded Systems - I/O Programming In 8051, I/O operations are done using four ports and 40 pins. The following pin diagram shows the details 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 of the 40 pins. I/O operation port reserves 32 pins where each port has 8 pins. The other 8 pins are designated as V designated as V , GND, XTAL1, XTAL2, RST, EA (bar), ALE/PROG (bar), and PSEN (bar). , GND, XTAL1, XTAL2, RST, EA (bar), ALE/PROG (bar), and PSEN (bar). It is a 40 Pin PDIP (Plastic Dual Inline Package) It is a 40 Pin PDIP (Plastic Dual Inline Package) Note Note − In a DIP package, you can recognize the first pin and the last pin by the cut at the middle of the IC. − In a DIP package, you can recognize the first pin and the last pin by the cut at the middle of the IC. The first pin is on the left of this cut mark and the last pin (i.e. the 40 The first pin is on the left of this cut mark and the last pin (i.e. the 40 pin in this case) is to the right of the pin in this case) is to the right of the cut mark. cut mark. I/O Ports and their Functions I/O Ports and their Functions The four ports P0, P1, P2, and P3, each use 8 pins, making them 8-bit ports. Upon RESET, all the ports The four ports P0, P1, P2, and P3, each use 8 pins, making them 8-bit ports. Upon RESET, all the ports are configured as inputs, ready to be used as input ports. When the first 0 is written to a port, it becomes are configured as inputs, 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 a port. an output. To reconfigure it as an input, a 1 must be sent to a port. Port 0 (Pin No 32 – Pin No 39) Port 0 (Pin No 32 – Pin No 39) It has 8 pins (32 to 39). It can be used for input or output. Unlike P1, P2, and P3 ports, we normally It has 8 pins (32 to 39). It can be used for input or output. Unlike P1, P2, and P3 ports, we normally connect P0 to 10K-ohm pull-up resistors to use it as an input or output port being an open drain. connect P0 to 10K-ohm pull-up resistors to use it as an input or output port being an open drain. cc cc th th
  • 2. It is also designated as AD0-AD7, allowing it to be used as both address and data. In case of 8031 (i.e. It is also designated as AD0-AD7, allowing it to be used as both address and data. In case of 8031 (i.e. ROMless Chip), when we need to access the external ROM, then P0 will be used for both Address and ROMless Chip), when we need to access the external ROM, then P0 will be used for both Address and Data Bus. ALE (Pin no 31) indicates if P0 has address or data. When ALE = 0, it provides data D0-D7, but Data Bus. ALE (Pin no 31) indicates if P0 has address or data. When ALE = 0, it provides data D0-D7, but when ALE = 1, it has address A0-A7. In case no external memory connection is available, P0 must be when ALE = 1, it has address A0-A7. In case no external memory connection is available, P0 must be connected externally to a 10K-ohm pull-up resistor. connected externally to a 10K-ohm pull-up resistor. MOV A,#0FFH ;(comments: A=FFH(Hexadecimal i.e. A=1111 1111) MOV A,#0FFH ;(comments: A=FFH(Hexadecimal i.e. A=1111 1111) MOV P0,A ;(Port0 have 1's on every pin so that it works as Input) MOV P0,A ;(Port0 have 1's on every pin so that it works as Input) Port 1 (Pin 1 through 8) Port 1 (Pin 1 through 8) It is an 8-bit port (pin 1 through 8) and can be used either as input or output. It doesn't require pull-up It is an 8-bit port (pin 1 through 8) and can be used either as input or output. It doesn't require pull-up resistors because they are already connected internally. Upon reset, Port 1 is configured as an input port. resistors because they are already connected internally. Upon reset, Port 1 is configured as an input port. The following code can be used to send alternating values of 55H and AAH to Port 1. The following code can be used to send alternating values of 55H and AAH to Port 1. ;Toggle all bits of continuously ;Toggle all bits of continuously MOV A,#55 MOV A,#55 BACK: BACK: MOV P2,A MOV P2,A ACALL DELAY ACALL DELAY CPL A ;complement(invert) reg. A CPL A ;complement(invert) reg. A SJMP BACK SJMP BACK If Port 1 is configured to be used as an output port, then to use it as an input port again, program it by If Port 1 is configured to be used as an output port, then to use it as an input port again, program it by writing 1 to all of its bits as in the following code. writing 1 to all of its bits as in the following code.
  • 3. ;Toggle all bits of continuously ;Toggle all bits of continuously MOV A ,#0FFH ;A = FF hex MOV A ,#0FFH ;A = FF hex MOV P1,A ;Make P1 an input port MOV P1,A ;Make P1 an input port MOV A,P1 ;get data from P1 MOV A,P1 ;get data from P1 MOV R7,A ;save it in Reg R7 MOV R7,A ;save it in Reg R7 ACALL DELAY ;wait ACALL DELAY ;wait MOV A,P1 ;get another data from P1 MOV A,P1 ;get another data from P1 MOV R6,A ;save it in R6 MOV R6,A ;save it in R6 ACALL DELAY ;wait ACALL DELAY ;wait MOV A,P1 ;get another data from P1 MOV A,P1 ;get another data from P1 MOV R5,A ;save it in R5 MOV R5,A ;save it in R5 Port 2 (Pins 21 through 28) Port 2 (Pins 21 through 28) Port 2 occupies a total of 8 pins (pins 21 through 28) and can be used for both input and output Port 2 occupies a total of 8 pins (pins 21 through 28) and can be used for both input and output operations. Just as P1 (Port 1), P2 also doesn't require external Pull-up resistors because they are operations. Just as P1 (Port 1), P2 also doesn't require external Pull-up resistors because they are already connected internally. It must be used along with P0 to provide the 16-bit address for the external already connected internally. It must be used along with P0 to provide the 16-bit address for the external memory. So it is also designated as (A0–A7), as shown in the pin diagram. When the 8051 is connected memory. So it is also designated as (A0–A7), as shown in the pin diagram. 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. to an external memory, it provides path for upper 8-bits of 16-bits address, and it cannot be used as I/O. Upon reset, Port 2 is configured as an input port. The following code can be used to send alternating Upon reset, Port 2 is configured as an input port. The following code can be used to send alternating values of 55H and AAH to port 2. values of 55H and AAH to port 2. ;Toggle all bits of continuously ;Toggle all bits of continuously MOV A,#55 MOV A,#55 BACK: BACK: MOV P2,A MOV P2,A ACALL DELAY ACALL DELAY CPL A ; complement(invert) reg. A CPL A ; complement(invert) reg. A SJMP BACK SJMP BACK If Port 2 is configured to be used as an output port, then to use it as an input port again, program it by If Port 2 is configured to be used as an output port, then to use it as an input port again, program it by writing 1 to all of its bits as in the following code. writing 1 to all of its bits as in the following code. ;Get a byte from P2 and send it to P1 ;Get a byte from P2 and send it to P1 MOV A,#0FFH ;A = FF hex MOV A,#0FFH ;A = FF hex MOV P2,A ;make P2 an input port MOV P2,A ;make P2 an input port BACK: BACK: MOV A,P2 ;get data from P2 MOV A,P2 ;get data from P2 MOV P1,A ;send it to Port 1 MOV P1,A ;send it to Port 1 SJMP BACK ;keep doing that SJMP BACK ;keep doing that Port 3 (Pins 10 through 17) Port 3 (Pins 10 through 17)
  • 4. It is also of 8 bits and can be used as Input/Output. This port provides some extremely important signals. It is also of 8 bits and can be used as Input/Output. This port provides some extremely important signals. P3.0 and P3.1 are RxD (Receiver) and TxD (Transmitter) respectively and are collectively used for Serial P3.0 and P3.1 are RxD (Receiver) and TxD (Transmitter) respectively and are collectively used for Serial Communication. P3.2 and P3.3 pins are used for external interrupts. P3.4 and P3.5 are used for timers T0 Communication. P3.2 and P3.3 pins are used for external interrupts. P3.4 and P3.5 are used for timers T0 and T1 respectively. P3.6 and P3.7 are Write (WR) and Read (RD) pins. These are active low pins, means and T1 respectively. P3.6 and P3.7 are Write (WR) and Read (RD) pins. These are active low pins, means they will be active when 0 is given to them and these are used to provide Read and Write operations to they will be active when 0 is given to them and these are used to provide Read and Write operations to External ROM in 8031 based systems. External ROM in 8031 based systems. P3 Bit P3 Bit Function Function Pin Pin P3.0 P3.0 RxD RxD 10 10 P3.1 < P3.1 < TxD TxD 11 11 P3.2 < P3.2 < Complement of INT0 Complement of INT0 12 12 P3.3 < P3.3 < INT1 INT1 13 13 P3.4 < P3.4 < T0 T0 14 14 P3.5 < P3.5 < T1 T1 15 15 P3.6 < P3.6 < WR WR 16 16 P3.7 < P3.7 < Complement of RD Complement of RD 17 17 Dual Role of Port 0 and Port 2 Dual Role of Port 0 and Port 2 Dual role of Port 0 Dual role of Port 0 − Port 0 is also designated as AD0–AD7, as it can be used for both data and − Port 0 is also designated as AD0–AD7, as it can be used for both data and address handling. While connecting an 8051 to external memory, Port 0 can provide both address handling. While connecting an 8051 to external memory, Port 0 can provide both address and data. The 8051 microcontroller then multiplexes the input as address or data in address and data. The 8051 microcontroller then multiplexes the input as address or data in order to save pins. order to save pins. Dual role of Port 2 Dual role of Port 2 − Besides working as I/O, Port P2 is also used to provide 16-bit address bus − Besides working as I/O, Port P2 is also used to provide 16-bit address bus for external memory along with Port 0. Port P2 is also designated as (A8– A15), while Port 0 for external memory along with Port 0. Port P2 is also designated as (A8– A15), while Port 0 provides the lower 8-bits via A0–A7. In other words, we can say that when an 8051 is connected provides the lower 8-bits via A0–A7. In other words, we can say that when an 8051 is connected to an external memory (ROM) which can be maximum up to 64KB and this is possible by 16 bit to an external memory (ROM) which can be maximum up to 64KB and this is possible by 16 bit address bus because we know 216 = 64KB. Port2 is used for the upper 8-bit of the 16 bits address bus because we know 216 = 64KB. Port2 is used for the upper 8-bit of the 16 bits address, and it cannot be used for I/O and this is the way any Program code of external ROM is address, and it cannot be used for I/O and this is the way any Program code of external ROM is addressed. addressed. Hardware Connection of Pins Hardware Connection of Pins V V − Pin 40 provides supply to the Chip and it is +5 V. − Pin 40 provides supply to the Chip and it is +5 V. Gnd Gnd − Pin 20 provides ground for the Reference. − Pin 20 provides ground for the Reference. XTAL1, XTAL2 (Pin no 18 & Pin no 19) XTAL1, XTAL2 (Pin no 18 & Pin no 19) − 8051 has on-chip oscillator but requires external clock − 8051 has on-chip oscillator but requires external clock to run it. A quartz crystal is connected between the XTAL1 & XTAL2 pin of the chip. This crystal to run it. A quartz crystal is connected between the XTAL1 & XTAL2 pin of the chip. This crystal also needs two capacitors of 30pF for generating a signal of desired frequency. One side of each also needs two capacitors of 30pF for generating a signal of desired frequency. One side of each capacitor is connected to ground. 8051 IC is available in various speeds and it all depends on capacitor is connected to ground. 8051 IC is available in various speeds and it all depends on cc cc
  • 5. this Quartz crystal, for example, a 20 MHz microcontroller requires a crystal with a frequency no this Quartz crystal, for example, a 20 MHz microcontroller requires a crystal with a frequency no more than 20 MHz. more than 20 MHz. RST (Pin No. 9) RST (Pin No. 9) − It is an Input pin and active High pin. Upon applying a high pulse on this pin, − It is an Input pin and active High pin. Upon applying a high pulse on this pin, that is 1, the microcontroller will reset and terminate all activities. This process is known as that is 1, the microcontroller will reset and terminate all activities. This process is known as Power-On Reset Power-On Reset. Activating a power-on reset will cause all values in the register to be lost. It will . Activating a power-on reset will cause all values in the register to be lost. It will set a program counter to all 0's. To ensure a valid input of Reset, the high pulse must be high for set a program counter to all 0's. To ensure a valid input of Reset, the high pulse must be high for a minimum of two machine cycles before it is allowed to go low, which depends on the capacitor a minimum of two machine cycles before it is allowed to go low, which depends on the capacitor value and the rate at which it charges. ( value and the rate at which it charges. (Machine Cycle Machine Cycle is the minimum amount of frequency a is the minimum amount of frequency a single instruction requires in execution). single instruction requires in execution). EA or External Access (Pin No. 31) EA or External Access (Pin No. 31) − It is an input pin. This pin is an active low pin; upon − It is an input pin. This pin is an active low pin; upon applying a low pulse, it gets activated. In case of microcontroller (8051/52) having on-chip ROM, applying a low pulse, it gets activated. In case of microcontroller (8051/52) having on-chip ROM, the EA (bar) pin is connected to V the EA (bar) pin is connected to V . But in an 8031 microcontroller which does not have an on- . But in an 8031 microcontroller which does not have an on- chip ROM, the code is stored in an external ROM and then fetched by the microcontroller. In this chip ROM, the code is stored in an external ROM and then fetched by the microcontroller. In this case, we must connect the (pin no 31) EA to Gnd to indicate that the program code is stored case, we must connect the (pin no 31) EA to Gnd to indicate that the program code is stored externally. externally. cc cc
  • 6. PSEN or Program store Enable (Pin No 29) PSEN or Program store Enable (Pin No 29) − This is also an active low pin, i.e., it gets − This is also an active low pin, i.e., it gets activated after applying a low pulse. It is an output pin and used along with the EA pin in 8031 activated after applying a low pulse. It is an output pin and used along with the EA pin in 8031 based (i.e. ROMLESS) Systems to allow storage of program code in external ROM. based (i.e. ROMLESS) Systems to allow storage of program code in external ROM. ALE or (Address Latch Enable) ALE or (Address Latch Enable) − This is an Output Pin and is active high. It is especially used − This is an Output Pin and is active high. It is especially used for 8031 IC to connect it to the external memory. It can be used while deciding whether P0 pins for 8031 IC to connect it to the external memory. It can be used while deciding whether P0 pins will be used as Address bus or Data bus. When ALE = 1, then the P0 pins work as Data bus and will be used as Address bus or Data bus. When ALE = 1, then the P0 pins work as Data bus and when ALE = 0, then the P0 pins act as Address bus. when ALE = 0, then the P0 pins act as Address bus. I/O Ports and Bit Addressability I/O Ports and Bit Addressability It is a most widely used feature of 8051 while writing code for 8051. Sometimes we need to access only 1 It is a most widely used feature of 8051 while writing code for 8051. Sometimes we need to access only 1 or 2 bits of the port instead of the entire 8-bits. 8051 provides the capability to access individual bits of the or 2 bits of the port instead of the entire 8-bits. 8051 provides the capability to access individual bits of the ports. ports. While accessing a port in a single-bit manner, we use the syntax "SETB X. Y" where X is the port number While accessing a port in a single-bit manner, we use the syntax "SETB X. Y" where X is the port number (0 to 3), and Y is a bit number (0 to 7) for data bits D0-D7 where D0 is the LSB and D7 is the MSB. For (0 to 3), and Y is a bit number (0 to 7) for data bits D0-D7 where D0 is the LSB and D7 is the MSB. For example, "SETB P1.5" sets high bit 5 of port 1. example, "SETB P1.5" sets high bit 5 of port 1. The following code shows how we can toggle the bit P1.2 continuously. The following code shows how we can toggle the bit P1.2 continuously. AGAIN: AGAIN: SETB P1.2 SETB P1.2 ACALL DELAY ACALL DELAY CLR P1.2 CLR P1.2 ACALL DELAY ACALL DELAY SJMP AGAIN SJMP AGAIN Single-Bit Instructions Single-Bit Instructions
  • 7. Instructions Instructions Function Function SETB bit SETB bit Set the bit (bit = 1) Set the bit (bit = 1) CLR bit CLR bit clear the bit (bit = 0) clear the bit (bit = 0) CPL bit CPL bit complement the bit (bit = NOT bit) complement the bit (bit = NOT bit) JB bit, target JB bit, target jump to target if bit = 1 (jump if bit) jump to target if bit = 1 (jump if bit) JNB bit, target JNB bit, target jump to target if bit = 0 (jump if no bit) jump to target if bit = 0 (jump if no bit) JBC bit, target JBC bit, target jump to target if bit = 1, clear bit (jump if bit, then clear) jump to target if bit = 1, clear bit (jump if bit, then clear)