How a Character LCD Works – Part 2

How a Character LCD Works – Part 2


Hello, and welcome to Episode 2 on how Character LCDs work. So, in the last episode I showed you how you can control these screens using nothing but toggle switches, and if you haven’t seen
that, I suggest you go back and watch that one first. So, in this episode I’m going to try to
show how to connect one of these to a computer. And the computer that I’m going to use is
the Commodore 64. So, you might ask why a Commodore and not
an Atari or an Apple II, or something like that. Well, all of the Commodores have something
called a user port and It goes as far back as the Commodore PET. The VIC-20 has one, the 64 has one, so does
the Plus/4 and the 128. The only Commodore machine that really lacks
a user port is the Commodore 16, which is fairly rare. So, I have no idea why Commodore called this
the user port. But what it really is, its a parallel port
and a serial port all combined into one connector. However, for this particular project, we’re
only interested in the parallel aspect of the user port. If you take a look inside the Commodore 64,
you’ll see it has two 6526 chips. These are input/output chips and they actually
do quite a few things, but what we’re interested in are the 16 lines of general purpose input/output
that these chips have. There are 32 lines in total between the two
chips. These are pretty similar to the general I/O
lines you might have on a Raspberry Pi or a micro controller. However, most of these lines are in use by
the computer for things like the keyboard, joystick ports, disk drive ports, etc. What we’re interested in are the 8 lines
of port B. These go straight to the user port and are not used for anything, other than
whatever we want to use them for. Now, the thing is, 8 lines are not enough
to drive an LCD like this because we would need two more lines for the enable pin and
the register select. However, we can easily solve that problem
by operating the screen in 4 bit mode instead of 8 bit mode. And here’s how that works. Let’s say we wanted to send the number 42
to the screen, since that is the meaning of life, the universe, and everything. Well, we would send this 8-bit binary number
to represent that. And it would be assigned to the 8 data pins
just like I showed in the last video. But, if we set the screen to 4-bit mode, we
would just use the last 4 pins on the screen like this. And we’d send the first 4 bits, then the
next 4 bits. In this mode the screen will always be expecting
two burst of data for every command or character sent to the screen. So, back to our user-port diagram, we will
only need 6 pins to control the screen instead of 8. Of course, we’ll use the ground and +5v
to power the screen. Then we’ll use these last for lines for
the data bits. PB3 can operate the register select. Then PB2 can operate the enable line. So, once we hook the LCD up to the user port,
how do we control it? Well, the 6525 chip occupies a few bytes in
the C64’s memory map. There are only two memory locations that are
relevant to us. The first is 56579. This location sets the direction for all 8
lines on the user port. Because it is an 8-bit register, each bit
represents one of the 8 data lines. So, If you set them one of them to a zero
then that line becomes an input line so that we can read the state of that line. If you set it to a one, then it becomes an
output line that you can control. For our purposes we need it to be an output
line. In fact, just to make things easy, we can
set them all to be output lines by storing the value 255 in this memory location. The other memory location we need to worry
about is 56577. This is where actual reading and writing happens. Since everything is set to output mode, we
can actually write an 8-bit value to this register, and each bit represents the state
of each pin. Let me demonstrate this for you. So I’ve got this edge connector that fits
the C64 user port. I like to print out little labels and attach
them to the sides so that there is no question as to which pins I’m connecting things to. I also like to run a spare piece of wire through
these holes on the side so that I have some way to pull the connector back out of the
machine when I’m done with it. Now I’m going to temporarily attach an alligator
clip to the ground and another one to PB0. Now I’m going to carefully stick this in
the back of my Commodore 64. Next I’m going to turn on the C64 and type
POKE 56579,255 which will turn all of the user port pins to output mode. Now if we look at the voltmeter you’ll see
it’s reading .068 volts, which means the pin is being held low. Now I’m going to type POKE 56577,1, which
should set that particular pin to a high state. And you’ll see the voltage on that pin jumped
up to almost 5 volts now, so that is the high state. OK, so now that we know that works, I’ll
use that pull wire I put in there to yank this out. Next I’m going to wire up one of my LCD
screens to the user port. So I’ll get to soldering. And here we go, a finished product. So I wrote this little test program in BASIC
that will send some simple commands to the LCD, and allow you to type on the screen. So the first thing I’ll do is press 5 to
set the interface length to 4-bit mode. Then I’ll press 4 to send the command to
enable the display. However, this is a multi-part command, so
my program will also ask if you want the display on then if you want the cursor on, and if
you want the cursor to blink. So I said yes to all 3. Unfortunately, it didn’t work. So, I played around with this screen for hours
trying to figure out, you know, did I connect something wrong? You know, what did I do wrong? You know, things don’t always go to plan. I actually pulled this screen out of an old
piece of equipment a long time ago, and to be honest, I’ve never even seen this screen
work before. So, for all I know, there’s something wrong
with it. So, I decided to pull the screen out of my
last contraption with the toggle switches and wire that up the exact same way. However, I knew something was wrong the moment
I turned on the power to the C64. The screen displayed garbage like this. Oddly enough, when I ran my program it actually
did initialize the screen and I was able to type out some characters, even though it was
clear the screen was behaving oddly. Unfortunately, even when I connected this
screen back to regular power away from the C64, it still now displays that garbage on
the screen permanently. So, I spent the next entire day going over
every connection and every detail, checking everything with a voltmeter, checking for
continuity, seeing if I could have possibly wired something up wrong. I simply couldn’t find anything that I did
wrong.. In fact, the really frustrating part about
this is that I’ve done this experiment before about 10 years ago and it worked fine. So, I know it will work. But, the only thing I really did different
back then was I did power the screen externally. And the reason I did that back then was because
I was using a backlit screen and I didn’t think the user port on the Commodore 64 could
supply enough miliamps to run both the screen and the backlight. So I had one more screen handy, and I decided
to wire it up so that it gets its 5 volts of power from this USB charger instead of
the C64. I also wired up the backlight. Now, just for a comparison, I decided to fire
it up here on the bench with just the power and nothing else. And it appears to work as expected. This is exactly what it should look like with
power only. And the contrast control is working. So, time to test it. I unplugged my little SD card reader for the
time being, since I didn’t have that 10 years ago when I did this experiment. Then I’ll plug in the screen. So, the first thing I want to do is just try
powering the screen on again before I even turn the C64 on. And already something appears wrong. I can’t see the two lines on the screen
and the contrast control isn’t working. But it didn’t take long before I noticed
that the main ground wire had come loose. So I needed to go resolder that. OK, so this is getting more and more tense…
this is my last screen. If I fry this one, I’ll have to wait a week
while I order some new ones online. However, things went even further south. Now, for some reason, my C64 is dead. I mean, totally dead. So, things were not looking good. I mean, I couldn’t figure out how I could
have fried my C64. Nothing I did should have been able to cause
that. The only wires connected to the C64 are these
here. And the sheer fact that I was able to send
characters to the last screen confirms that these are all hooked to the right place because
if any one of them were not, it wouldn’t have worked. And I couldn’t see how any of these connections
could damage a screen or a C64. So I took the C64 apart and started troubleshooting. And I found the answer. I didn’t catch this on video, but when I
checked the voltage on the motherboard, it found that it was reading 8 and half volts. It’s supposed to be 5! And, so as soon as I saw that, I shut the
computer off and didn’t turn it back on because I didn’t want to risk further damaging
any of the chips. Hence, why I didn’t catch it on video. However, I measured the voltage on the 5 volt
line of the power supply and look what I got. Dang! 11 and a half volts! So this is unfortunately a very common failure,
if not the MOST common failure of all Commodore 64 problems. The power supply will start sending too much
voltage when it goes bad and thus frying the rest of the computer along with it. And I never actually checked the power output
coming out of the user port, but obviously it was way more than 5 volts and that was
what was frying my screens. So this solves yet another mystery! A few weeks ago I started work on an episode
about speech synthesizer cartridges. and during filming the episode, my cartridge just died. It quite working completely and I couldn’t
figure out why. So, I had to put that video on hold while
I tried to find another working speech synthesizer cartridge. And, so I started the LCD video earlier than
expected. So that’s why I had to run to Fry’s to
buy those parts rather than ordering them online, which would have been much cheaper. Well, now I know what killed my speech synthesizer
cartridge, and apparently this whole thing is just a big coincidence and didn’t have
anything to do with the experiment I was working on. On the bright side, since I was powering the
3rd screen externally, hopefully it survived the encounter. So Brought out my Commodore 64c. I’m fairly confident at this point that
I didn’t do anything wrong, so even though I’m nervous, I’m going to proceed with
the experiment using this computer. Of course, I got a different power supply
and confirmed it was outputting the correct voltage before plugging it. OK, so the screen is powered on and looks
normal. And it is connected to my C64c. I’m going to power on the 64c and so far
everything looks good. So, now I’m going to initialize the screen,
and it looks like that worked. Now I’ll adjust the contrast. So now I’ll try the little clock program
that I wrote. Of course, I wrote all of this in BASIC so
it is kind of slow, but you can see that it does work. By the way, in theory it should be possible
to connect up to 3 screens to the user port. The way you would do that is all three screens
would share the exact same 4 data lines. They would also share the register select. However, PB2 enable would go to one screen,
and then you would use PB1 fo the next screen, and then PB0 for the third screen. That way each screen has its own enable line. So, every screen will completely ignore whatever
is on the data bus until it’s very specific enable line is raised high. I should also mention that you can connect
a character LCD like this to an older style MS-DOS computer if it has a parallel port. The concept is almost identical to what I’ve
just shown you using the parallel port on the Commodore 64. However, the PC doesn’t really have any
easy way for you to go control the registers and stuff of the parallel port like the Commodore
64 does. In fact, that’s one of the things I love
about working with the old 8-bit computers like these is that you have so much control
over the hardware and you can just boot it right up to BASIC and just type a few commands
and just turn pins high and low and stuff like that, it’s just really convenient. OK, so I had also planned in this episode
to show you not just connecting it to the user port, but also connecting a screen to
the cartridge port of the Commodore 64. Unfortunately, with all of the delays and
problems I had earlier in the episode, I decided that is going to be split off into a part
3. But, I think its really important that you
see a character LCD plugged into the cartridge port and there’s good reason why, which
you’ll understand when you see. So, stick around for that.

