UPC EETAC Bachelor's Degree in Telecommunications Systems and in Network Engineering EEL

 

 

Tri-state gates, PORT pins and direction configuration

L9.2


How to make a wire bi-directional? 

Tri-state gages were presented in L5.4.

Bidirectional microcontroller bus structure.

biderectional bus 

Fig. 1. The idea behind bidirectional busses.


 PORTx direction configuration register (TRISx)

Data direction registers TRISx are correlated to PORTx: writing a '1' in the corresponding pin of the TRISx register, the PORTx pin bcomes an input; writing a '0' in the corresponding pin of the TRISx register, the PORTx pin is an output.

In init_system() we must fix port directions for all inputs and outputs in a given application. However, writing and reading TRISx bits is possible any time in software, meaning that we can change port pin direction when required by our application.

port and tris registers

Fig. 2. The diagram used in CSD to represent RAM variables is also applicable to draw PORT and TRIS registers. It is very convenient to indicate bit number index as well to determine PORT bit positions.


Port pin electronic circuit

Fig. 3 is the electronic circuit from Microchip datasheet associated to a generic port pin. It is configurable as input or output depending on the value saved at TRIS register.

Fig. 3. Electronic circuit of a typical port pin where the use of tri-state buffer gates allows pin reversibility. TRIS register bits configures pin direction. 

Thus, as we usually do in our introductory CSD course, to fully undestand the circuit operation, it it possble as shown in Fig. 5, redraw this schematic as if we had to design it in P8 as an advanced digital system. PORT and TRIS pin information can be read and write organising the sequence of control signals (LD) to drive 1-bit data registers.

PORT pin circuit example

Fig. 4. Interpretation of the circuit in Fig.3 using our model for a synchronous 1-bit data register studied in P7 tutorial.


Other materials of interest  

- Microchip PIC18F4520 datasheet.