Most LCD character displays connect to the outside world via a controller IC, such as the HD44780 (Hitachi) or equivalent. However, that interface has serious drawbacks. It uses a large number of the microcontroller's general-purpose I/O (GPIO) pins, and it can't provide digital contrast or backlight intensity control.
The circuit in the figure reduces the required number of GPIOs from 11 to two while also supplying digital control of the LCD's contrast and backlight intensity. A versatile I/O-port expander (U1) emulates the typical 8-bit I/O port of a microcontroller. You can implement this interface with little or no extra code if your microcontroller integrates an I2C peripheral. As an alternative, you can bit-bang the required signals through the regular GPIO pins.
Op-amp U3b buffers digital-to-analog converter (DAC) output OUT1, which controls the contrast voltage. DAC output OUT0 controls a constant-current sink consisting of op-amp U3A, MOSFET N1, and resistors R1, R5, and R6. This current sink draws 500 mA when the DAC voltage output is at full scale.
You may need to adjust the maximum LED backlight current according to the LCD display size. To do that, use the following equations to calculate resistor values R1, R5, and R6:
R1 = (VDD(MIN) — VFLED(MAX) — RDS(ON) —IFLED(MAX))/IFLED(MAX)
PR1 = IFLED(MAX)2 × R1
R5 = R6\[(VFS(DAC)/(R1 ×> IFLED(MAX)) — 1\]
VDD(MIN) = minimum anode supply voltage (4.5 V typical),
VFLED(MAX) = maximum forward LED voltage,
IFLED(MAX) = maximum forward LED current,
RDS(ON) = on resistance of switch N1,
VFS(DAC) = full-scale voltage output of DAC,
PR1 = minimum power rating of resistor R1, and
R6 = 10 kO.