8051 port initialization

Status
Not open for further replies.

4electros

New Member
sometimes i see programs for 8051 that initiliazes port2 or anyother port by the value (ff or 00),so why do we usually do that?
 
The answer is a bit deeper. Ports 1, 2, & 3 have output structures which are refered to as quasi-bidirectional ports. When the port data register contains a zero the N-channel output transistor can sink several milliamps of current. When the port data register contains a one there is only a weak pullup which can supply only a few tens of microamps. In this case the "output" can be overridden by another strong pulldown.

In order to use the alternate functions of port 3 you must write 1's to the bits which will be using the alternate function. The alternate function of port 2 is the high order address bits (A8-A15) which are used to access external memory and peripherals. Initializing P2 to 0xFF would be a clue that external memory or peripherals are involved.

Lastly, never forget that port 0 has "open drain" outputs. You must provide an external pullup, except when port 0 is the multiplexed address/data bus.

Is all of that just about as clear as mud in the street?
 
Sorry but i may need some diagram or drawing in order to understand what you said well.....

could you?!
 
4electros said:
Sorry but i may need some diagram or drawing in order to understand what you said well.....

could you?!
The drawings of the port pin structures are in the datasheets. Those from Atmel www.atmel.com have been particularly helpful to me.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…