I/O Interfacing
Release 1.2 March 21,2004

Proper interfacing to and from a PIC or any microprocessor chip is important. Improper hookup can cause damaging or erratic operation. 

If you just want to light an LED from an output port of the PIC from the existing 5 volt supply, you can use the following circuit:

Clearing the bit A.1 will illuminate the LED

Setting the bit A.1 will illuminate the LED

Remember! The PIC chip only has enough drive to light only one LED. Trying to light more may damage the PIC.

If you want more drive to illuminate an incandescent lamp or activate a relay, you can use an external transistor.

The following shows the proper way to illuminate an LED with a bi-polar transistor driver:

If you use a VMOS FET device such as a BS170, 2N7000, or VN10KM, you can eliminate the input resistor and use the following circuit:

Another advantage of using an external transistor is that the power to operate the LED can be higher than 5 volts as long as you use the appropriate resistor to limit LED current.

Below is an example of driving a relay with a PIC:

If you want to isolate the output of the PIC to drive different power and/or ground circuits, use an opto-isolator as shown below. Note the resistor value K33 is 330 ohms. See Component Identification for further information.

Setting Register bit A.1 high will give a low output as shown above.

Isolated inputs to the PIC can use the following circuits:

A logic high on the input will generate a logic
 low on port A.1

A logic high on the input will generate a logic
high on port A.1

R1 should be calculated to generate 20 milliamps of current from the positive input voltage.

Level shifting can be accomplished by using a VMOS device and a resistor. Circuit 30 shows how to interface to another voltage other than +5 volts.

Circuit 30

+V can be any voltage from 3 volts to 40 volts. Higher voltage may require a higher value for R1. Of course the logic level is inverted by Q1 so you may have to invert the bit in software. Q1 can be any VMOS device like the BS170, 2N7000, or VN10KM.

To interface from an electret condenser microphone element, the following connections must be made:

Circuit 27

A voltage between 5 and 12 volts is required to power the microphone element. If using 12 volts, you can increase R1 to about 4K7 ohms or higher. Use an opamp to increase the gain to a usable level. A circuit can be designed from the OPAMP Design page.

2004 Rick C.