Placeholder Image

Subtitles section Play video

  • these little LCD modules are extremely common.

  • But what to take to hook one of these up and get it working?

  • Let's get these 16 pins that are used to interface with it.

  • So if we just feed the right signals in, we ought to be able to get it to do something.

  • And I got this little computer that I've been building that so far I've just programmed toe blink some lights.

  • But now, instead of using these signals, just attorneys led us on and off like this.

  • Let's use them to feed in whatever needs to be fed into this display to make it do stuff.

  • So I took that up.

  • Let me get these ladies out of the way and I'll get the resisters out of here and I'll install one of these LCD modules and and these come in different colors.

  • That blue is pretty common.

  • I'm gonna use the yellow one risks.

  • I think it shows a little bit better in the video, but I'll start by hooking out power to the display.

  • These 1st 2 pins air for five full power and V s s is ground and then V tedious five volts.

  • It says the power for the module into the next pain here is V zero, and that's for adjusting the contrast of the display.

  • And really, all we need to do with it is tie it to ground through a resistor.

  • To set the contrast, we'll use a 10 K variable resistors.

  • We can adjust the resistance to adjust the display contrast and already got the ground line here.

  • So we'll hook 11 leg of this up to that ground and then the middle pin will hook over to the V zero input.

  • And now we should be able to just turn this and adjust the display contrast and the rest of the pins Here are just the signals that will have to hook up to the computers.

  • I own lines here in order to communicate with the display.

  • Except for the last two pins a N.

  • K.

  • Here there's actually for the backlight for the display.

  • So the display lights up and a is the anode for the backlight led.

  • So hook that to five volts and Kay is the cathodes will hook that to ground, and we can hook this directly to five votes like this because the models already got a current limiting resister in it.

  • So we don't worry about blowing up.

  • That led by putting too much current through it.

  • We hooked directly to five volts, and we still haven't hooked up any the signals.

  • So it's not gonna really doing do much yet.

  • But let's up hard on anyway, just to sort of make sure and the backlight work.

  • So that's good.

  • And nothing's on fire.

  • So that's also good.

  • And, you know, we could check the contrast setting, too, so because that ought to work.

  • And so there we go.

  • So this is this is obviously maybe too dark.

  • And if we go the other way, that maybe to light.

  • So if I kind of said it somewhere in the middle there, that's probably about right there in the middle.

  • So hopefully, if anything were on the display, we'd be able to see it.

  • But of course, you know we're not sending anything to the display yet, so you know it's probably good.

  • We don't see anything there.

  • Let's look up the data lines so we can actually send data to the display.

  • You can see they're actually ate data lines here, so D zero through d seven.

  • It's all just hook up all eight of them to the 65 22 interface adapter here.

  • And I'm hooking these up to the same eight bits that I originally had.

  • Those led is hooked up to because we know we can set those pins to whatever one.

  • And you know, actually, I technically don't need to hook up all eight of these.

  • The display actually has a mode where you can do everything with just four data bits, which is a nice feature because it means, you know, we wouldn't have to hook up many wires or we wouldn't need to use as many pins on the 65 22.

  • But the A pit mode that I'm hooking up here is a bit simpler to use, so we'll start there.

  • But, you know, maybe if you're doing a project like this yourself and you know you could get all the parts over eater dot net slash 65 02 But you know, whether you get the parts for me, you're somewhere else.

  • If you doing a project like this, you might want to try figuring out for yourself how to do it with just four bits.

  • But the a bit mode is a good place to start because that is gonna be easier for us to use in.

  • Either way, there are also a few control signals that we need to hook up.

  • So this rs r w and e pins are additional control signals that we need along with the eight data lines.

  • Unfortunately, the 65 22 interface that were adapter that we're using has to eight bit i o ports that we can use.

  • So we could just hook up these three control signals to three more Io port pins over here, and we'll be able to control all the things.

  • So hook up this e pin, the art of you pin and the RS pin into those all the pens we need to look.

  • But what of these pins?

  • Even four.

  • Well, we need to dive into the data sheet to figure out how this all works, and this is actually the data sheet for the interface chip on the module.

  • So it's underneath this blob here.

  • It's not the data sheet for the entire module, which, which actually means we don't really care.

  • About half of what's in here because on one side you were talking to the chip through this.

  • You know, the eight Data Signal's lost these control signals rs RWE that we just hooked up.

  • But the other side of the chip actually talked to the actual LCD screen, and so it's got a whole bunch of pins.

  • And so, you know, the chip itself has tons of pens that we don't really need to worry about, because most of them are these, like common and segment pins, they go off to the actual display and control, which pixels on the display or set.

  • And actually, the display they were using 40 by 16 isn't even enough.

  • So there's there's actually a little expansion ship here is well, and so there's extra pins that interface to that expansion ship.

  • But we don't have to worry about any of that because someone else has built this module and taking care of figuring that out.

  • So we can just ignore roughly half of what's in this data sheet.

  • Um and really just focus on this interface here.

  • There were connecting to.

  • So we look at this MP, you interface.

  • An MP was microprocessor unit which, you know, we're building a microprocessor computer.

  • Then we see the eight data lines that we've hooked up a CZ Well, as the r S, r W and e signals that we also just hooked up.

  • And the way this works is we've got these eight data lines going in, and there's a data lines either access the data register, which stores eight bits of data or the data lines can access the instruction register, which also stores eight bits of data and the way we select whether we wantto send data to the instruction register or the date of register is with the register select signal.

  • That's that's what this RS is register select.

  • So if register select zero than any data we send in here is gonna go to the instruction register, And that might be where we send commands to initialize the display or clear the display or move the cursor around things like that.

  • But then, if register select is high than the data that we send goes into the data register and I would typically be how we send whatever characters we want actually appear on the screen, because then that goes into the data display RAM, which stores all of the characters that are currently on the screen.

  • There's also a read right signal, as we can actually read information from the display model to wear it just writing to it.

  • For example, we could read what's in the data registers to get data out of the display Ram or, you know, we could read with Register Select Low.

  • And actually, we wouldn't read the instruction register.

  • When Register Select is low, we actually end up reading the address counter a CZ well is the busy flag, so those come out as well, so there's data we can read and write, so we have a read right flag there.

  • And then finally, the the E pin is the enable signal.

  • So for any of the reading or writing we might do here they've been talking about the actual read or write doesn't happen until the enable signal is is toggled high.

  • So that's gonna be important.

  • So let's look at the assembly code we're using to control these signals.

  • Is the program ahead running and puts a pattern of 50 hex out on the eight bits that we had there and then he uses this rotate right instruction to shift the bit pattern over each time through this.

  • This loop here.

  • But first it initialize is the i o interface chip.

  • That's what these 1st 2 lines here are.

  • Just address 6002 is the data direction register that says whether these eight bits here on the right, that we're using our whether we're using this for input or output.

  • And so, by storing FF in that register, we're saying that the signals are all hell puts.

  • Actually, we could make this a little bit clearer by defining symbols for these different addresses.

  • So instead of just saying six years or two, we could define some symbols up here.

  • Support Bea.

  • Is that address 6000 and port A, is it address?

  • Six year 01 And Port A is the eight bits on the left here.

  • So we're just gonna be using the top three of those bits, and then port B is the eight bits here on the right that we've got hooked up, but then in the code, Once we define those addresses here, instead of saying, store a six years or zero weaken, say store, eh?

  • Port B, This is the same as it was before, but hopefully maybe a little bit easier to make sense of.

  • And then the data direction registered report be is it six years or two and the data direction registered Report A is at six years or three.

  • Now, I could change this to store a DDR be, you know, to make it a little bit more clear that this f f is setting the direction of the data for Port B.

  • And then if I want, you know, maybe it's not clear what this FF even means, because what we're doing is we're loading FF into the register and then we're storing that to address six years or two, which is the data direction for Port B.

  • But the reason we're using FF is because FF in binary is just eight ones.

  • So if we want, we can actually write out the binary to make it even clearer instead of a dollar sign.

  • If I use a percent, that means the number is binary.

  • So I just have eight ones, and then that's gonna be the same number as FF in Hexi Decimal.

  • And then here, maybe it's more clear that each of these ones indicates that that particular bit should be an output.

  • And of course, it never hurts to add a comment explaining what we're actually doing and then for port a week actually do the same thing.

  • But here we just set the top three bits as ones in order to configure just those 1st 3 bits as outputs.

  • And then if we store this to the data direction, register for port.

  • Aye, that'll set just those three bits on port areas outputs.

  • So here we're setting just the top three pins on poor day to output.

  • So that sets just these 1st 3 pins here that we're using as outputs.

  • And there's still another five pins here that are part of Port A That we're not using.

  • We could configure them is either input or output, and because I left those bits zeros in the data direction register, I'm leaving them as inputs, not outputs.

  • But you know, we're not using them right now, so it doesn't really matter that we're leaving misters imports.

  • But anyway, now that we've got all these pins hooked up and we've got him all configured as outputs we can start sending instructions and data to the display.

  • And if we look back at the data sheet, we can see all of the different instructions we've got.

  • So like clear display return home entry mode said and so on.

  • And of course, all these instructions have the register select signals set to zero.

  • Because then, you know, that's how we tell it that we're sending it an instruction you have registered, select for one.

  • Then we'd be actually sending data to the display, but register select zeros for instructions.

  • And then, of course, the read signal here is also zero for all these instructions because we're writing to the display when we send it instructions.

  • And then the instruction itself is kind of encoded here, based on where the 1st 1 is in the data.

  • Is all of these instructions start with some number of zeros, followed by one.

  • And so if it's if it's seven zeros followed by one well, that's the clear display instruction, you know, if it's, ah, you know, four zeros followed by a one, then that's the display on off control instruction and you can see like the earlier that the one appears in the instruction, the more room there is after it for parameters that go along with that instruction, yes, so the clear display instruction, for example, that's all.

  • One that's you.

  • That's all zeros with the one at the very last position.

  • So there's no room for extra parameters, which is fine because for a clear display, there really isn't any parameter.

  • You just do a clear display, and it clears the display.

  • It's not that complicated, but for like the display on off control, there's four zeros, followed by one.

  • And then there's room for three parameters.

  • So there's a bit here that could be a zero or one, depending on whether you want the display on or off.

  • Then there's a bit for whether you want the cursor display on or off.

  • And then there's another bit for whether you want the cursor to be blinking and see exactly.

  • Set.

  • All three of those is part of the display on off instruction.

  • But what instructions we actually to send to get the display?

  • The work Well, if you flip a little bit further back in the instructions here, we're in the data.

  • She hear it say they give some examples, and so it probably easiest just to find an example that seems kind of close to what we're trying to do and then try to figure it out from there.

  • And since this example here is for a bit operation, which is which is what we're doing and then it's an eight digit by two line display.

  • And of course, we've got a 16 digit by two line display.

  • But I don't think it's actually gonna make that much of a difference.

  • And this is sort of the closest example that's in here.

  • But either way, you know, walk through the example and actually try to understand what everything's doing in here rather than just kind of blindly following the example of hoping for the best.

  • So, you know, let's start here with with Step one step one is just powering it on, and then it's initialized.

  • No display.

  • Well, we've gotten that far, So Step one is a success, and then step to hear is function set.

  • So it says it's setting it to eight bit operation, and it's selecting a two line display with a five by eight dot character fund.

  • And so, for this instruction we've got register, select a zero and we're writing.

  • So those those two zeros means, you know, this is an instruction.

  • And then the last eight bids here are the are the actual data that we're going to send to to send the instruction.

  • And so the 001 That's sort of the first part up to that 1st 1 that actually tells us what instruction it is.

  • 001 is is the instruction.

  • And then we've got the parameters here of 110 and then the last two bits.

  • It says it doesn't care.

  • So we put back.

  • We actually find that instruction in that table were looking at before.

  • So it's an instruction here with 001 is the instruction.

  • So that's that's what we're just looking at.

  • And then it says we've got these three parameters that we can set.

  • So D.

  • L is the data length and is the number of display lines.

  • And then f is the character fund so we could see over here on the next page D l.

  • If we set it toe one, that means we're using an eight bit mode.

  • And if deal is zero, raising forbid mode, so we're using a bit modes.

  • We want to set that toe one and is the number of lines on the display.

  • So if we set that to a one, we've got two lines of who set that to a zero.

  • It's one line, and then the phone is either five by 10 dots per character or five by eight dots.

  • So that's just how many pixels make up each character.

  • And, you know, we really don't have a choice here either with a number of lines or the number of dots, because the physical display were using has five by eight dots for each character.

  • So it would look wrong if we tried to use this five by 10.

  • So we go back to the example.

  • 001 is the instruction.

  • And then we're setting eat bit mood, a two line display, which is what we've got and a five by eight character fund, which, which is also what we've got that all sounds like what we want.

  • So let's send this instruction to the display.

  • So again, the instruction itself 001 and then we're gonna have a one because we want eight bit mode and then a one for the two line display and then a zero for the font want the five by eight font and then the last two bits aren't used.

  • I'll just set those two zeros because this doesn't matter.

  • And so this is the instruction to set a bit mode to line display and a five by eight phone.

  • So I'll help with that in there, and then we can put this out on port be and so that sets thes these eight data bits out on port be here.

  • But we also need to set the register Select bid a zero and the reed right signal as as zero and those air over here on Port A.

  • We need to make sure we set those as well.

  • So we just loaded and store a zero to port A that'll clear the register, select the read, write and enable bits and then to toggle some of these bits.

  • What I can do is going to find some more symbols here for each of the control signals.

  • So they enable signal is the top it on port, eh?

  • And then the reed right signal is the next bit and then register Select is the third bit like this.

  • So if we go back down here and take a look at what we've got so far we're putting our instruction on port be here and then we're clearing all of the control signals.

  • And so, in order to actually send the instruction, we need to toggle the enable bit.

  • So what I could do is load just the enable bit into the A register and then store that into port A.

  • So that'll turn the enable signal on.

  • And then if we immediately set it back 20 that'll turn it off again.

  • So this effectively, we'll just toggle that enable signal on and off really quickly, which will have the effect of telling the display to then accept this instruction that is, that is sitting on the data pins so effectively, all of this ends up sending this instruction to set the admit mode to line display five by eight Fault.

  • And of course, this here is where we're setting the enable bit to actually send the instruction.

  • So all of that is just for this Step two here in the initialization example we've got so that sets the function.

  • We've got our display set in this in this mode.

  • So then the next thing in the example here is the display on or off control.

  • So again, this is sending an instruction.

  • In this case said 00001 So four zeros in a one is the instruction.

  • And then there's three parameter bits here.

  • So if we go flip back and look at the instructions we've got from what is it?

  • Four zeros in the one that's gonna be display on off control.

  • So four zeros in a one is the instruction code there, Um and then the parameters we have or do we want to display on or off?

  • Do we want the cursor on her off?

  • And we want the cursor to be blinking or not.

  • And if we go back and look at the example in their case, what they're saying is they want see the display to be on makes sense, um, the cursor to be on which, you know, except us, whether we want to see that or not.