How to drive 5V inputs from 3.3 V microcontroller with 5V tolerant inputs

Recently I bought a serial graphical LCD from Ebay. I thought I’ve checked everything before buying it, but I was wrong!  When they arrived I realized I’ve bought the 5V version  instead of 3.3V version. I was going to use PIC 18F46J50 for my project but it was a 3.3V microcontroller. Then I found a neat trick (which was actually from the datasheet of PIC 18F46J50) which uses 5.5V input capable pins of PIC18F46J50  to drive the 5V inputs . This article is all about this cool technique. To use this technique you should find pins which has the capability to withstanding 5V or higher voltage. The table 10-2 in page 132 of the datasheet for PIC18F46J50  tabulates the tolerated input voltage of the pins.


Above table shows inputs with 5.5V capabilities. As we can see we can use all the pins of portD, 2 pins (portc.7, portc.6) of portc , 4 pins(portb.7, portb.6, portb.5, portb.4) of portb.


The above schematic excerpt show how to connect 5V tolerant inputs to LCD. Note the pull up resistor to 5V. The value of this resistor is not critical but you can use 1k  as a starting point. In case the inut pins of the LCD needs more current you may have to decrease the resistor value. How are we going to drive the input of the LCD using input pins of the microcontroller? Well, actually the pin is going to be an input when we need logic high and output when we need logic low. That’s where the trick in software comes in. Below is the code to toggle  pin RDO.

void main()

//First Clear the LATCH register for the particular bit
LATD0_bit = 0; //If we make pin an output then it will read zero
TRISD0_bit = 0; //Clear the particular tris bit to make it an output
//At this point we will read logic zero as we have set the output pin to clear latch register
TRISD0_bit = 0;//Output low
Delay_ms(1000); //1 second delay
TRISD0_bit = 1;//Make the pin input (Hi_z) so it will read 5V from the pull up resistor
Delay_ms(1000) //1second delay

 The above code is self explanatory but here is brief explanation. When you need low logic level you make the pin an output and drive it low. This will pull down the voltage of the resistor and LCD input will read zero. When you need high logic you make the pin an input. This will make microcontroller pin Hi_impedance. In another words it will not pull the resistor voltage to ground. As a consequent 5V will appear at the LCD.

The code above is written in MikroC but readers can choose a compiler of their choice. Hope you will use this fast and dirty trick in your projects.

Leave a Reply

Your email address will not be published. Required fields are marked *