Friday, 27 July 2012

8051 INPUT OUTPUT PORTS

The AT89C51 from ATMEL is the most commonly used variation of the 8051 microcontroller because of the built-in Flash which makes programming / burning very easy. The 8051 has a total of 4 ports for input / output operations which means you can transfer data in or out of the microcontroller through these ports. Let's have a brief introduction to these ports.

UPDATE: You can also click this link for an updated version of this post.



This is a basic block diagram of the internal architecture including the 4 ports. They are named as P0, P1, P2, and P3. Later on we will see that we can refer to them by using these names while programming for the 8051. Each port is 8-bit wide thus capable of handling 8-bit data at a time. 


USING THE PORTS FOR INPUT / OUTPUT 

While using these ports, you must keep in mind that except P0, all the ports are being provided with internal 10k ohm pull-up resistors. Now what does that mean? The pull-up resistors are for the safety ( to limit the amount of current ) of the ports. Port 0 has no internal resistors for this purpose so you have to attach a 10k ohm resistor whenever you intend to use it for input / output as shown in the diagram below. If you are using P1, P2, or P3 you don't have to worry about the pull-up resistors.

The 10k ohm pull up resistors attached to P0

DUAL NATURE 

Some of the ports have dual nature / purpose which means that they can perform some secondary function designated to them. If you are using them for data transfer then you simply forget about the dual function as you are concerned only with the data that appears on the port as a whole ( i-e 1 byte ) but if you are using interrupts, timers (to be discussed later) then you have to consider the dual nature of each pin accordingly. Here is the description of each pin

PORT 0
PIN
DUAL FUNCTION
0.0
AD0
0.1
AD1
0.2
AD2
0.3
AD3
0.4
AD4
0.5
AD5
0.6
AD6
0.7
AD7



PORT 1
PIN
DUAL FUNCTION
1.0
None
1.1
None
1.2
None
1.3
None
1.4
None
1.5
None
1.6
None
1.7
None



PORT 2
PIN
DUAL FUNCTION
2.0
A8
2.1
A9
2.2
A10
2.3
A11
2.4
A12
2.5
A13
2.6
A14
2.7
A15



PORT 3
PIN
DUAL FUNCTION
3.0
RxD
3.1
TxD
3.2
INT0
3.3
INT1
3.4
T0
3.5
T1
3.6
WR
3.7
RD



From the tables, you can see that P0 and P2 are assigned the address lines from A0 to A15 which are used for external interfacing to memory but only if needed. P1 offers no dual nature so it can be used only for input / output. For some reason, I like Port 3 for its dual nature as it offers interesting and useful features :)

2 comments:

  1. I don' t think you need a pull up resistor if you use P0 as input port

    ReplyDelete