You are on page 1of 4

learn design share

Single Wire LCD Interface


Control your LCD display using just one data wire
By Detlef Hanemann (Germany)

Anyone with hands-on experience of installing multiple


types of microcontroller
knows that in the process
of circuit development
they are often forced
to add one extra
function after another.
Eventually they reach
the stage where
the number of I/O
pins available is no
longer sufficient.
Only three options remain
now: do without some of the functions
(reluctantly), employ a larger chip (sometimes one
doesn’t exist) or use a so-called port expander (at extra cost). All three workarounds have their pros and
cons. A developer’s life would be made considerably easier using peripherals that took up only one port pin
of the microcontroller. And that’s precisely what the interface for commonly used LCDs described here does.

Using small microcontroller like, say, an in parallel, as many LCD modules do. In Therefore we have relocated the neces-
8-pin ATtiny from Atmel, we’re left with addition, the increased pin-count usually sary conversion from serial to parallel
just five GPIOs remaining after discount- complicates the soldering, because the away from the actual microcontroller
ing the two supply pins, assuming we inter-pin distances are reduced. circuit into a module that contains the
wish to retain the reset pin. That’s not If you neither wish to use larger control- necessary conversion electronics, so that
many. A larger chip with more pins not lers nor forego functions, then you are inexpensive, widely available LCDs can be
only takes up more surface area of the forced to use a port expander, consist- used. A display upgraded in this way can
PCB but we still run out of pins rapidly ing usually of shift registers connected then be connected to any microcontroller
after connecting all the press buttons, either by I2C (slow) or by SPI (requiring with minimal effort.
LEDs and other peripherals, especially an extra pin). Even then, the shift regis-
if they demand that data is transmitted ters use up at least two or even three pins Single-wire solution
of the microcontroller for converting the Long before the Internet age people were
data into parallel format and transferring already aware of methods of tricking a
Technical specification this to suit the particular interface of the shift register into accepting serial data
LCD module. This kind of kludge certainly using fewer inputs than were actually nec-
• Universal interface for parallel LCDs
leaves potential for optimization. essary. The simplest possible shift register
• Serial addressing using only one
has at least two inputs, one for data and
GPIO line
Optimal solution one for the clock. The clock is necessary
• Plugs into LCD modules with
The attainable optimum just has to be to determine the point in time at which
differing pin configurations
the use of a single data line. Anything the level on the data input is valid. How-
• Compatible with low-cost LCD
fewer would be impossible and any more ever, if you generate a special combined
modules
than one not really necessary, as an LCD data + clock format, you can then sepa-
• Minimum transfer time for a
only receives data; it doesn’t send any. rate the data from the clock using a sim-
character = 0.8 ms
An optimum solution should not require ple resistor and capacitor (RC) element.
• Compatible with all microcontrollers
reinventing the wheel each time either. Figure 1 shows how this process works

92 September & October 2015 www.elektormagazine.com


labs project reader’s project

in principle. There is one prerequisite, came up with a circuit using a simple


that the shift register is edge-triggered alternative control signal to achieve a
Shift Register
and reacts to a rising edge — which is different method of data acquisition into
the case with many of these chips. When the output register and delivery to the serial in Q0
there is no signal transfer happening, the LCD module. clock in Q1

parallel data outputs


R
quiescent level is High. In this state both Q2

inputs are at High level and there is no Single-wire circuitry Q3


Q4
activity. If a short pulse (measured by As seen in Figure 2, the control signal
data in Q5
the time constant of the RC low-pass) passes from Pin 3 of K1 to the two dif- Q6
occurs, the data input remains High and ferent low-pass filters. The fast filter (R1 Q7
C
as a result the rising edge of the (nega- and C1) has a time constant of approx-
tive-going) pulse clocks a High into the imately 10 µs and drives the data input
internal register. If we now wish to push Pin 14 of IC1. The slow one (R2 and C2)
a Low into the register, then we need has a time constant of around 200 µs, 130397 - 13

