io ports in 8051
Post on 18-Apr-2015
76 Views
Preview:
TRANSCRIPT
8051 Port structure
04/11/23 1
PRESENTED BYDHARANIPATHY .S
11MR61ME (AE ) Micrcontrollers & Applications
8051 Pin Diagram
04/11/23 2ME (AE ) Micrcontrollers & Applications
I/O Pin Structure
04/11/23 3
The four 8-bit I/O ports P0, P1, P2 andP3 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
ME (AE ) Micrcontrollers & Applications
Port 0 Used as Bi directional I/O port as well
AD0-AD7.
The ALE pin is used for de-multiplexing the address and data
When ALE=0, P0 provides data D0-D7.
– When ALE=1, P0 provides address A0-A7.
– No internal pull up resistors
04/11/23 4ME (AE ) Micrcontrollers & Applications
A Pin of Port 0
8051 IC
D Q
Clk Q
Read latch
Read pin
Write to latch
Internal CPU bus
M1
P0.X pinP1.X
TB1
TB2
P1.x
04/11/23 5ME (AE ) Micrcontrollers & Applications
In order to make port 0 an input, the port must be programmed by writing 1 to all the bits
Port 0 is configured first as an input port by writing 1s to it, and then data is received from that port and sent to P1
MOV A,#0FFH ; A=FF hexMOV P0,A ; make P0 an i/p port;by
writing it all 1sBACK: MOV A,P0 ; get data from P0MOV P1,A ; send it to port 1SJMP BACK ; keep doing it
04/11/23 6ME (AE ) Micrcontrollers & Applications
Port 1
04/11/23 7
Port 1 is denoted by P1.
P1.0 ~ P1.7
P1 as an output port (i.e., write CPU data to the external pin
P1 as an input port (i.e., read pin data into CPU bus)
ME (AE ) Micrcontrollers & Applications
04/11/23 8
A Pin of Port 1
D Q
Clk Q
Vcc
Load(L1)
Read latch
Read pin
Write to latch
Internal CPU bus
M1
P1.X pinP1.X
TB1
TB2
ME (AE ) Micrcontrollers & Applications
Writing “1” to Output Pin P1.X
D Q
Clk Q
Vcc
Load(L1)
Read latch
Read pin
Write to latch
Internal CPU bus
M1
P1.X pinP1.X
8051 IC
2. output pin is V cc1. write a 1 to the pin
1
0output 1
TB1
TB2
04/11/23 9ME (AE ) Micrcontrollers & Applications
Writing “0” to Output Pin P1.X
D Q
Clk Q
Vcc
Load(L1)
Read latch
Read pin
Write to latch
Internal CPU bus
M1
P1.X pinP1.X
8051 IC
2. output pin is ground1. write a 0 to the pin
0
1 output 0
TB1
TB2
04/11/23 10ME (AE ) Micrcontrollers & Applications
Port 1 as Output ( Write to a Port)• Send data to Port 1:
MOV A,#55H BACK: MOV P1,A
ACALL DELAYCPL ASJMP BACK
– Let P1 toggle.– You can write to P1 directly.
04/11/23 11ME (AE ) Micrcontrollers & Applications
Port 1 as Input ( Read from Port)• In order to make P1 an input, the port must be programmed by
writing 1 to all the bit.
MOV A,#0FFH ;A=11111111B
MOV P1,A ;make P1 an input port
BACK: MOV A,P1 ;get data from P0
MOV P2,A ;send data to P2
SJMP BACK
– To be an input port, P0, P1, P2 and P3 have similar methods.
04/11/23 12ME (AE ) Micrcontrollers & Applications
PORT 2
• Just like P1, 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
• To make port 2 an input port, it must be programmed as such by writing 1 to all its bits
04/11/23 13ME (AE ) Micrcontrollers & Applications
PORT 2 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,indicating its dual function
Port 0 provides the lower 8 bits via A0 – A7
04/11/23 14ME (AE ) Micrcontrollers & Applications
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.
04/11/23 15ME (AE ) Micrcontrollers & Applications
04/11/23 16ME (AE ) Micrcontrollers & Applications
04/11/23 17
THANK YOU
ME (AE ) Micrcontrollers & Applications
top related