How to configure contacts 8051 as input / output?

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

But in 8051 there is no such type of TRIS register. To configure the register as input / output, you need to write to the same register and write / read data that you must use in the same register. Am I right about this? If so, please explain how this is possible? If not, then please explain the correct theory about this.

+5
source share
1 answer

In fact, there is nothing to set the standard output 8051 as input; all contacts are always bi-directional.

However, if you write β€œ0” to the pin, it will enable the open-drain driver, and there is no way that anything external could ever force it anything other than β€œ0”, so the input will only read β€œ0” - regardless from an external signal that you might want to read.

But if you write β€œ1” to the pin, it will turn off the open drain driver and thus the external signal can output the pin either high or low - and the input can read the state of the external signal.

Everything is explained in chapter 3 of the Bible for 8051:

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

Start reading p2, β€œStructure and Operation of the Port,” and pay particular attention to Figures 4 and 5.

+5
source

Source: https://habr.com/ru/post/1209057/


All Articles