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.