100 thoughts on “How a Character LCD Works – Part 2

  1. Shouldn't you with a bit of logic be able to use 4 screens (since 3 outputs can produce 8 different combinations of outputs and thus you could wire 4 high and low each?)

  2. If you have DOS on that PC, you can easily manipulate the LPT almost the same way you did on the C64
    If you have some kind of linux, you can easily manipulate it through I think /dev/lp0 or similar

  3. Hello, great channel, i can create a vga port or add a big screen or tv to my akai mpc 1000? I've find this site, http://www.mpchunter.com/category/mpc-3000/page/31/ The akai s 3000 already have this vga port. It should be possible create an additional port and convert the signal of the character lcd to another signal? Thanks in advance.

  4. Nice video and I love that you show us the entire process! This is what happens when you make a project – not everything goes as planed! ha ha ha At first you go bananas and you find out fried components and bad wires ……It happen to me Sunday when we tried with my friend Arduino project and I2C – 4 wires were bad and I used only 6 wires! These wires were brand new and never used before, so I didn't check them at all – trust and burn! ha ha ha Thanks again for your video!

  5. The first time I used one of those LCDs, I simply attached a shift register to the data lines to save on pins.

  6. Love the exercises in trouble shooting. I had many hours of fun using the old ZX-81 and then Sinclair 1000 writing programs that included machine code, building a parallel port that allowed me to make a garden monitor using home brew analog to digital converters and wet and dry bulb thermistors to measure soil humidity to alert when water was needed. Every robotics class could benefit from these basic instructions and trouble shooting methods. Bravo!

  7. You should be able to get 8 lcd displays connected to your C64 if you use a 3 bit to 8 bit decoder chip like a TI SN74HC259N 8-BIT addressable latch found on eBay.

  8. OOPS. lol. still very cool. I'm having trouble interfacing an LCD to my Microprofessor. It CAN be done but programming the Microprofessor aint a walk in the park. ha. Thanx for these vids David. x

  9. I'm so grateful your putting out these videos. Beautifully presented and I'm learning stuff that I've wondered about for many years. Keep up the great work!

  10. David: For some reason, MY C64 IS DEAD (totally. dead.)
    Me: Don't plug that externally or the voltage shares to the user port (am I right?)

  11. 11:35 Using 3 lines (pb2, pb1 pb0) and additional 3-to-8 line decoder/demultiplexer (74238 for example) you can easily connect up to 8 screens !

  12. Putting a 6 volt Zena diode across the Commodore power supply with a fuse should prevent this from happening again.

  13. Parallel port on a PC should be the ultimate in easy to do an output only. Just wire STROBE to the LCD's SELECT. Every character you send to the printer in BASIC should dutifully be sent to the LCD.

  14. I found my Commodore 64 (looks like your C model but doesn't say C on it) a while back but not the power supply, and after seeing your video, I'm glad I didn't find the power supply in case it was bad. I've found a way to take some AC adapters to make a new one for it for the 5 & 9 volts.

  15. I'm dying to know: Did you end up fixing the fried '64? Which chip(s) were massacred by the faulty supply? It's amazing that the chips tolerated that much voltage before dying! TTL usually likes very close to 5v.

  16. you could go up to 8 lcd screens if you use the three enable pins to put out an address (0 to 7) and then a multiplexer to get 8 enable lines back 🙂

  17. How many years would it take to compute the ultimate question to life universe and everything in four bit mode?

  18. The strange thing is that any time you see a component "frying" like that the first thing you should think of is the voltage and therefore the power supply.

  19. Just ran across this, and I know it's a couple years old, so I hope you're not still running to Fry's when you need switches or other parts in a hurry.
    Tanner Electronics has all that stuff and more for far better prices than the mega-store place… (look 'em up, they're in Carrollton)

  20. every time when you turn on your stuff and it does not go well. I dont know why my stomach feel itch and i get frustrated. GBU Best Youtube Channel <3

  21. No idea what your talking about but still binge watch your videos every night 👍🏻👍🏻👍🏻👍🏻

  22. There is something I don't get: how is 4 bit mode set on the LCD in the first place?
    If only 4 data lines are connected,how can a command be sent to tell it to use 4bit mode?

  23. 11:33 In fact, it is pretty easy to connect 8 screens to the user port with a 74138 (decoder/demultiplexer) to control the 8 enable pins. PB0, PB1 and PB2 can be combined into 8 different combinations, and that is what the 74138 uses to enable one of the 8 screens. Now, that would make it impossible to update two or more screens "at the same time", but that can be done in software (a few clock ticks apart, that is). Great video, 8-Bit Guy!

  24. I made custom animated screensavers for a 2 x 16 & 4×16 LCD like rising bubbles, a walking man, and others using the custom character RAM in those. It's not that hard, plus you can create even more custom characters by updating the custom RAM on the fly since it's very limited.

    Great Arduino project, by the way. I've been considering writing an article about it along with providing the code, diagrams, and video examples etc.

  25. I once mounted some USBs wrong on a computer… it was my umpteenth time i mounted those and the first time i got it wrong… then i went and got a great big flash drive… well… i fried that and three more after that… and the geniuses at the store replaced them every time until they got sick of me and just gave me my money back… a couple of weeks later i realized what the problem was and just stopped using that hole

  26. you would probobly like the raspbery pi, going to the python terminal, you can directly controll its gpio pins. sure its python instead of basic. but its nice to have.

  27. Three things:

    You could run seven displays with the three Enable lines from the user port, if you use a demux chip with eight outputs. Just leave one output unconnected and tie the input to 5V, your three user port lines can address the demux to enable any of the seven or none.

    You could have an additional I/O line by using a shift register to send your data/instruction byte. That would only take three I/O to run – serial clock, latch, data.

    Thanks to your power supply troubles, and this is a "common problem" with Commodore PSUs, one might want to start using an in-line voltmeter, maybe with overvoltage protection.

  28. Cool. Still, i'm quite sure that writing to a parallel port in a PC is not that hard. If i recall correctly, it was done using OUT.

  29. I wonder. How to switch it to 4-bit mode (using 4 bit instruction while LCD expects 8 bit)? More reasonably the question is — how to understand if you are sending the first nibble or the second nible (while both operations are identical and you even not sure if it works in 4-bit or in 8-bit mode yet)? What is foolproof sequence of instructions that resets correct mode and correct nibble position (in case if one nibble missed accidently)?

  30. This is why you never trust a brick. Like re-capping is a given for old equipment, similar things go for old computer brick power supplies, and replace them with more reliable switching supplies. You can gut the old brick and install it there, to keep it vintage looking, but it should be done.

  31. I found working with the MS-DOS parallel port quite easy to work with. Just use the "OUT" assembly instruction and off it goes. The equivalent commands are able in C.

  32. This is kind of sad , im way to uneducated in the regards of computing, to understand this video, but it seems so interresting 🙁

  33. Actually, you could get up to 8 screens if you used a 74LS138 3-line to 8-line demultiplexer on lines PB0, PB1 and PB2.

Leave a Reply

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