How to configure 8051 pins as input/output?
Asked Answered
E

1

6

In pic microcontroller TRIS register determines whether port would act as input or output and PORT register would determine the content, what should be written (in case of output) or read (in case of input).

But in 8051 there isn't any such kind of TRIS register. To configure the register as input/output you have to write to the same register and to write/read the data you have to use the same register again. Am I right about this? If yes, then please explain how is it possible? If not, then please explain the correct theory about this.

Entail answered 15/12, 2014 at 7:19 Comment(1)
To read and write data in PIC and most other microcontrollers you also use the same register for that port. It's just that other MCUs have a register for configuring the pin as input or output. There's none in 8051Repair
S
8

Actually, there is nothing to set a standard 8051 pin as an input; all pins are always bidirectional.

However, if you write a '0' to a pin, it turns the open-drain driver ON and there is no way that anything external can ever force it to anything other than '0' Therefore the input will just read '0' - irrespective of the external signal you might wish to read.

But If you write a '1' to a pin, it turns the open-drain driver OFF and so an external signal can take the pin either high or low - and the input can read the state of the external signal.

The is all explained in Chapter 3 of the "bible" for the 8051:

Chapter 3 - 80C51 Family Hardware Description: http://www.semiconductors.philips.com/acrobat/various/80C51_FAM_HARDWARE_1.pdf

Start reading at p2, "Port Structure and Operation" and pay particular attention to Figures 4 & 5.

Saddler answered 15/12, 2014 at 8:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.