A2 Basic 5 Folder Collection
After playing the video, you can click or select the word to look it up in the dictionary.
Report Subtitle Errors
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.
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.
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.
And then cursor blinking is off, and that all sounds fine to me.
So let's let's send this command and so What I'm gonna do is actually just copy what we've got here.
So all of this sent the first command, so I'm gonna copy that and then paste it down here.
So I've got a second copy of that.
Except here, the instruction is gonna be four zeros, followed by a one.
So this is the instruction.
And then the three last bits here set the different things we want display on cursor on.
Blink off.
So I said, that is a zero.
So this is gonna be display on cursor on link off, and we're sending that to Port B.
That's our data lines.
And then same thing here.
We're starting with zero on poor day and then were toddling that enable bit to send the instruction.
And so now that should take care of step.
Three years we've got our display turned on our cursor on, and it's not blinking.
So then step for his entry mode set.
And so here again, we've got registered.
Select zero read, write a zero, and then the instruction is gonna be C 12345 zeros, followed by a one.
That's the instruction.
And then there's two bits here a the end.
There were recon cept Aram Attar's and it says this is setting the mod to increment the address by one and shift the cursor to the right at um, at the time of writing to the display data or character generator.
Ram display is not shift.
So what does all that mean?
So let's look at what this instruction is.
So it's What is it?
Five zeros followed by one is the instruction and there's two parameters.
So we flipped back here to the instructions table.
That's this cursor display shift.
So again we see.
Nope, that's not it, um, entry mode set.
So we see five zeros followed by once.
That's the instruction itself.
And then there's a bit for i d.
And then there is a bit for s.
So what are those?
So it sets the curse, removed direction and specifies display shift, and it's performed during data right and read.
So what does all that mean?
So I d is, well, incremental Decker mint.
So what are we incriminating?
Or Decker Menting.
We'll understand what this is doing.
We gotta look back at the block diagram.
I think it's helpful.
Look at the block diagram here.
Remember, we're talking to this interface through through the eight data lines plus these three control signals.
And so far we've just been sending instructions in here, and those instructions go into the instruction register and there's some decoder, and there's some logic that deals with all that.
But eventually we're gonna be sending data to this thing and actually displaying stuff on the screen.
And so when we send that data that goes into this data register and then ultimately gets transferred into the display data RAM and this display data Rams got 80 bites essentially so it can hold up to 80 characters of stuff that's gonna end up displayed on the screen and see if this got 80 characters of storage space in it.
And there's, you know, potentially up to 80 characters on the screen, depending on what how it's hooked up.
In our case, there's only 32 characters on our screen, but that's just the hardware we've got.
But in any event there's there's potentially 80 bytes of data in here, and we only have one bite where we're sending data to it.
How does it know where to put that bite in memory and therefore how doesn't know where to put that character that were sending on the screen.
What to do that it's got an address, counter and so effectively When we when we reset this thing, you know, the address counters going to say, you know, the next character you send is gonna go in the top left position on the screen.
It's gonna go in that first character.
And so when we send a character, it's gonna put it in RAM in the right place so that it will appear first on the display.
Then, if we send it another character, what we'd like to do is have that character, then go to the next position on the display and that if we send 1/3 character that she go to the third position on the display.
And so each character we send just shows up in the next position on the screen so we could just type out text and in order for that to work, what we want is that every time we write a character, this address counter that keeps track of where that character is gonna go on the screen, we want that address counter to increment each time we write a character, and that's actually what we're setting with his next instruction.
So if I can find the page where we had this instructions, here we go.
Entry mode is is when we enter data into it.
What what motives it in?
What is it doing?
So this incremental document says, Do we want increment that address register each time we send a character?
Or do we want a decker meant it?
And essentially, what that saying is like when we write a character here, Do we want the next character to be written to the right of it?
Or do we want to be writing backwards?
So if we have, this is detriment than each time we wrote a character, it would it would Decker Mint, the address counter, and the next character would then go to the left of the previous character.
So it seems like the normal scenario there would be, you know, we want characters to go, you know, left to right.
So we want that to be incriminating.
And then s is what was that?
That was a company's display shift, which I believe what that means is that you can have the the entire display shift over.
And so even though you're implementing the address where you're putting the next character, the screen, the entire screen can shift the other direction, which might make sense if you get to the end of the display and you wanted to scroll.
But in our case, the example that they have here they're setting an increment and they're setting it to not scroll.
And so that sounds like it makes sense to me.
So again, we want to send another instruction.
So what I'll do is I'll just copy all of this code again to send another instruction.
And in this case, the entry mode is five zeros, followed by a one.
Then we have two parameters.
One is we want to increment the address register each time we write a character so that the next character goes that we send goes next to it.
And then we don't want the display to scroll implementing and shifting the curse of each time.
But we're not shifting the entire display.
Okay, so now all of this sends sends that instruction.
Is that Step four in this example here and so the next step bust at five is actually writing data to the day to display RAM, which looks like it should actually put a character on the screen.
So this case, one thing that's different is the register Select is now one because we're not sending instructions anymore.
We're actually sending data.
So that's that's the other register.
So we want to set, register, select a one, and then we're still writing.
So the reed right signal is still zero, and then the data here, this is actually just the binary representation of letter H.
So let's do this.
So now the data we want to put out there is that is that letter h so we could do the binary representation of H like this.
But instead, what we can actually do is just put the letter h like that.
And that's going to the same thing because the assembler is gonna know the ages representatives, that is that particular binary sequence in asking So we could put that h then and port be, and then, just like before, we need to actually toggle that enable signal.
So I'll copy that code down here.
So we're loading the H and then we're tackling enable.
But But we also need the register select signal to be a one because we're sending data, we're not sending an instruction.
And so here we want register select to be a one before and after we toddle unable.
But also, when we talk all the enable, we also need the register selective you to be a one.
So weaken Dio we can say register select bit wise or with the enable and that'll basically set both of those bits.
So here we have just the register select mint set.
Here we have the register selected and the enabled it set.
And then here we have just the register select bit set.
So this will keep the register, select that said and toggle the naval honor off which will send the data on Port B to the data register.
So it should send this h now to the display.
And that's everything we've got here up to this point where we're putting a character on the screen and says, You know, we could basically continue to do that to continue to write other characters to the screen, but let's just try this out and see if it works so far.
So this point in our code once we've written that h to the screen, um actually don't really want to do anything in loop.
So if I just have a loop and then jump toe loop, this whole essentially just hold the program because it will just throw it into an infinite loop.
So once it's Ah, once it gets to this point where it puts the age on the screen, it'll just sit here, loop forever and not do anything else either good or bad.
So let's save that and then I'll go over and assemble it, and I'm gonna use of ASM and we want to create a binary file and we're using dot directives.
And then the final is Hello, world dot s.
And so there we go that compiles it So, everyone, we could take a look at the contents of that binary file that it created.
And I guess if you wanted, you could check in and see that it did everything right.
Looks like it's, you know, doing a load a f f and then a store.
A 26 years or two and you could pick this all apart if you really wanted to.
One thing that sort of jumps out to me as I see the h there for the actual age that we're gonna display on the screens that that appears in there.
Let's go get this put on the prom.
So pull the prom, Matty.
Here, put that in.
The programmer.
We've got 80 28 C 2 56 is the one we've got.
We're gonna write the aid out out file and there goes.
It's written and there it goes.
And so now we'll stick this back in the circuit and let's power this up.
Reset it And we have a cursor.
And in each Hey, it worked So able to print something to the screen, and it's ah, this code here that it's actually printing that h says this block of code here.
We're putting the h out on the data port, and then we're back to the comments wrong here.
We're setting register select because it's the setting that register select tells it that we're sending data.
We're not sending an instruction, and then we talk all the enable bit on to actually send the instruction.
And then here we are basically just clearing, clearing the enable bit.
So if all of this works to send the character each, the quick and dirty way of sending more characters would be just a copy this code and add four letters.
So if I wanted to print the message Hello world, You know, I might not be the cleanest way or the most efficient way to do it, but I could just copy this block of code for each letter and send each letter just like like we are here.
That's what I'm actually doing here.
And I realized this is not the most efficient way of writing code, but but that's okay because I just want to get this working and then we can talk about how do we actually make this more efficient or make the code easier to read her things like that.
So there we go and definitely not proud of this code.
But let me make sure actually stole this right.
But here's here.
We're printing Hello world, definitely using a lot of code to do it, but it should work.
So let's let's give this a trial.
Save this and then, ah, go ahead and reassemble it and hear.
Actually, if I do a hex dump, you'll see this is this is what I'm talking about by not being particularly efficient.
This is all of the binary code for that program and its huge relative to you know what it's doing.
Just printing Hello world.
You can see the The message is in there, but that's fine at this point.
I just want to get this working, and then we can talk about how to make it more efficient.
So let's re program it.
I'll pull the pram out of here and put it back in the programmer and then go ahead and program it.
There it goes.
Now put the prom back in our circuit here and powered up and hit.
Reset and there goes.
It's printing Hello world, just like we just like we expected.
But you know, I have to say I'm not particularly proud of this code.
It's 100 77 lines of code just to print the Hello World Message, and it compiles 2 333 bites of machine language code just to print the Hello World message.
I think we could do a lot better than that And that's what I'm gonna do in the next video is you rewrite this to be a lot more efficient, but I'm gonna do that in the next video, since we're actually gonna need to add some more hardware in order for us to write more efficient software.
So that's when we get into in the next video.
And remember, if you're interested in following along with these videos, you can get all the parts I'm using over at my website eater dot net slash 65 02 I've got the base computer kit as well as everything else you need to follow along with these videos so you can check that out at eater dot net slash 65 02 And of course, as always, I want to thank all my patrons.
Your support is a huge part of what makes these videos possible, So thank you.
    You must  Log in  to get the function.
Tip: Click on the article or the word in the subtitle to get translation quickly!


Connecting an LCD to our computer — 6502 part 4

5 Folder Collection
林宜悉 published on March 28, 2020
More Recommended Videos
  1. 1. Search word

    Select word on the caption to look it up in the dictionary!

  2. 2. Repeat single sentence

    Repeat the same sentence to enhance listening ability

  3. 3. Shortcut


  4. 4. Close caption

    Close the English caption

  5. 5. Embed

    Embed the video to your blog

  6. 6. Unfold

    Hide right panel

  1. Listening Quiz

    Listening Quiz!

  1. Click to open your notebook

  1. UrbanDictionary 俚語字典整合查詢。一般字典查詢不到你滿意的解譯,不妨使用「俚語字典」,或許會讓你有滿意的答案喔