8051 (AT89S52) Question

Thread Starter

Dseng

Joined Jan 13, 2016
26
Since the ports are bit addressable on an 8051, can I make some bits of a port inputs and some bits outputs by writing ones and zeros to them.
Example:
Will the following make bits 0,2,4 and 6 of P1 an input and bits 1,3,5 and 7 output bits?
ORG 030H
SETB P1.0 ;Make P1.0 an input bit
CLR P1.1 ;Make P1.1 an output bit
SETB P1.2 ;MAKE P1.2 AN INPUT BIT
CLR P1.3 ;MAKE P1.3 AN OUTPUT BIT
SETB P1.4 ;MAKE P1.4 AN INPUT BIT
CLR P1.5 ;MAKE P1.5 AN OUTPUT BIT
SETB P1.6 ;MAKE P1.6 AN INPUT BIT
SETB P1.7 ;MAKE P1.7 AN OUTPUT BIT
END

If the above is true then will the following acomplish the same thing?

ORG 030H
MOV P1,#AAH
END
 

ScottWang

Joined Aug 23, 2012
7,400
AT89S52 datasheet, please check page 3 - Pin Description.

Port 0 Port 0 is an 8-bit open drain bi-directional I/O port. As an output port, each pin can sink eight TTL inputs. When 1s are written to port 0 pins, the pins can be used as highimpedance inputs.

Port 1 Port 1 is an 8-bit bi-directional I/O port with internal pullups. The Port 1 output buffers can sink/source four TTL inputs. When 1s are written to Port 1 pins, they are pulled high by the internal pullups and can be used as inputs. As inputs, Port 1 pins that are externally being pulled low will source current (IIL) because of the internal pullups.

Do you have any special why not separate two parts as P0~P3 and P4~P7?
 

Thread Starter

Dseng

Joined Jan 13, 2016
26
No, it's just a general question. It could be any ports or any combination. For example could I use six bits on port 2 as inputs at 2 as outputs?
 

ScottWang

Joined Aug 23, 2012
7,400
No, it's just a general question. It could be any ports or any combination. For example could I use six bits on port 2 as inputs at 2 as outputs?
Yes, you can do what you want as that

What I want to emphasize is that before you want to use the input function then you have to send 1(high) to the bit you want to input.
 
Top