Module 3 : Introduction to PIC Microcontrollers

Lecture 19 : I/O  Port Configuration

Discussion on I/O ports of PIC16C74A:

PIC16C74A has five I/O ports. Port-B, Port-C and Port-D have 8 pins each. Port-A and Port-E have 6 and 3 pins respectively. Each port has bidirectional digital I/O capability. In addition, these I/O ports are multiplexed with alternate functions for the peripheral devices on the microcontroller. In general, when a peripheral is enabled, that pin may not be used as a general purpose I/O pin. Each port latch has a corresponding TRIS (Tri-state Enable) register for configuring the port either as an input or as an output. The port pins are designated by the alphabet R, followed by the respective port (viz. A, B, C, D or E) and the pin number. For example, Port-A pins are named as RA0, RA1, etc.


Port-A pins RA0-RA3 and RA5 are similar. These pins function (alternate function) as analog inputs to the analog-to-digital converter.

Fig 19.1  RA0-RA3 and RA5 pin of Port-A

The structure of Port-A pins RA0-RA3 and RA5 is shown in the figure. TRISA register decides whether the port-pin is configured as an input or as an output (digital) pin. Setting a TRISA register bit puts the corresponding output driver in high impedance mode. In this mode, the pin can be used as a digital or analog input. Clearing a bit in the TRISA register puts the contents of the data latch on the selected pins, i.e., the pin functions as a digital output. Pins RA0-RA and RA5 have current sourcing capability of 25mA.

The alternate function of RA4 pin is Timer-0 clock input (T0CKI). RA4 pin is an open drain pin and hence requires external pull-up when configured as output pin. It is shown in the following figure.
Fig 19.2  RA4 pin Configuration
Configuration of Port-A pins
Example :     Set RA0-RA3 as outputs and RA4 - RA5 as inputs.

bcf STATUS, RP0 ;           Select Bank-0
clrf PORTA ;                       Clears the data latch
bsf STATUS, RP0 ;           Select Bank-1
movlw 30H ;                       W 03H ( data direction )
movwf TRISA ;                   Set RA0-RA3 as outputs, RA4-RA5 as inputs


Port-B is an 8-bit bidirectional I/O port. The data direction in Port-B is controlled by TRISB register. Setting a bit in TRISB register puts the corresponding output in high impedance input mode. When a bit in TRISB is made zero, the corresponding pin in Port-B outputs the content of the latch (output mode).

Each port pin has a weak internal pull-up that can be enabled by clearing bit   of OPTION register (bit-7). When a pin is configured in the output mode, the weak pull-up is automatically turned off. Internal pull-up is used so that we can directly drive a device from the pins.

Fig 19.3 Pins RB0-RB3  of Port-B
Configuration of Port-B pins
Example :          Set RB0-RB3 as outputs, RB4-RB5 as inputs, RB7 as output.

clrf PORTB
movlw 70H
movwf TRISB