How a Character LCD works Part 1

How a Character LCD works Part 1

Welcome to another episode of the 8-Bit Guy. So, in this episode I want to show you how
character LCDs work. Now, these things have been around since at
least the 1980s. You can find them in all kinds of electronics
like old computers, music keyboards, synthesizers, calculators, early mobile phones, laser printers,
and are still widely used today on servers, and for hobby projects with microcontrollers.

In fact, they are ridiculously cheap now and
you can find them all over ebay for just a few Dollars in just about every shape, size,
and color you could want. They come in as small as 8 by 1 characters. Some other common sizes are 8 by 2, 16 by
2, and 20 by 4. These screens should all have either 14 ot
16 pins on them.

They can be arranged in different ways, but
they should be labelled 1 through 14. Im going to start by showing you what each
of the 14 pins do. The first pin is ground. The next pin is +5 Volts.

So these two wires are essentially what gives
the screen power. The next pin receives an analog voltage to
set the contrast of the screen. Typically this is done by connecting it to
the middle pin of a potentiometer. Then the other two leads on the potentiometer
go to +5 volts, and ground.

So the signal you are feeding it will always
be somewhere in between those numbers depending on where you turn the knob. The next pin is register select. So the screen can accept two types of information,
one is text data. Thats basically just putting ASCII characters
on the screen, the other option is instructions, which tell the screen to do stuff like turn
the cursor on, initialize the display, create graphics characters, things like that.

So imagine you had a toggle switch you could
hook up this pin to the center of the switch and then connect 5 Volts to one side, and
ground to the other. That way when you move the swtich back and
forth it will pull the line high or pull the line low, telling it which type of data you
want to send it. The next pin is for read/write. Yes, besides just sending information to the
screen, you can actually read information from the screen.

And you have to pull it high for reading,
or low for writing. The next pin is the enable pin. Ill come back to this in just a minute. The next 8 pins are the data bits 0 through
7 which represent an 8-bit binary number.

All of these pins need to be set either high
or low, just like the last few. So back to that enable line. This is the final piece of the puzzle. Basically, once youve set all fo the other
pins exactly how you want them, then you set this line high and that will feed all of the
information into the screen.

Also, some screens have 16 pins, and those
are to accomodate a backlight and so thats just the power source for the backlight. Ive hooked these screens up to all sorts
of things, and I plan no showing you how to hook one up to a Commodore 64 here shortly. But, before I do that, it occurred to me that
it might be possible to control these screen without any sort of computer at all, using
nothing but toggle switches. So I set out to construct such a device.

So I played around with my design here in
a paint program and this is what I came up with. Obviously Ill connect these two pins to
power and ground. This one for contrast. A toggle switch for register select.

The read/write pin will go straight to ground
because Im not going to be reading anything, Im only going to be writing data. Then Im going to use a pushbutton on the
enable line. And then, of course, 8 toggle switches for the data lines. So,I went to my local Frys Electronics
to pick up some toggle switches.

I could have gotten them a lot cheaper on
line but I didnt want to wait for shipping. This single pole double throw ought to work
fine. I would also need a push button for the enable
line, so I picked this one. So heres all of the stuff I picked up.

I got this nice little project box to mount
everything in. Im going to use this 16 by 2 LCD that I
pulled out of an old ISDN modem years ago. Im just going to test-fit the LCD screen. OK, so heres all the switches mounted.

This reminds me of an old Altair computer,
only this will be a lot simpler. So heres the potentiometer for the contrast
control. And heres the pushbutton. I also have a nice little knob to fit on the
contrast control.

I printed out some labels so that I could
better see what each switch is for. And heres what it looks like so far. Now its time to start wiring up the inside. So Im just going to use a big piece of
solid core wire and mount it across all of the leads on these switches.

Now that those are all soldered on, I can
actually use the spaces in between to connect all of the other wires that need to connect
to either ground or +5 volts. Im also going to need a power cable. Since USB is 5 Volts, Im just going to
cut the end off of those USB cable, then Im going to wire up a barrel jack to the end. And, of course, Ill need a barrel jack
on the back of the box so Ill install that too.

When I need a bunch of small wires of different
colors, I usually just take an old scrap multi-conducter cable like this one and strip it back and
cut off a bunch of wires. Unfortunately, when I started soldering wires
to the LCD, I noticed that one of the solder pads was missing and I couldnt solder to
it. So, Ive had these little screens around
forever and desoldered and resoldered to them probably dozens of times because Ive used
them in a lot of different projects, you know, just temporarily. And thats an unfortunate side effect of
continually desoldering and soldering to those little pads.