only make the negative input pulse much however, and does not control the inter-
longer, so that the voltage at the data nal data acquisition for IC1 (as with the
input falls to Low. The input signal now solution in [1]). Instead it enables a reset Figure 1. Block diagram for controlling a shift
consists of a sequence of short and long of its Pin 10. Data acquisition is therefore register via an RC low-pass filter using only one
negative pulses — depending on the bit solved in a different way. data line.
pattern being transmitted. If you select
the timings appropriately, the solution
functions very reliably.
+5V R6
To avoid the data piling up sequentially bit 68R
1
K3
by bit on the parallel outputs and caus- 2
BACKLIGHT
ing indeterminate states there during the 1 3 5 14
LCD_D7
13
clocking-in period, shift register ICs are JP1 LCD_D6
12
LCD_D5
generally provided with an output reg- 2 4 6 11
LCD_D4
ister that takes in data from the actual 10
GND
9 K5
shift register only ‘on demand’ and then GND
8
defines and organizes the data at the +5V +5V GND LCD
7
GND
outputs in one fell swoop. To this end, K1
6
LCD_ENABLE
5
therefore, a third input is necessary. As 1 3
C4 GND
4
LCD_REG SEL
would seem natural, a solution was found 3
2 R1 R2 100n LCD_V_LCD
from authors on the Internet such as [1] 16
2
+5V
2k2

47k

1
by simply using a second RC element with VCC
QA
15 GND

greater time constants. Here, however, 14


SER QB
1
2
short and long pulses would not suffice 11 IC1
QC
3
SCK QD
for bringing the input for data transfer 10
SCL QE
4 1
5 2
K4
down to Low. This pulse must then be QF BACKLIGHT
12 6
very long. Altogether we now require a C1 C2 RCK QG
7
14
LCD_D7
QH 13
control signal containing the short (High), 4n7 4n7 74HC595N
LCD_D6
12
13 9 LCD_D5
long (Low) and very long (acceptance) G QH' 11
GND LCD_D4
pulse. This solution also works well, albeit 8
10
GND
9 K2
with a couple of restrictions: the final bit 8
GND
GND LCD
must always be Low and can therefore 7
GND
not be used for serial-parallel conversion. 6
LCD_ENABLE
5
GND
+5V 4
LCD_REG SEL
For connecting an LCD module we’re 3
LCD_V_LCD
left with one further problem, however. 2
+5V
R3 R4 R5 1
Although data is transferred to com- GND
10k

22k

10k

monplace two-line LCDs using the Hita-


chi HD44780 controller (or compatible
T1 P1
types) mainly in the ‘4-bit parallel’ mode, C3
which handles seven data bits easily, it 2k2
4n7
expects to see a positive pulse in order BS170
for the LCD to accept the data delivered
130397 - 11
by the shift register. To generate a pulse
of this kind we need to transfer each data
word twice over, which is inconvenient Figure 2. The author’s solution with two RC low-pass filters uses one element of the 74HC595 shift
and wastes time [3]. Therefore the author register.

www.elektormagazine.com September & October 2015 93


learn design share

bits clocked in and a reset triggered by


a fairly long negative control pulse on
Pin 10, QH’ is now set to Low, with QH
and the other outputs remaining as they
were. C3 and R3 together activate the
monostable of T1 to enable acquisition
of data for the LCD. After some recovery
time for R2/C2 the next data word can be
transferred. Figure 3 shows the progress
over time of the various signal levels at
the relevant stages of the circuit.

The timings for the Low, High and Reset


