So we'll come back to projects Number two we ended the previous one by right now a lot in it and I'm
very sure about we have a deep understanding about initialization and cheeky I O registers by now.
That is very good show.
And this one we're going to complete the rest of the code and we'll stop by writing The Loop remember
what is going to keep the program running on and on is the loop.
So an assembly as we have meant we write a move by given a label and then branch into that label continuously.
Sure.
Let's just call this move a loop.
The first one what cops and for this loop.
When it starts we want to give some delay and then accept input and then output delay input output so
that we have enough time and we let it delay for about let's say three cycles which is which is equivalent
to the SEC divided by five.
We declared up to two what we're going to do in order to create this delay that's going to load or funnel
you into a register and then form a bit of magic with it no actual magic you know what I mean.
So this was declared so we know this here and then grunge to a subroutine that we would create now called
delay and this subroutine is going to use this funding for us this created a whole lot more.
So this subroutine here
this collector and what it's going to do it is going to use this collection.
Remember we spoke about this.
I know I like going to buy things now again can and again I saw our share one.
So as you can tell the fundamentals of our issue currently when you get here just want to go through
this.
I know it might take time to at this point ask you or has this button.
And then branches here and then it branches to delay subroutine.
Well we aim to subroutine Iris here is still a positive value.
So what we want is to continuously subtract this value from Iris here sort of like it counts down.
And what we're going to how we're going to achieve that is by using the subtraction plus updating the
API so register to do this and then we'll tell it.
And the
and then X are basically the entry delay means callback to delay if it's not required to see your X
LR 5 return.
So this is a countdown basically it's lost to value the value an answer and then subtract one from it
comes in it checks whether the value is equal to zero or not if it's not courtesy of the branches but
to delay which is this and then delay continues and then comes and branches onto it reaches zero.
That's a very nice way of writing a calm down.
So then we return to the function after we've delayed then the next and we'll have to do will be to
take our input and then we do the by production to another subroutine.
It's really good to use subroutines easier to manage and then make understanding there is straightforward.
So we recall under that branch here.
So here we would call the subroutine influence an office name.
And what we're going to do here for the subroutine input is we're going to use the data register.
We're going to compare it to a particular value.
That's how we decide whether an input has been triggered or not.
Remember our switch is a logic mode switch meaning when it's in the low state it's activates and when
it's high it's to activate.
So what is actually going to turn on the end is when the switch goes to zero.
And that is why we connect to the pull up resistor to it.
So what are we going to do is compare this.
We're going to compare the state of the switch to a particular states in order to detect whether it's
compressed or not.
So let's continue let's create a new subroutine called in good and then a pointer to the register LDA
point to GPO Gates a registered GP called data on the school are and then OCR Of course we're going
to perform a bit of manipulation using the logical operations we have to load it into our shoe in order
to get to.
Remember this first line is only pointing to it.
The second line is what built it into the register.
For those of you who were here for the introduction you might remember this show.
So now it's an Irish theater.
And what we want is to use the end operation to check whether it's been pressed or not.
So what I'm going to do here is in one hour show our CEO.
Then I'm going to compare it to this filing what I'm going to do would be to compare it to both switches
and see whether there's a difference in the state currently.
When when did microcontroller it's not activated or when the switch is not pressed.
This is the state meaning this.
Let's break it down to the undefined reform.
What do we have here.
We have we have to assume one and then to assume that one show the switch here is false and it's both.
That's the lowest state.
If we tend this to sue the switch switches high.
That's what switch one if we tend to zero.
This will switch to it's high and it's dormant state.
This is what it is.
So we have to compare this we have this file and see you have to compare this file and see whether there
is a difference and you'll see how that works when the call back up to our main subroutine and we're
going to show how that works.
So once we get our share and then we perform this we can return from the subroutine along with this.
So basically unlike other registers just register here keep the yet changes without Curt rhino aside.
Chris as I progress my switch on the code on the physical board I mean the value of this this register
is changing.
So what we want is at any given time check what is the value of this and perform on end operation with
this.
So let's say I press which one if I press each one button becomes the value of this becomes 2 x 3 0
x 0 1 costs which one this one here becomes you.
And if I press a switch to the five.
Sorry if I press switch to
and if I press 1 2 the value becomes x 1 2 and this has nothing to do with this one.
They change based on code but this one here just changes.
That's why we can perform on end with it.
So we check in.
As the user presses the funding here changes and then it is compared to this an an operation is performed
with this and then it's stored back into our shoe and then we're returned from the subroutine.
So whether it is such one dice price for this value we'll switch to Vice President this finally it is
stored in virus you return to we're going to use this button until the end the microcontroller if it
is this fun turn on this ability or if it's this one you turn on this motor.
So basically that's how this on this input detection works too.
Let's go back up.
And as I said this is where we used to value what we're going to do this.
We're going to use the C and I'm going to use the simple instructions into our singer compared with
2 x 0 1
so we compare the value what about value comes we compare it with this file.
Of course we know this is the value that would be there if switch one is price cost which one becomes
zero.
So we'll compare it and we'll tell it if it's less than 10 and the red and as simple as that.
So CNPC the operation for comparing.
So basically it's saying it's our or equal to zero x 1 and then we use Q the Q S If so branch.
Basically if true branch to a particular subroutine assemblies find a key then we have to create another
subroutine that would deal with it.
If so branch to switch on.
So we compare the value of minus you to X or Y.
If it is the same then branch to this and this is where we're going to trigger our lights to turn on
very nice with drip with broken everything down nice pieces.
So let's just ride this one here and basically what this one is going to do is to keep this code very
firm going to break it down further.
Let's move faster.
Let's move red to our two
you know Red.
Yeah we've already declared red.
We'll get her to exit two and this is for the Red LCD.
This is for P F F one to remove move ahead and then or we have to do is we can create another subroutine
to perform the output so that when we have multiple outputs we can manage it.
And then from this subroutine we can branch to the output for it get this branch to output.
And after that the branch bunch loop you might be wondering first articulate article which is basically
is basically the same as the the switch on.
Yeah the switch on subroutine revealed in the previous projects says that over here.
It's not called the constant value of 1 to 10.
We always have to go through to go it would the files to turn on which means we can create another comparison
and then move loop here to send to outputs anyway this war output looks like the output subroutine.
This what looks like output then or we have to do is load again.
Point to this game to register
story data.
Register
and then distort and funny or shear.
Remember we did not put anything in our 0 0 coins are similar to anything course this filing read our
here as punch to the subroutine.
So it's already contains red.
So the source read story to destination which is this and then the X are returned from this subroutine
and does a good job.
So yes this is our code and always remember we have to make sure it is aligned and we have to end this
in the code.
The time
yes.
So like we did previously the fact.
Yeah well we have to do this great to compile this.
You have two errors or more why you have to come here and go to the reset handler and tell the reset
handler.
What crew bump starts and I'm going to go with her.
There we go.
Michelle handler said yes or worse is called Made in order in order not to always come back here.
You can just name your program.
We can always put this underscore on this call made of this place.
This place as well as this place you can just replace this and use to finally reset.
Handler uses if you don't want to always come and change the name of the starting point you could see
probably have one last.
You have two errors
Okay so it says our RC GC GP bio.
Oh yeah.
Did not talk to them.
Correct.
Yes he
seemed to know what the cause that's what we have now.
Got one more error switch on what defined shit on the front.
Okay.
This user should have more modems.
Okay good work.
Don't forget to add these two lines to the main subroutine the L output and and be loop without these
two lines the loop wouldn't work what you would see would be just a red light on without any interaction
with a button.
Okay.
It looks okay and it looks complete.
Let's see.
Fingers crossed a let's load onto our board for control of okay.
We have to set our board.
Remember our frequency 16 megahertz Bulker.
Is this the lives I see.
I click here to find errors I see.
Okay.
Guess crossed moments and then reset to board.
Then we'll see what do you see okay.
The light stays on.
Yeah okay let's solve that problem now.
There are two things that we need to take into consideration first before the comet and the lock registers
have to occur before the other registers in order to allow the data to be committed.
So let's cut this here and put it right on the clock.
Register activation.
Good one thing you might have found on your own is that over here we are comparing these two values.
This PFC and P F for how ever.
When we come here to our initialization you realize though we did not enable s here.
So how can you use something you've not enabled.
We actually use it in our comparison but it's an invalid value therefore it wouldn't work currently.
What this value here means is it's just 0 0 1 0 0 1 2 but we want this.
So we have to enable this this way.
So now this is enabled and we can perform our comparison properly in order to give us the proper resource
and we don't need to change anything because zero here implies it's already on inputs.
So what we're going to do now for these changes we've done yeah we're going to compile and then download
onto our microcontroller.
And this time it's going to work.
I guarantee you but always keep in mind when you use the incorrect commit to register it should come
before the young the activation or initialization of the other registers and this is trickier to should
be aware.
It's easy to forget and just perform a comparison without enabling this this other pin.
So always be aware.
Let's go forward.
So severe errors as download and then we've done all of or restarts and there we go.
Mine works.
I hope yours works.
And congratulations.
See you in the next project.
Yeah.