Sometimes they just pull right off. However, I do have another one just like it
so Ill use that one inside. But it does have some ribbon cable still attached
so Ill need to desolder that. So after I removed the ribbon cable and cleaned
up the flux on the board I noticed that it was also missing not one, but TWO solder pads.

So I simply wont be able to use those. I do have another LCD but it is a smaller
8 by 2 character display and much too small for the hole I made. So it looks like Ill have to use this larger
20 by 4 character display instead. It will barely fit.

It does have a pin header soldered into it,
but after the bad luck I just had with the other two screens, Im just going to leave
that in place and solder wires directly to the pins like this. And once Im done Ill run some heat shrink
over the pins just to be on the safe side. I think thats going to work out just fine. So, Ive cut a larger hole in the box.

Its not as elegant as the first one because
I had too much stuff in the way this time. Now all thats left is to connect up all
of these wires to the right switches. There is one problem, though. The push button switch only has 2 leads, not
3.

So there is no way to alternate a signal between
high and low. If you leave a pin unattached, its called
a floating pin, and thats bad because it can randomly pick up static in the air and
alternate between high and low on its own. So what Ill do is attach a resistor to
ground. That will keep it pulled low.

Then when I push the button it will over power
the resistor and pull the line high. So lets try it out. Ive got a chart printed out to show me
binary digits for ASCII characters, and a few sheets showing all of the instructions
for the screen. But things didnt go exactly to plan.

All right. So, heres the deal. So this is actually a normal thing to see
when you fire up an LCD screen. Just have these little two lines kind of lit
up.

The contrast does work. However, I couldnt get anything else to
work, until eventually I realized that all of my buttons are upside-down. My switches are upside down. This is upside-down.

All of these are upside-down. So, Im going to have to think about this
for a moment. So, I want to turn on the display. So Im going to move, I want it on instruction,
so yeah, its actually going to be opposite of where I need.

And this should be the sequence to initialize
the display. And bam! It works! It looks like we need to adjust the contrast
a little bit. So, now we want to set the data path. OK.

Now lets see if we can send some data. OK, so one of the things youre probably
going to notice is that every time I push one of these, I get more characters than I
wanted to. And thats because of a bounce problem. So lets talk about bounce.

When you have two pieces of metal on a switch
coming together, now it may seem like the touch instantaneously, but in reality they
actually bounce every so slightly when they first touch. Now, its imperceptible to use humans, but
digital electronics are fast enough they can actually see the bounce and to them it seems
like youve pushed the button multiple times. So what we need to solve that is to add a
capacitor to the switch. That slows down the transfer of power because
it takes a short delay for the capacitor to charge and discharge, thus smoothing out the
behavior of the switch.

So lets test it out again. All right, so were going to try this again. Power it on. There we go.

OK, well set the font. And now, lets try sending some characters. OK. It looks like our debounce is working.

Were sending characters without repeats
now. OK, so this is the inside after everything
is done. Now Its time to finally screw the bottom
plate on. I cant easily rotate my switches around,
but I can change the labels on here so that the register select is showing correctly.

Unfortunately my data bits are still upside
down. Ill put the contrast knob on now. All right, so Ive written out my name here. So, one of the interesting things that Im
going to show you is if you want to cursor around, youre going to want to set to instruction
mode and then zero zero zero one.

OK, that should let me move the cursor to
the left. And I can change direction by flicking this
switch and I can move it back to the right. However, instead of moving the cursor, I can
move the entire screen by moving this switch. Look at that.

And I can move it back the other direction. So thats just some of the interesting things
that youll learn playing with this. And you can see the contrast adjustment seems
to work pretty well. So heres one final look at this device.

And heres what it looks like in the dark,
since this particular screen is backlit. All right, so I think this is a pretty cool
little educational device. You know, learning how to use the binary information
and key it into the screen is probably a really good learning tool for someone getting into
digital electronics. Anyway, I was going to show you how to connect
this up to a Commodore 64 both on the cartridge port and on the user port.

However, this video is getting a little long. So Ive decided to split that off into a
part 2. So, hopefully youll stick around for that. And I hope this episode wasnt too technical
or boring or anything like that.

Because, Id kind of like to make a little
more technical videos like this every now and then but you know I run the risk of going
too deep, and that might not work for some people, so let me know what you think in the
comments, and Ill see you next time!.

No comments:

Post a Comment