pulses selected by the author mean that
the transfer of an 8-bit data word to the
LCD takes around 1.3 ms. As you can
see, other than the four data bits QA to
QD (bits 0 to 3), the only other infor-
mation needed is QG for controlling the
register selection of the LCD. QE and QF
offer two additional pins you can define
for your own purposes. While Luc Lem-
Figure 3. Oscillogram with the following signals: yellow = control signal, violet = data input Pin 14,
mens in Elektor Labs was doing some
blue = reset input (Pin 10) and green = signal at QH’ (Pin 9 of IC1).
fine tuning and developing a PCB layout,
he provided K2/K4 along with K3/K4 as
Responsibility for data acquisition into which the very first High applied for bit 7 pinheader strips for connecting the LCD
the output register of IC1 is handled by arranges on the last clock timing for the display. Regular two-line LCD modules
Pin 12, which also looks after the LCD_ acquisition of data into the output register vary mainly in whether physical connec-
Enable input of the LCD module at K3 of IC1. Pin 12 of IC1 is linked to its QH’ tors are provided on the upper or lower
or K4 respectively. The positive pulse output, which in fact is responsible for surface of the device (and in which order)
for the LCD is produced at the end of cascading ICs of this kin d and is conse- or not at all. Other variations concern
each data word transferred using the quently linked directly to the shift register. the polarity of the backlighting (and fre-
monostable constructed around T1. This The reset input of IC1 deletes — in this quently even the pin assignment). This
is feasible thanks to a special feature of IC only — the status of the shift register makes it impossible to say whether our
the 74HC595 shift register employed, in but not the output register. With all the interface truly works with all modules.
Luc is certain, however, that by providing
K2 plus K4 together with K3 and K5 (and
Component List selectable polarity for the backlight using
JP1), he has achieved the best possible
Resistors
All 5%, 0.25W. flexibility and compatibility. In addition,
R1 = 2.2kΩ in 0 Luc has reduced the time constants of the
+

R2 = 47kΩ 1
RC elements against the author’s version
R3,R5 = 10kΩ
R4 = 22kΩ for more stable data transfer. Inciden-
R6 = 68Ω tally, in your own programs you should
P1 = 2.2kΩ trimpot, large, horizontal not make the duration of the Low pulses
Capacitors any shorter (to avoid jeopardizing stabil-
C1,C3 = 4.7nF, 0.1” pitch ity). On the other hand you are free to
C4 = 100nF, 5mm pitch lengthen the High pauses. In the demo
software Luc has also made provision for
Semiconductors
T1 = BS170 a trigger signal to Arduino Digital pin 9
IC1 = 74HC595, DIL (see prototype photo). This is for test
purposes and you can of course omit this
Miscellaneous
in your own implementation to save pins.
K1 = 3-pin pinheader, 0.1” pitch
K2+K4,K3+K5 = 16-pin pinheader or 16-way
pinheader receptacle*, 0.1” pitch Construction and operation
JP1 = 6-pin (2x3) pinheader, 0.1” pitch
There is really not very much to say about
2 pcs jumper, 0.1”pitch
LCD module, 2x16 characters* populating the board seen in Figure 4.
PCB # 130397-1* With only one wired IC and ten passive
Figure 4. Component side of the PCB for
single-wire LCD interface. non-SMD components, there is nothing
* see text
insurmountable even for raw recruits to

94 September & October 2015 www.elektormagazine.com


labs project reader’s project

soldering. The only thing to


watch out for is the functional
order of the connection pins
of the LCD and whether it is
equipped with male or female
connectors. The pin assignment
is usually printed on the LCD
board — if not, the data sheet
will assist. Figures 5 and 6
show the prototype plus LCD,
together with an Arduino.

Take care with the connections


and polarity of the LCD back-
light. Two jumpers look after
the latter. When jumpers JP1
are closer to K3 (linking 1 with
3 and 2 with 4), they arrange
for the (positively charged)
anode to be on the outermost
terminal of K3 and on the
innermost terminal at K4. However, if Figure 5. Prototype of the single-wire LCD interface, mounted on the rear of an LCD module.
the two jumpers of JP1 are closer to K4,
the situation is reversed. The combination
of interface and LCD is linked direct to As usual the layout files for the PCB as
the microcontroller extension board via well as the sample code (for the Ardu-
K1. It’s important here that the supply ino) are available free at the web page
Web Links
voltage of the microcontroller being used for this article. Configuring this for the
is the same as that of the LCD module. particular microcontroller used should not [1] Roman Black’s solution:
If the character stream output by the pose any problems thanks to the ample www.romanblack.com/shift1.htm
(correctly) programmed microcontroller commentary provided. You can of course (and do check out the rest of his
cannot be read on the display, it’s worth also obtain the small double-sided PCB ‘minimalist design’ website)
first checking whether the contrast is set ready etched, drilled and overprinted in [2] www.elektormagazine.com/130397
correctly using P1. the Elektor Store [1]. [3] www.elektor-labs.com/node/3598
(130397)

Figure 6. Single-wire LCD interface in action, connecting an Arduino board to a display.

www.elektormagazine.com September & October 2015 95

You might also like