How a Character LCD Works – Part 3

How a Character LCD Works – Part 3


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 16×2 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!

100 thoughts on “How a Character LCD Works – Part 3”

  1. 7:22 = best piece of info I gathered from this video: these screens act as if they are 40 x 2 no matter the size (when it comes to "wrapping" when you pump characters into them). Explains weird stuff I was seeing with my 16 x 2.

  2. Hi, I like your video very much, I was looking micro-bit connectivity with LCD. i do not find any useful video as you brief in your lesson. Please prepare and upload it as soon as possible. i will appropriate you much

  3. These LCD videos are fine examples of the power of "first principle thinking", which is an invaluable skill/mindset that I fear today's kids are missing out on. One problem with today's technologies is that all the science and engineering are neatly packed into sleek packages that try hard to portrait themselves as "magic"; "warranty void" if you so much as remove a sticker. I applaud the 8-bit-guy for his great works not just for their nostalgia value, but also for the "tinkerer spirit" they inspire, which shouldn't (and hopefully wouldn't) ever become obsolete in today's 64-bit world and beyond.

  4. Potentiometer… Still saying it wrong! The second t is pronounced like a sh. Like in the word 'potential'. 2nd t is like 'sh' 🙂 love your videos!

  5. Iam not Happy after the moment you got the board from your friend. I think you should do a video reverse engeneering what it was needed to work and making a DIY fix.

  6. It’s interesting how those lcd screens work. Was wondering how they got all the characters from so few pins. Everything done is a result of a data stream each time. One more thing. Always wondered how the display matrix worked. Got me looking that up, now.

  7. It's already fascinating that you had the guts to plug an LCD board prototype into your c64, let alone figure out a bitmap display program in BASIC that displays stuff in it!
    I do wonder what is the bus trickery that your electronics expert friend sorted out…

  8. i love how in part 1 and i think 2 u had that shirt that reminded me of rick and morty and this one uhad a funny futurama clip lol

  9. HD44780 or equivalent display driver chip, have a command to move cursor position in desired place.. It should be in that manual.. 😉 40h is base address for character ram, 80h is base address for data ram.. For 2×16 display – first line first character is 80h, last 8Fh, second line first character is C0h, last CFh.. Command C0h sets cursor to start of second line and no need to put blank 28 times to get to the second line.. 🙂 For 4 line displays first line didn't change – 80h.. then line adreses as follows – C0h, 94h, D4h..
    And delay after initialization is very important. Best way is to read back instruction register to check busy flagg before putting some new instruction in.. Some displays working slower and i eat a hair's off to figure out why, sometimes, after start, that display didn't want to initialise but sometimes it start normally.. It was from slow ones.. 😀

    Anyway, great design ideas.. 🙂

  10. Wow! I caught part one, then I wached the other two! In the early days I wasn't into the hard ware so much, but I got deep into the software part, writing programs. So I learned a lot on about how to work with switches to make things work, using pokes and peeks, to change registers. So just watching you do this helped me understand more how the chips work! Wish I would have understood that part better. Always wanted to build something to interface with my c64. I could probelbly build that from watching your videos, but I'm a big chicken, and I think I'd rather have someone else do that part. Lol

  11. Gracias por compartir sus conocimientos. Yo no conozco nada de esto, no me dedico a nada relacionado a esto pero me gusta aprender cosas nuevas. Creo que todo conocimiento es útil.
    Sus vídeos son interesantes. Aún cuando las cosas no resultan bien es interesante que has investigado la causa.
    Me gusta su canal porque los vídeos tienen subtítulos en español.

  12. hmm… it was something I could almost follow until you had someone else add more chips and a custom PCB. it's ok, I was just watching for infotainment.

  13. now I'm scared of rebuild that project because if you had to consider an expert and for me you are an expert. what I can do then?XD

  14. Hey David, I know this video is old but I can't find a way to contact you.. Is there any chances you can upload your program to design characters on LCD screen?

  15. Such an honorable man. Fries his C64 attempting something similar to this (THROUGH NO FAULT OF HIS OWN) and goes on dauntlessly, risking frying his immaculate 64c all for our viewing pleasure. You really are a hero of youtube.

  16. Great series but I'm confused what the "good reason why" (timing issues aside) to demonstrate attaching the character LCD to the cartridge port teased at the end of Part 2 is. Is it because you can operate the display in a full 8-bit mode using the 8 data lines on the 6502? I want to do a project similar to this with a Z80/Intel 8255.

  17. Just AWESOME! You are a guy of my type who doesn't bother to waste time to get into the very deep to fine the real treasure of electronics! However, the difference between u and me is, I'm a fresh graduate newbie and u are a geek! Kudos !

  18. I like your videos a lot and watched this trio 🙂

    however your titles are terrible… "How a Character LCD Works"??? You never once said anything about how it works, what the electrons do, nothing about the physics, what the properties of the liquid are, how the liquid is a crystal, and how it polarises light (indeed, how polarized light behaves). I feel sorry for people that search for "How a Character LCD Works" and listen for 40 minutes or more and after all that time get 0.0001% of the answer they are looking for (and yes I am being generous here:).

  19. You are not done! You have to create a serial interface board! Then we can use these things anywhere! Especially if it's USB in some form or fashion. Interfacing the ancient with the current/modern is a really cool thing.

  20. I've now watched all three parts of a three part series on how character lcd screens work. What am I doing with my life?! (Kidding. They've been interesting)

  21. Видео из разряда "Я смог", ничему не учит, вот где учат https://www.youtube.com/watch?v=UVlz2M5oMhc&list=PLJTlt64jBcCtQ99qqW-n-hraDkSJVMBCR&index=13

  22. It's amazing how incredibly advanced our computers have become, and most of us haven't the faintest idea how it works or why. The OG stuff is so fascinating, gives you a great appreciation of where it all came from.

  23. Just like what happened to David, if you have one of the original C64 power supplies, DO NOT USE THEM. They have basically no protection and not well designed in the first place which means the voltage will slowly creep up and fry the machine that is slowly getting more and more rare. A new modern replacement is like 40 bucks and much better if you don't feel like creating your own but the original power supplies are ticking time bombs and the only way I'd use them is by checking the voltage every single time it's about to be used but that is still not a good way

  24. Would it be possible if your friend could share the pcb layout files for the board he made? Think it makes a very nice hobby project.

  25. If the LCD can work with commodore via the data bus pins, can we communicate Arduino with commodore with those pins?

  26. I believe the world needs more of these types of videos. I always rewatch this LCD series when I see it recommended

  27. hi i have an embroidery machine and i can't see any thing on it the letters are so faded out . Now the machine develop an error and i can.t see could you give some help about the dullness o the letters?

  28. Ideally when cutting chips like that, you cut it close to the chip, after the bend. The way you cut it can damage the board from the mechanical stress when the soldered in pin is pushed when clipping. When you clip it at the chip it induces a lot less stress to the board.

  29. Really interesting episode! Please continue. I like a fuller explanation of the software used! Thank you ■□●○●□■..

  30. I miss RadioShack.. gotta wait for any parts and pieces by mail. I'm definitely not patient when im wanting to fix something.

  31. I'm terribly sorry I'm digging through the comments and I can't find a true answer to this question. Was there ever a schematic released and/or a proper write-up? ( This is a great little project you have here good job)

  32. dude ur a fucking genius. wrote your own software to draw the designs for lcd screen. damn. thats dope. you could make your own retro handheld if u wanted to.

  33. What about connecting a larger LCD screen (e.g. 240×128, 40×16 characters) to the PE6502? Then you'd have something useful and readable – and with a battery pack, portable. The 40 character display could (would?) avoid the "wrap or edit" problem.

  34. Wouldn't it be better to programmatically pad your text so that it wraps automatically? For example, for a string that is n characters long you could send (40 – n) blank spaces to the screen.

  35. Nice job! i'm wondering if it's possible to use a character lcd display instead of a PC monitor only for command line typing.

Leave a Reply

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