Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure 8051 pins as input/output?

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.

like image 273
Muhammad Nouman Avatar asked Dec 15 '14 07:12

Muhammad Nouman


1 Answers

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.

like image 127
norekhov Avatar answered Sep 22 '22 13:09

norekhov