Placeholder Image

Subtitles section Play video

  • in the previous video, we hooked up this e prom and were able to hook some switches up here to our address lines.

  • And by setting these thes address lines, we can get different data out of the data lines.

  • We could program it by setting the address that we wanted to program and then setting, hooking these jumpers up to put whatever data we wanted into the chip and then pushing this button here to write that data.

  • And I was fine for writing a few bites and programming a few bites into the e problem.

  • But if we want to program more than just a few bites, that's gonna get really old.

  • So this video, I want to look at a much faster way of programming this chip with a lot more data.

  • And to do that, we need to find some way of automatically setting all of these address lines and data lines and the right enable and the output enable the control lines all of these different inputs here to this chip.

  • We need to find some way of automatically setting them to the right values and kind of sequencing through all those values to program the chip.

  • That's what I'm gonna do is look at using an Arduino for that because they are Do we know lets us hook it up, You know, from us be to our computer, and then it gives us a bunch of digital outputs that we can program.

  • I could certainly use this Arduino, you know, no problems there, but I'm gonna use instead the Arduino Nano, which has exactly the same functionality, has all the same outputs.

  • That's just in a more compact form factor here, which is really nice because it will plug right into our bread board.

  • We complete the Nano directly into bread board here, and then it has a USB port that we can use to plug it into the computer.

  • And once we plug it in the computer, it also powers the board, which is very nice.

  • And the other nice thing is that that power is is also available here.

  • There's five volts and ground so we can hook that up to the bread board and we can actually use the USB.

  • The same USB that's that's connected to the Arduino toe also provide power to the rest of our bread board.

  • So we got the Arduino plugged in all.

  • Go ahead and make sure everything's working just by loading up one of the basic examples here.

  • The blink example.

  • And that's basically just flashes the led that's on the board.

  • So I'm gonna make sure under tools, I've got the Arduino Nano selected as my board and I've got the right port selected there and go ahead and compile an upload and it looks like everything's working fine are led.

  • Is is now blinking on the board.

  • So how is this gonna work?

  • Well, if we look at the data sheet for the 28 c 16 the UT problem that we're looking at in the last video you can see we've got our address pins.

  • We've got address zero through tents.

  • There's 11 address pins And then, of course, a data pins, you know, 012345678 data pins.

  • And then we also need our output enable we need to be ableto set that and then we need to pulse are right.

  • Enable pin from Hyde alot.

  • That's a bunch of pins that we need to control.

  • And if we look at the Arduino, you see we've got in terms of the digital pins that we control.

  • There's basically 14 pin.

  • So there's zero and one here, which are also marked a Xrx and T X and then 23456789 10 11 12.

  • And then D 13 is over here to those air the digital pins that we can control from the Arduino.

  • So that's that gives us 14 pins.

  • So how do we use those 14 pins that we've got to control essentially the 11 address pins plus the eight I opens?

  • So that's Ah, 19 pins, plus the right enable and output enable pins.

  • That's 21 pins.

  • So we need to be able to control 21 inputs, essentially to the E problem, using just 14 data signals on the Arduino.

  • So that sounds like a bit of a problem, but But actually, it's worse than that, because this these 1st 2 pins T X and Rx, you can only use those if you're not using the serial interface with the USB.

  • And as you'll see, we really want to use that serial interface because if we would have read what's on the e problem, would be nice to be able to read the data from the prom and then send it to the computer so we can display it on our screen or something.

  • So it's easy to read.

  • And to do that, we need to use the serial interface through this USB, and that takes up these 1st 2 pins.

  • So instead of 14 that leaves us with with only 12 data pins to work with.

  • And so you could say, Well, we definitely need to be able to control the eight data pins because that's ah, you know whats You know where we have to write all ate at the same time when we hit this.

  • This right signal.

  • All eight of these bits are getting written to the chip at the same time.

  • So, you know, we definitely need eight data, the signals, but we've only got 12 here, so if we use eight of them for for a data signal going into the into the chip, then that only leaves us with four additional lines.

  • Unfortunately, there is a solution here.

  • There is a way to use on Lee a couple pins on the Arduino to control a whole bunch of signals, and the way to do that is with something called a shift.

  • Register says the name would imply a shift register is a kind of register and registers store data, and so we can, ah, basically build one using D flip flops.

  • And so this is a 74 less 74 which has two D flip flops on it, and I've got got it hooked up here so that this button here controls the input to the ER to the D flip flop.

  • And then I've got, ah, clock hooked up to it as well, And so, just as a reminder of how this works.

  • If the clock pulses, then it latches whatever is on the input.

  • And so if I'm not pushing this button and the clock pulses, then it stores a zero.

  • If I am pushing the button here and the clock pulses, it stores a one and then if the clock pulses again and I'm not in putting anything here, it stores a zero.

  • But what we do with the shift register is we take the output of that D flip flop, and we hook it into the input of another D flip flop and So what happens now is if I clock the one into this D flip flop that one is now serving is the input for the next D flip flop.

  • You'll notice I've also connected all the clocks of these d flip flops together.

  • And so on the next clock pulse, this one here is the input for the next D flip flop.

  • And do you see on that clock pulse that one comes over here and I can hook that to another D flip flop on the next clock pulse.

  • It moves over there, and I can have that hooked up to another D flip flop.

  • And you know, I can put a one in over here on the 1st 1 and you see that one goes here.

  • But also this one moves to the next.

  • He flip flop, and we can extend this for as many stages as we want.

  • And so from this stage, it can go here and here and here and here.

  • So I've got eight stages essentially hooked up here, but you could have arbitrarily many stages, as many stages as you want hooked up here and every clock, everything just moves down.

  • One stage And so you can put whatever data you want into this thing by just controlling the one input here and the clock so I can put whatever value I want in here.

  • So if I want to put 10101010 into this shift register, I just need to clock in those those bits so and clock in a one and then a 01010 10 And now my outputs collectively show that 10101010 And I was able to get that data into these eight outputs.

  • You've just using us well, really.

  • Two inputs with the one in the single input and then the clock, because a shift register has just a single input.

  • But as many outputs as you want, it's very useful in a case where, you know, like an Arduino where we have a limited number of output pins and we and we need more.

  • And so that's why shift registers actually very common in Arduino projects and one of the most common shift registers its uses the 74 h c 595 and it's an eight bit shift register, Cyril input.

  • And this is kind of the block diagram here.

  • And so it has this eight stage shift register, which is what we what we just built here.

  • And so it has a D s is the data serial input, and then it has the shift clock pulse.

  • And so that's their, you know, basically our data in and our and our clock pulse and then this m r is a master resets that just resets the whole thing.

  • But really, it's just these two inputs that control all eight of those bits.

  • So I've got a 74 h c 595 here, and I've booked a few things up.

  • I've got, you know, power and ground hooked up to it here and then the outputs.

  • There's eight outputs those air hooked up to these ladies and so that that's thes eight blue wires that come over to the ladies and then through the ladies to ground and the 74 h c 595 doesn't have any kind of current limiting on the output.

  • So we need to make sure we have current limiting resistors there, so we don't, uh, push too much current through our ladies.

  • I also got pin 10 here tied to five volts.

  • And that's that Master reset.

  • So just by tying at the five volts, that's not gonna not reset.

  • Ah, and then pin 13 here is an output enable and so tied that to ground.

  • It's an active low.

  • So that just enables our outputs.

  • So then, beyond that, we've got these two inputs.

  • We've got our data input.

  • Here is the green wire, and then we've got our clock.

  • And so this should work very similarly to the shift register that that we already built.

  • In fact, we can hook it up to the same input.

  • So I'm gonna hook the clock to the same clock as as, ah, shit register that that we built before.

  • And I'm gonna hook the input, the data, serial data input into that same button there, and I'll hook up power as well.

  • And so now, whatever we clock in here should also get clocked in here because this chip should behave the same way as this eight stage shift register here.

  • So let me clock a few fits in here and you can see we've got 11011011 And that's the same thing that we've got down here.

  • 11011011 So great.

  • Using just two pins and these could be two pins coming from our art.

  • We know we can control eight or even more.

  • We could we could cascade these like we could have the output.

  • The last output of this go into the input of another one of these seven for 85 95 and get 16 additional are 16 additional outputs here.

  • This is perfect.

  • But there is one other part of the 74 h c 595 that is important to understand and that is that there is this eight bit storage register.

  • And so there's this pin 12 which is the storied register clock pulse.

  • And what that does is it sort of serves as a as a register between the shift register and the output.

  • So what we what we've been seeing is that with each clock pulse, the data shifts in and we see it, you know, we see it shift as the clock pulse has come with The data shifts along like that.

  • But pin 12 what pin 12 lets us.

  • D'oh is if we type in 12 low like that, then we can shift data in here and it will just stay in the chute register.

  • It won't actually go to the output until we tell it to.

  • And that could be very nice, because we can put some data in here.

  • So there's some data and you see that that data is, you know, that it is getting shifted into the 7 45 95 Even though we don't see it on the output, it's in here.

  • All we need to do is then take this pin 12 this storage clock pulse, we take that high.

  • You see, now the data shows up on the output, and that could be very handy, because if you want to change all eight of these pins, you don't necessarily want to shift it around because who knows what that's gonna do to whatever this is hooked to?

  • You want to be able to set whatever you want on all eight of them simultaneously.

  • So let's say we want to turn all of these off.

  • We could just shift in Paul zeroes and then once all zeros air shifted in.

  • Then we just put that and it shuts them all off.

  • If you want to turn them all on, you can shift all ones in.

  • Once all the ones air shifted in, we could turn them all on.

  • And so, really, to use this properly, we want to use all three of these signals.

  • But that still gives us an awful lot because we can use three signals to control eight or 16 or 24 32.

  • However, many, uh, outputs we want control.

  • So the 7 45 95 is definitely gonna help us overcome this problem of not having of pins on the Arduino.

  • Okay, so we determine that we're gonna need two of the 74 h c 595 So let's add two of them to our board here, and it will hook up power and ground to both of these.

  • We could also tie 10 pin 10 which is that Master reset.

  • We could just tie that high because we're not going to be using that.

  • Then we can also type in 13 which is the output enable we can tie that low because we always want the output to be enabled.

  • Now, coming from our do we know, we're gonna have our serial data.

  • Our shift register clock and our storage register clocks of those three pins 14 11 and 12 as a pen 14 is our serial data.

  • And that's gonna be de tu on Arduino d two is going to go to pin 14.

  • Then d three is going to go to pin 11 which is the shift register clock pulse and then d three on the Arduino is going to go over here.

  • Thio pin 12 which is the storage register clock pulse.

  • So with these three signals, we can push data into the shift, register and control the eight outputs, which are these pins over on this side.

  • And I think one over here.

  • Now hook up the second shift register conveniently.

  • They give us a tap here for this this last bit because if we're clocking data in here, that data first gonna go to this bit and then it's going to shift its way along here until it gets to this last bit and want to able to keep shifting it into the next chip.

  • And so what we want to do is connect Pin nine of the first chip back into pin 14 which is the serial data input of the second ship.

  • So we hook pin nine here to pin 14 that provides the input for this next chip, and then the clock should be the same.

  • Actually, both clocks should be the same to the shift register clock from the first ship is hooked to the ship registered clock.

  • The second ship.

  • And that's the same shit register clock that's coming from the Arduino in the same thing for the storage register clock.

  • And so those clocks are all just hooked up the same.

  • So now from the Arduino, we should be able to just with these three pins, push data out into all 16 of these outputs.

  • So before we get too far and start hooking, Ari prom up and everything be good idea to test to make sure this is actually working the way we think it is.

  • So for that, I've got another board here with a bunch of ladies and resistors hooked up that we can hook up to the outputs of our shift registers just to see that they are, in fact, working.

  • I've got 11 led is here, even though they're 16 outputs.

  • But I think that's okay, because we're only gonna be using 11 of these outputs for the address lines because there's only 11 address lines, so I'm just gonna hook these up in order.

  • And so the outputs for these 7 45 9 fives are pins 15 and then one through seven.

  • So hook up to pin 15 and then pin one through seven.

  • So that's 15 137 says the first, uh, the 1st 8 and then these last three, You're going to be on the second ship here.

  • So this will go to pin 15 in the second chip and then pins one and two on the second chip for these last two ladies.

  • Okay, so now if we start shifting data out of these pins 23 and four, we should see that data show upon these ladies first.

  • I'm gonna create a new sketch, and this is what what we start with.

  • And I'm going to define a couple constance here to keep track of what pins were using.

  • So shift data is pinned to shift.

  • Clock is pin three, and shift latch is pin four.

  • And so it's just giving names to these first the dy two d three and the four pins here, just so we we remember what they are.

  • And then in our set up, we want to make sure that all of those pins are set for output.

  • I'll say pin mode, shift data output.

  • And that sets up all those pins so that their output, because we're gonna be out putting to them.

  • We're not reading the what's coming in from them and actually shift the data out on these pins.

  • What we've got to do is we've gotta set each bit on D two and then toggle d three, which is the clock, and so put a bit on D to Tuggle d three.

  • Put the next bit Andi to toggle d three.

  • We're not talking about Pulse D three.

  • So that's what we need to do now, conveniently or do we know provides a function that does this for us?

  • So the shift out function here says it shifts out a byte of data one bit at a time.

  • Start to me the most are least significant bit.

  • Each bit is written in turn to a data pin, after which a clock pin is pulsed, taking high, then low to indicate that the bid is available.

  • It's exactly what we want.

  • So if we look down here, the syntax shift out and we give it the data pin, the clock pin, the bit order, uh, which has either msb first or Ellis beef her.

  • So that's just saying to our we're shifting the most significant bid or the least significant bid.

  • And that's important because we're giving it a value.

  • We're not actually giving it the bits.

  • We're just gonna give it a number, and then it's gonna convert that number to binary.

  • And then it's just a question of what order does it put it in?

  • So let's give this a try.

  • Shift out, and then it's the data pin, the clock pin.

  • So data is shift.

  • Eight o'clock is shift clock and then the bit order.

  • So let's say most significant bit first and then the value so we can set a value of zero x ff.

  • So that's 2 55 or all ones, so that should shift all ones.

  • So let's ah, compile that and upload and I could see its programming and it hasn't done anything.

  • Stop blinking.

  • So definitely took the new program, but it has not put anything.

  • And that's because we forgot to toggle our storage register so we might very well have that data in the chute register, but we haven't pushed it through to the storage register, so we need to toggle this storage clock pulse.

  • Let's go back over here.

  • And we could just do that by doing a digital right for our shift latch, which is pinned four here, and we can take that low.

  • And then what I'll do is just go low than high and then low again.

  • So that'll just pulse it high.

  • So let's compile that and program it.

  • It's now its programming, and there we go.

  • It pushed all one's out.

  • Now, interestingly, you see, when what we wrote here we wrote zero x ff, so that's eight bits of ones.

  • But if we look here, we've got more than eight ones out here, and I think what happened was when we ran it the first time.

  • It actually clocked eight ones into here, but then we didn't toggle the outputs.

  • We didn't see them, and then we were in it again.

  • It pushed.

  • Those eight ones were still here.

  • We didn't.

  • We never took the power off these These Ah, 74 85 95 So those ones just got pushed further onto here.

  • And then we pushed eight more ones into here, and then we actually did the toggle here on.

  • Then all of those.

  • All of those things showed up on the output here.

  • So let's try changing this and running it again.

  • So let's change this to all zeros and I applaud that.

  • You see, it's uploading and boom, we get eight zeros and then these ones were presumably the ones that were over here before it got all shifted along.

  • So it looks like this is working, so we're gonna shift all of these at the same time.

  • Really, What we need to do is do two lines here.

  • And so let's say we wantto do a bunch of alternating ones and zeros.

  • So 55 should do that, cause 55 is going to be 0101 That's five and then 0101 is another five.

  • So it's just gonna be alternating ones.

  • And so we do that twice that should push 16 bits of alternating ones and zeros.

  • So let's hit, upload and programming.

  • And there's our alternating ones and zeros.

  • It looks like this is working pretty well for us.

  • So what I'm gonna do in the code here because we're gonna use this shift register to set the address.

  • I'm gonna write a function here to actually set the address so we'll actually copy all of this code here.

  • Actually, Movil, that's code into this set address.

  • But we want to shift out the value of this address.

  • We don't want to shift out this, uh, you know, alternating ones and zeros.

  • So we can say address here and maybe here.

  • But what?

  • What this is going to do with each of these?

  • Shift out, only shift eight bits at a time.

  • That's that's how it works.

  • So this first thing we need to give it, not not the whole address.

  • We just need to give it the 1st 8 bits.

  • And the way to do that is with this shift right eight operator.

  • So, for example, if our address is, let's say 1234 of course, that could be represented in binary as 10011010010 So this is the binary representation of 1234 Of course, it's more than eight bits, since we could only shift out eight bits at a time.

  • That's what the shift out command does.

  • This operator this address greater than greater than eight.

  • What that does is it takes this value 1234 and it shifts all the bits to the right by eight places.

  • So if we shift the bits to the right one place, then we just get, you know, 100 1101 001 and then this last zero just falls off.

  • So it's just each bid is shifting to the right by one.

  • If we do that eight times, then we end up just getting 100 because we've shifted this one's there.

  • Is there all the way to the right by eight times?

  • And so that address shift right?

  • Eight.

  • When we say that in and see what that does is it takes this address.

  • If it's 1234 and it and it performs this shifting operations, and it leaves us with just the top bits, however many there might be.

  • It basically wax off the lower eight bits.

  • So this first shift out.

  • If we do that address ship right.

  • Eight, that'll shift out the top bits of the address.

  • And in the 2nd 1 if we just say shift out address, it's It's by default is just gonna ignore the top.

  • So this will only shift out these lower hate debts.

  • So in theory, these two commands here should put whatever address we've got.

  • Even if it's up to 16 bits worth of address, it should put it out onto our ship registers.

  • So let's give that a try now that we've got this dysfunction.

  • So we have this function called set address.

  • So if we're down here on our set up, we could say Set address 1234 So let's go ahead and give it a try.

  • Let's upload that.

  • It's uploading and here we go.

  • We got something, and actually, it's It's there.

  • It's backwards.

  • So 1234 is 10011010010 So, 1001101 0010 s Oh, that's that's perfect.

  • So this is this bit here would be address line zero for the prom.

  • 1234 and so forth.

  • And then this is the most significant bit that looks to be working just fine.

  • The only other thing we need to do with our shift registers.

  • Remember, we're not just using it for the address lines.

  • We also need to use it for the output enable line.

  • Because we just don't have enough other pins on the Arduino.

  • You know, we can cover all the io pins.

  • We could do the right enable, but we don't have another pin for output enable, so we need to use the shift register for that too.

  • So for that, we can use any of these open outputs on their 2nd 74 85 95 So I'm just gonna use the last bit here is very top bit, and I'm gonna hook that up here to another led just so we can see what's going on there.

  • So this is our this is gonna be our output enable and s.

  • So I think if we've got our address lines and our output enable, then we can do everything else directly off of the Arduino but for output enable We're gonna shift that out at the same time that we we shift out this this this bite here, it's got to be part of this first bite that we ship shift out because that's what's gonna end up in this 2nd 74 85 95 So to do that, I'm gonna actually change my set address function here to also take a Boolean with what I want the status of output unable to be and the way that I'm gonna set this is take the the top part of the address that were already outputting and do a bit wise or with another expression here, which is gonna be conditional on whether output enable is true or false.

  • So if output enable is true, then I went or it with zero, which is gonna do nothing if you're something with zero, you get with whatever you started with.

  • If it's no if output enable is not true, if it's false, then a man or it with zero x 80 which is if you convert Hex 80 into binary, it's basically just the first bit set So now I can use this set address function.

  • So I sent my address.

  • 1234 I consent my output unable to true.

  • So this I would do this if I wanted to.

  • Let's say we want to read from address.

  • 1234 We set the address 1234 and we set output unable.

  • T true.

  • So we go ahead and run this.

  • It's uploading and nothing happened.

  • But that might actually be right, because when I set out, put unable to true, That means I want to.

  • I want the e pronto output its contents and I'll put its contents.

  • This output enable is an active low, so output enable should be low and it is low eso it might actually be working in orderto test that let's let's try setting this to false.

  • So here we want to put the chip into input the promised input and let me actually gave a different address instead of 1234 to say 1456 or something.

  • So we see that something is happening on.

  • And then, without putting able false, we should see the output and Abel go high.

  • So sending data and yeah, our output changes and we get this output enable goes high.

  • So perfect.

  • That means we're now able to, with just using three pins from our Arduino so far were able to control all of our address lines as well as the output enable.

  • And that means the only thing left that we need to be able to control is the eye opens.

  • So there's eight of those and the right enable and I think everything else we can, either.

  • Just tripping, able to just high low.

  • And yeah, that's pretty much it.

  • Unfortunately, we still have nine pins left, which is exactly how many we need.

  • So now let's start actually hooking the EAP Rama up to this thing.

  • So instead of just looking at ladies, let's try to do something now.

  • I hope the same outputs here to our our address lines.

  • That's the 1st 8 address lines we got.

  • Three more.

  • We're in this side of the chip.

  • Okay, so that's all 11 address lines hooked from our 74 55 95 into the various address pins on the prom.

  • We can also, of course, while we're here, tie the chip enable low and that'll just always be low.

  • We don't ever wanna do anything with that.

  • And then, of course, sorry.

  • Prom also needs ground and power.

  • So you've got all of our address lines hooked up.

  • We've got our chip enable hooked up.

  • That's just tied to ground.

  • We've got ground in power here.

  • How?

  • Put enable.

  • Remember, we could hook that up, too, because that just goes to the eighth output here of our second shift register.

  • Now, with that, the only things left on a chip here are the io pins.

  • So I 00123456 and seven and our right enable.

  • And so, for those, we're just gonna hook those right up to our do we know.

  • So the eye open zero through seven.

  • We're just gonna hook up to ah d five, I guess, is the next data pin.

  • So D 53 d 12.

  • Okay, so that's all the IOA lines.

  • And the only last connection is the right enable, which is right in there.

  • I think that's gonna go over to pen 13 is that should be everything.

  • We should be able to control everything on this, uh, prom.

  • It's the first thing I want to do is write some code that allow us to read what's on the prom.

  • So get this set address out of here, and I'm gonna write another function here.

  • That'll just let me read the, uh whatever is in a particular bite.

  • So first they want to do is like is tell the prom what address were reading from So we can use this set address and then the address that was passed in here and then output enable we want to be true because we want to be able to read what's coming in.

  • So now what I want to do is read each of the data pins.

  • It's each of these.

  • Ah, you know, I 00 through.

  • I owe seven.

  • We want to read those.

  • And so those air on D five through D 12 So I'm gonna make some or contents here, so we'll say he prom d zero is on pin five and ephraim D seven is on pen 12.

  • We can use these constance down here so we'll do a loop.

  • The pain is going to go from actually to go backwards from G seven down to D zero Well, decker mint pin and what I want to do is basically read each pin and shifted into some bite that we're gonna keep track of.

  • So data will be the data that we're reading, and we'll start out with that equal to zero.

  • And then for each of these pins from seven down to zero will say that data equals whatever is currently in data.

  • Shift the left one and then add whatever is on that pin, so digital Read that pin.

  • So this should build up a bite by reading one one pan at a time and whatever we end up with, indeed, a we're gonna return from this really problem function.

  • And so now in our setup, which is which gets run, you know, when we reset the board or when we, you know, when we upload new code to it, let's do a reed he problem of address zero, and it's gonna return a bite.

  • So what do we do with that by?

  • So this is why I didn't want to use, uh, these 1st 2 data pins.

  • Because if we don't use us first to baited pens, then we can use the serial on this board to actually get data out of the U.

  • S.

  • Be so if we say serial, begin and then give it a speed 57 600 I think, is the default.

  • So we'll go with that.

  • Now we can do a serial print line of whatever we read from Address zero, and this will print it to the serial monitor.

  • And so if I go to tools, serial monitor that pulls up this window and anything that we do, the serial print line will show up in this window.

  • So let me go ahead and upload this program, and you could say it's uploading and the board doesn't do anything.

  • But now here we have a zero shows up, so that could mean a bunch of things.

  • It could mean that there's actually a zero an address zero of Ari problem, or it could mean something's not working.

  • It's actually kind of hard to tell, unfortunately, because we don't actually.

  • Well, I don't know what's programmed in this heat problem.

  • S o.

  • I guess what we could do is we could stick it in this thing that we were building the last video and see if we could actually see what's in it.

  • Pry this prom outta here and pop it in this circuit.

  • And then if we power this up, go to address.

  • Zero.

  • Well, there's a zero in there, so maybe maybe we're reading it properly.

  • Let's see what's in address one.

  • Okay, address one.

  • There is a six in there.

  • So let's let's put this he prom back in here and then see if when we read address one, we get a six.

  • Probably shouldn't be doing this while the board is powered up.

  • But I've had some problems Where if I unplug my USB sometimes my I have to reboot my computer for to see the Arduino again.

  • I'm not sure what's going on there, So So now let's come back to our code and read address one, and hopefully we'll see that six in there.

  • So run that look.

  • Our serial monitor.

  • And hey, there's a six, so looks like we're able to read the contents of the prom.

  • So now what I'm gonna do is I'm gonna write some code that actually reads out Ah, larger block of data from the prom and print it all nicely to the serial monitor.

  • So I'm gonna go from 0 to 2 55 by increments of 16.

  • Because what I'm gonna do is I'm gonna print a line for every 16 bites.

  • That way, it's formatted nicely.

  • And so I'm gonna read 16 bites at the time, So I'm gonna create a ray of bites that 16 bites long and then fill that array.

  • So doing, offset of 0 to 15 here, I'm gonna put each bite into that data.

  • You're gonna read each bite from the problem.

  • Really?

  • Prom.

  • Um and I want base plus offset on.

  • What this will do is it will read, You know, they will go through this loop and read all 16 of those bites starting at whatever the basis.

  • So the baseball started zero, but then it'll jump by 16.

  • And so each time through this outer loop will read 16 bites, one bite at a time through this inner loop.

  • Then I'm going to use ah, uh s print F, which is it's a C function to kind of create a formatted string.

  • So me created a buffer for that string.

  • How long that's gonna be?

  • Let's say 80 characters is probably enough, and I'm do esperan f into that buffer.

  • And then here I'm just gonna specify the format string.

  • So I want to start out with the address that were on.

  • And so this percent 03 x just means that that's gonna be filled in by a three digit hex number with leading zeros.

  • We'll do that.

  • And then a bunch of two digit hex numbers for whatever the contents at each of those bites is that's eight.

  • And since we're reading 16 at the time, give 16 put a little extra space in there and make it easier to read.

  • So that will be the format string.

  • And then we just need to specify all the things that fills into this first thing is going to be our base.

  • And then the rest of these are just our data.

  • Okay, so that's all the data bites that we read reading 16 at the time.

  • And then once we have that lovely string, we're going to a serial, that print line of that string.

  • And so what this should do is go through from 0 to 2 55 So the 1st 255 address locations we could go to 2048 if you wanted to read everything out of the chip, but we're not using that much of it.

  • So we're going through the 1st 285 addresses in blocks of 16 and then for each block of 16 will go through and read 16 bites from the chip.

  • And then we'll print out one line with all 16 of those bites.

  • So let's go ahead and upload that and run that and see what shows up on her serum monitor.

  • There's some data.

  • I have no idea what that data is or why it looks like that.

  • But, oh, take it on faith that that is what's actually in the in the chip.

  • Let's pop this out and actually put in the he prom that we used in the last video because that one, I actually know what's in it.

  • So if you put that in there and there's a couple things we could do, we could just hit reset here.

  • And when we reset the card, we know it'll rerun everything in that set up.

  • So let me just do that.

  • So my purse reset.

  • Then you see the serial monitor spits out some stuff, and it's a little bit confusing here because we don't We don't do anything to say we started over again.

  • So you can see we, you know, our starting over it.

  • Zero.

  • So this is when I reset.

  • It is actually starting here.

  • And so you see, the first ah, 16 bites.

  • There's, like, some stuff there.

  • And then the rest of it is all efs.

  • And you remember from last video, the chip started out with all left because that's what it looks like when it's fresh from the factory or it's been erased.

  • And we programmed these 1st 16 bites.

  • So let's take a look at what we programmed in there.

  • You remember this is that true table we put together for the seven segment displays.

  • And so, in address zero, we have a one.

  • And let's look address Zero.

  • Yeah, here we go.

  • Here's the one.

  • Address one.

  • We should have 1001111 So, what is that?

  • This is seven bits.

  • Remember, There's another zero here.

  • So this this one here is gonna be four.

  • And then this would be f So come over here.

  • Yep.

  • Four f ah, and This is one too.

  • Yep.

  • 1 to 060 and then six.

  • Yeah, so we're actually looks like we're reading correctly the contents of his e prom that we programmed by hand.

  • So that's pretty cool the next.

  • We're really the only other thing we have to do is figure out how to write data to the prom.

  • So create a ah right e problem function.

  • And this is gonna need an address on also the data that we want to write to that address.

  • And so, just like when we were doing the reedy problem, we need to set the address so that we're pointed at the right address of do set address address, and then here that output enable will be false because we don't want the prom to be outputting because we're gonna be writing to it where we were inputting data into the problem.

  • And so now we want to take the actual data and put that out on the D for D.

  • What is the D five through d 12 pins?

  • So what I'll do is create a loop that just goes through all of the pins and just sets the appropriate ah bit we're gonna start it.

  • He promptly zero, which remember, is pin five and then go to E prom in d seven and increment the pin each time.

  • So there's a loop through all of our data pins, and I wanna do a digital right to each pin with the physically the next bit of the data.

  • So what I can do is I can take the data, and if I end it with one that's basically going to zero out everything but the but the last bit ending that data with one is just gonna basically pick the lowest bits.

  • If he has some data when a 10101010 if you end that with one remembers all zeroes here.

  • So one and 00 all these end up being zeros, and what you're left with is one.

  • And whatever this bit is, in this case, it zero.

  • So you end up with zero.

  • So in this case, not very interesting.

  • You just end up with zero.

  • But if it were, let's say 01010101 and you end that with one.

  • Then again, you get all zeros for these places.

  • So 00000 But then the last digit here ends up being one and one, which is one.

  • So by ending with one like we're doing here is the data, and one we get the least significant bit.

  • And that's what we're putting out to the pin.

  • So for the first time through the loop, no problems, right?

  • Pin is is D zero and we're ending data with one.

  • So we get whatever is in that in that first bit s.

  • So the next time through the loop, we want to modify, we wanna have data modified so that we get the second bit.

  • So what we can do is we can say data equals data shift left one.

  • And what that will do is it'll take the data.

  • And so if this is what it was the first time through the loop, we we output a zero that time.

  • The next time it'll shift, it actually wanna shift right.

  • May change.

  • That should date a shift right one.

  • And so, if we shift this to the right one, then we get Ah, a leading zero comes in to get 01010101 And then this zero falls off.

  • So anyway, and that with one, we get a one.

  • And then if we shift right again, so we get zero zero comes in, and then this zero get shifted.

  • Right?

  • So 0101010 Think that's the right number of bits and bits.

  • We and that with one, we get zero.

  • And so, you see, what we're doing is we're getting a 010 and that corresponds to the original 010 Each time through the loop, we shift everything to the right and we look at that right most bit, or we out put that right most bit to the pin.

  • And then the pin is getting incremental each time through the loop as well.

  • So this should have the effect of getting our entire bite out put onto our our eight, uh, data pins.

  • Okay, so we've set our address, and we've set our data, So we've got the address getting output here to all of our address bits.

  • We've got our data being output correctly on all of these yellow data pins.

  • So now what do we need to do?

  • We need Thio and we also have our output enable set properly because that's set is part of our set address here.

  • So the only other thing we need to do is pulse that right, Enable pin If you remember in our original we had this button that we push and we had this ah, pulse generator thing that would generate a 600.

  • Whatever, Nana.

  • Second pulse.

  • So we need to do something similar now with our right enable pin here, which is attracted to D 13.

  • So I'm gonna create another constant here for right enable and that's connected to pin d 13 pin 13.

  • And so when we do our right, once we set our address and our output enable and we set our data, we need to pulse that right enable so visual right to write, enable pin and we want to pull sit low because it's an active, low kind of thing and then go back high again.

  • And this is where that timing is important.

  • And unfortunately, the best weaken dio with heard we know is this delay microseconds unless we get into the ATM l assembly.

  • But with just what Arduino gives us, we could do this delay microseconds one.

  • And you know it's not gonna be perfect.

  • We look at our data sheet, remember that, right?

  • Pulse with has a maximum of 1000 Dana seconds, and one microsecond is 1000 and a second.

  • So we're we're right at that Maximum.

  • But of course, this digital right is gonna take a little bit of time, so we'll be a little bit over, but I don't think that's a huge deal.

  • I think if if anything, the only negative effect it would have is around the endurance to sort of the longevity of the of the chip.

  • But it already, you know, is capable of 10,000 or 100,000 right cycles.

  • So I'm not too worried about that.

  • But of course, we do want to make sure that our right enable pin starts out high.

  • So, you know, our set up I'm gonna set that right, enable pin high.

  • Of course, we also want the pin mode to be set right, enable we'll set that output.

  • And actually, this is a good order to do things in, you know?

  • Might seem kind of strange to do the right before we set the pinto actually output.

  • But what?

  • Ah, what a digital right does when the pin is input is it just sets a pullup resistor.

  • So our if you said Heil said a pullup resistor on that pin and then when we set the pin moto output, it'll already be high.

  • So this is the right order to do this in two to be safe, because we don't, You know, we'd like to avoid that right?

  • Enable pain accidentally going low.

  • Because when it goes low, that means the chip is potentially writing data somewhere.

  • And we don't want it to do that this week unless we tell it to.

  • Otherwise, we might lose data that we want to keep in there.

  • So, uh, this is this is probably safest.

  • Wait.

  • Oh, to do that.

  • So this should take care of writing.

  • Ari.

  • Prom?

  • Yeah, we set our address, we set our data, and then we pulse are right.

  • Enable pin We should add another delay in here s so we can wait for five milliseconds is just kind of Ah good thing to do before we go changing our address or changing our data to something else to give the the problem a chance to actually get the data written.

  • And then I guess so.

  • The other thing we need to do is make sure since we're doing a right to our data pins here, we want to make sure our data pins are in our set for output.

  • Because if we're writing to the problem, we wanted a defense to be output.

  • If we're reading from the problem, we want our data pins to be input.

  • So let's do that.

  • So that's going to be a pin mode e prom D zero output actually imported for right?

  • No help?

  • Yeah, output from the output from the Arduino, which is being put into the into the into the problem.

  • But we actually wanted we we don't We want to set all of the output.

  • So let's do a loop here.

  • And then we'll set the pin mode in the loop here, and it'll be so well, that'll set all eight of them to output when we want to write.

  • And then when we want to read, will set him all to input.

  • Okay, let's take a look again.

  • So this is our right function.

  • We're gonna take an address and a byte of data.

  • We're gonna set all of our data pins to output, and we're gonna set our address so that the e promise pointed to the right address.

  • We're gonna set output, enable false when we set that address so that the problem is not outputting, which means we're going to be in putting to it.

  • And then we loop through each of the bits and write each bit of data to that bit.

  • And then we pulse are right, enable low for one microsecond, and then we wait five milliseconds.

  • Thio let it complete the rite cycle so that I think should do it.

  • Okay, so let's try would actually keep if we go into our set up here.

  • So, yeah, there's there's actually some set up here, and then this four loop is dumping the contents.

  • So maybe maybe you'll pull this four loop out into another Functions will create another function here, print contents, and that'll just print that contents of e problem.

  • All the stuff that we did last time, we'll move that up into here, print contents and then in my setup, we have our pin mod stuff.

  • Yes, this is all good set up stuff cereal.

  • So that's all set up.

  • So now we can do if we just want to read from the chip and are set up just to print contents, and that'll do what we did before.

  • If we want to write something, then we can say right he prom and given an address, let's say address zero and give it some data.

  • So let's say we wantto right 42 is a good number and then we do print contents.

  • We should see the contents the same as they were before, except for address location.

  • Zero should have a 42 in it.

  • So let's compile and see.

  • It looks like it actually compiled a little bit surprising.

  • Let's go ahead and and upload it, see what happens, and I'll pull up my cereal monitor here and you can see it's uploading and okay, so it looks like we've got 81 81 81 So somehow it looks like it overwrote.

  • The first wrote something to the 1st 2 bites, but not what I wanted, because I want to write 42 which it's gonna be to a hex is what we should expect to see.

  • There So that's not too, eh?

  • Let's see.

  • Let's let's look at some other things here.

  • So 42 in binary is 101010 That's convenient.

  • And what's 81 Hex?

  • That's what's actually there.

  • We go to binary.

  • That's a very different looking thing.

  • So why is that 81 there?

  • So I'm gonna try writing a zero and see what that does.

  • If anything.

  • Whoa, what is happening?

  • So somehow it's affecting the 1st 2 bites.

  • So I just pulled Thea chip out and stuck it in here, and you can see address.

  • Zero, in fact, has all zeros, which is what we put there.

  • And if I go to address one, I see what we had in there before you exit.

  • It shows the one.

  • So we never did overwrite address one.

  • So something funky is going on.

  • The right is actually working.

  • It seems to be the read is lying to us, so that's very strange.

  • Hey, let's just try writing something else.

  • Let's try writing a I don't know, zero x 55 That's a cool pattern.

  • And then we'll print the contents, upload that see our output.

  • So yeah, again the output for those 1st 2 is wrong.

  • But let's pull it out and let's see what's actually in the chip.

  • So let's pop it into the circuit.

  • And yeah, that is definitely 55 in address zero, then address one still unchanged.

  • So we're actually writing it correctly.

  • We're just reading it wrong, which is very strange, because we were reading it correctly before, So this is just a wild guess.

  • But maybe Maybe maybe we're not waiting long enough when we do this, right?

  • So I did add this delay in here.

  • It's just to make that 10.

  • It really shouldn't need to be that long.

  • What does the data sheets, eh?

  • Yeah, definitely.

  • Doesn't need to be that long since is saying right cycle time and they give you a different time for the 28 c 16 28 c 16 e.

  • And we have I don't see any there.

  • So I

in the previous video, we hooked up this e prom and were able to hook some switches up here to our address lines.

Subtitles and vocabulary

Click the word to look it up Click the word to find further inforamtion about it