Welcome back to Character LCD part 3.
Just as a refresher, in part 1 I showed what the various pins did on a character LCD, and
then I constructed a device which would allow you to manipulate the screen using nothing
but toggle switches.
And then, in Part 2 I showed connecting an LCD to the user port on a Commodore 64.
And then I promised I would follow up with a Part 3 where I connect the LCD to the cartridge
port.
And here we are a year later and I’m finally brining you that.
You see, I actually had some problems getting it to work.
So, I had to shelve the video for well, quite some time.
So, looking again at the pinout for an character LCD, I wanted to draw your attention to the
8 data lines it has, D0 through D7.
Now take a look at this diagram of the 6502 processor, which I’ve shown many times in
the past.
It also has 8 data lines marked D0 to D7.
So you might be wondering if it is possible to connect these 8 data lines on the CPU directly
to the 8 data lines on the LCD and allow them to communicate this way.
Well, yes.
In fact, that’s how these LCDs were originally intended to be used in the first place.
In fact, the Read/Write line on the CPU can also connect to the Read/Write line on the
LCD.
So, we seem to have a perfect harmony here.
(So happy together….)
So, it’s almost a perfect match, right?
But we still need to figure out what to do with the enable line, which tells the screen
to actually pay attention to the data on the bus, along with the register select which
tells the LCD whether this is instruction or data that is supposed to be coming in.
Well, that’s where those 16 address lines on the CPU come into play.
You see, when the CPU wants to read or write to a piece of memory, these address lines
are set to produce a number somewhere between 0 or 65,535.
Ideally, however, we would want the LCD to be somewhere in this designated input, output
region.
Well, as luck would have it the C64 engineers have already done part of the decoding work
for us.
Looking at the cartridge port, the CPU’s data lines are present there already.
And we’ll need one of these grounds.
And there’s the read/write line.
And then there’s this one called I/O1.
This line is already configured to go low whenever the CPU accesses memory address DE00,
or in decimal thats 56832.
So, we’ll connect the IO1 line from the cartridge port to the enable line on the CPU.
That way when we’re writing to that memory address, it should enable the LCD.
But what about that register select line?
Well, if we connect that to the CPU’s address 0 line, then we should end up with a scenario
where I can write to memory address 56832 and that will be the instruction input for
the LCD, and then if I write to the very next address, 56833, it should send data to the
LCD screen.
So with these two memory locations in the C64 I should be able to completely control
the LCD.
But, there’s only one problem that I can see.
You see, the LCD’s enable line is expected to go high to activate the LCD, but the Commodore
64’s IO1 line goes low when it’s active.
So, we need to invert that signal.
So I’m going to use a 74AC00, which is a standard off the shelf logic chip, known as
a quad nand gate.
If you peer inside of the chip you’d see there are actually 4 separate nand gates.
The chip is pretty simple.
You connect 5V of power here, and ground here.
And the IO1 line connects here.. and then we’re going to do some other crazy stuff
with PHI2 which has to do with the timing of the C64’s clock signal.
Now, ideally, I need one of these prototyping boards for the Commodore 64.
But I didn’t want to wait to order one of these, so I had the idea to just chop up this
broken voice synthesizer cartridge since it had all of the pins I needed available.
But first I need to remove everything on the board.
The easiest way to remove chips that are burned out is to just clip the legs off like this.
This particular board was fried when the power supply on my C64 went bad last year and started
sending nearly twice the voltage it was supposed to be sending over the 5 volt line.
OK, so after removing all of the parts, I’m just going to clean off the flux from the
board with some alcohol.
And there we go.
So, I bought a couple of brand new screens from eBay that we could try here since I ended
up frying some of my other ones if you recall.
Next I’ll go ahead and connect this pin header to the screen.
And there we go.
And next I’m going to use this prototyping board I bought at Radio Shack right as they
were going out of business last year.
And I’m just going to slide that down in there like so, and solder this in.
Of course, I don’t need these pins to be this long, so I’ll chop off the excess.
And now I’ll finish the soldering.
And here’s the little quad nand gate I mentioned.
Of course, I’m going to need to join that, to that, and I’ll just use this ribbon cable.
Ok, so I’ve soldered the ribbon cable on to all of the different places I need to get
signals from.
Next, I’m going to be creating some little jumpers out of some little solid core wire
pieces I’ve bent into shape.
I try to do this as elegantly as possible so I can easily see where all of the wires
are going.
And don’t forget we need a potentiometer for the contrast control.
And here we go..
It’s all done.
It isn’t the most beautiful design due to the two separate boards, but I think it should
work.
So, let’s power it on.
And then I’ll set the contrast.
It was at this point I realized the screen was actually upside-down from the orientation
I thought it was.
At least it wasn’t an upside-down screen on a bomb like a certain somebody did.
Well, let’s plug it into the C64’s cartridge port and see if my C64 goes up in smoke.
And the good news is, it seems fine.
Now time to test it.
So I’ll send some commands to tell it to initialize the screen, and it actually works.
However.
Every time I send it data to put on the screen, the cursor advances, but nothing actually
shows up on the screen.
I spent hours, really days actually, troubleshooting this.
I couldn’t figure out what was going on.
I could actually send any instruction to the screen that I wanted to and it would work,
like moving the cursor around, resetting the screen, stuff like that.
But, I simply couldn’t get any data to go through.
And, I couldn’t figure out why, so I turned this project over to a friend of mine, David
Hunter, who is an electronics expert and he actually managed to figure it out.
And he even had these two little boards custom manufactured for me, which are really neat.
So, it turns out there were some weird timing issues with the 6502 processor that I didn’t
take into account and he solved this with a few extra logic chips.
I think he also put some data bus buffers on here to help isolate the screen some from
the CPU as an extra precaution.
So, let’s try it out.
OK, so let’s try sending it a couple of commands.
I’ll start with a POKE 56832.
Now to be clear, in Commodore BASIC the command POKE simply writes to a memory address.
This part represents which memory address to write to, and the next number represents
what byte to store in there.
So I’ll plug in a 60 there which will initialize the screen and define how many lines it has
and so forth.
And there we go.
Screen is working.
Now let’s try poking something to address 56833, such as 65, which is the ASCII code
for the letter A. And looky there, we have an A. Lets try a B, and that worked.
And a C. So this is sort of time consuming, so I wrote a little test program in Commodore
BASIC.
With this program I can type in a few words, such as Commodore 64.
Now, one thing I have to warn you about on these character LCDs is that the order in
which the text comes across is a little bit weird.
You might think that if you kept sending characters that once it hit the end of the screen, that
it would automatically wrap around to the next line.
But it doesn’t.
You see, it doesn’t matter whether your LCD is a tiny 8 by 1, 16 by 2, or or a 20
by 4, they are all configured more or less like a 40 by 2 line LCD.
And so you have to send it a full 40 characters before it will wrap around to the next line.
so our 16x2 character display we’re using here sort of fits like this.
Fortunately, the screen on the Commodore 64 Is 40 characters wide, so we can just put
a bunch of spaces until we wrap around and then type our next line.
As you can see, that worked out just fine.
Hey, I like this, I think this will make a great thumbnail for this video.
And believe it or not, if you are using one of those 4 line displays, it’s like they
split this screen in half, and over here is the top part, and over here is the bottom
two lines.
So when you type out characters on these, it skips over one line, and then goes back
up to the second line, and finishes on the 4th line.. which is sort of irritating when
writing code for these things.
But, enough about that.
Let’s talk about graphics.
These little character LCDs can actually produce up to 8 custom characters that you can program
to look like whatever you want.
And if you place all 8 of the characters together like this, then you can sort of create a tiny
bit-mapped screen that you can draw whatever you want.
So, in order to demonstrate this, I wrote another little program in Commodore BASIC.
This one allows you to cursor around on the screen and draw different patterns.
I’ve even included the spaces between characters so that it looks authentic.
Once you’re done drawing, you can press F1 and it will take this bitmap and program
your 8 characters.
So, there you go.
There’s the famous Commodore logo.
This would be faster, of course, if I programmed this in assembly, but this is about as fast
as I could get it to run under BASIC.
And here’s a little smiley face.
Now if I wanted to start getting fancy, I could re-use some of these characters like
the eyes and actually expand out the drawing area, but that would become very complicated.
Especially if you wanted to program some sort of game, you could re-use these same characters
on the screen as many times as you wanted.
And here’s my attempt to draw a little mountain scene.
Or how about the radiation symbol.
Makes me want to play some Duke Nukem.
And while I did hook this into the Commodore 64’s data bus, in theory you could hook
this up to anything, whether it be a Commodore VIC-20, or an Apple 2, or an Atari machine
of some kind, and of course naturally you can hook them up to more modern machines as
well.
They’re actually quite versatile.
But, I think that concludes the little trio of LCD series, however I might come back and
do an episode on maybe some of the more modern graphical LCD screens and maybe we can play
around with some of them sometime.
But, until then, stick around and thanks for watching!