Hello.
Welcome back.
So this is this state of Iowa GPL u in its function or subroutine.
We initialize clock access.
And over here we set GPL u p f one as output.
And then we digitally enabled P.F. 1.
Now we're going to unlock our PFC row and then we can add green as another output and then add the switches.
So I'm gonna come over here right after initializing clock.
I'm going to unlock it.
Oh she went on lock PFC through by saying Lord
are 1 with the GPA f
0 she could register and then load r 0
we did lock key which we could lock a key simply lucky
and then start a.
So I'd say store our 0
R1
right.
So this would unlock this will not PFC or for us.
So now once we've done that we've got to commit.
I'm gonna come over here and say
Lord oh Lord a comet's register Lord I want a course GPA U F C R R and then I'm simply going to move
or simply use
user x f f over here and then store out as you are one
right.
So we've unlocked and we've committed.
Next we have our direction register here over here we just set in P F one as output.
So what I'm gonna do is I'm going to add the green LCD and to add that in C language I'll simply add
this and do Ellie de Green and this also will be set over here to add it's in assembly.
I'll have to use the O operation
um
so I'm gonna start off first.
I can't read with the current value of our zero.
Once I start I'm going to perform another or iris zero then a green.
This would add green to it.
Right.
As simple as that.
So does the direction register.
Remember to set a pin to to output in the direction register you've got to set the bit to 1.
That's why we're doing this to set to input you've got to set it to 0 but because the default state
is 0.
I'm not going to set anything for the switches caused by default I already input.
That is why I'm only doing it for the M for the output.
The red and green lady now on digital enable from digital enable to digitally enable a pin you've got
a set it built into digital enabled register to 1.
So we've got a set one for the LCD screen one for elderly red one for switch one one for switch to.
So this was going to be a little red like this in C language a Lady Green
switch one switch to this is going to be like this right.
So I can either use a plus sign a lady red plus a lady green plus which one plus switch to or I can
simply use the operator the.
Yeah perform an operation so I'm simply going to do this and then this becomes
Lady Green.
This becomes a sloppy one.
This becomes
messed up too right.
So once that is done we need to set the um the pool up.
We need to go to the pool up register and sets the pool up for our switches.
I'm gonna come over here.
Okay.
I forgot the C language.
I've not done that for a while.
Also GPL you f pull up register and I'm going to enable it for switch one and switch to like this.
So an assembly load R1 because GPA F P you are on the score R and then load r 0 are 1 and then we do
an all operation or r 0
with switch one and then all our 0 we switch to and then we can store no SDR r 0 R1 and then we return
would be X a la like this okay.
Right.
So we're looking good now.
Now we can um we have to write a subroutine to two to root D pin to read the buttons I should say I'm
going to delete a while
I'm gonna delete or delay and blink subroutines here we don't need them I'm gonna write a new subroutine
for GPL you read
and I'm going to load the data register load
GPL you f on this court data on the score register then
load C row are 1 here and then I'm going to check I'm gonna check if this switches suppressed and I
will do that by course the content of the data register is going to be an R1 so I'm gonna use the end
operation I'll end r 0 the content of Iris Zero which I you a check without data on pressed or not
when I use three or approaches.
Just think of the third one as the destination when I do this.
It's the same as doing this right.
Do not be confused okay.
So I'm going to say check PFC row and pay for what I do pressed or not.
Right.
And the result is going to be put the output of this and operation is going to be an Irish euro.
So I'm gonna do B X LR to return from the subroutine
right.
Okay.
So um let's see what we have.
This is our main.
We start off by GPL U in it.
We don't we no longer have blink.
But what we have is GPL you read so I'm gonna come over here once we've initialize our GPL you will
read it by doing branch to GPI you read
on this will read both.
Um this will read on what you call it.
Both of the the switches and the results is going to be in Irish euro.
So now let's compare what is in Irish euro.
So I'm going to use this GMP instruction.
Compare the content of Irish euro which switch pressed
and then we'll say if so if it is switch one pressed then we say BQ here.
If a switch one press then we're going to create another subroutine for what we want to execute.
In the case of switch one pressed.
So I'm gonna come down here and outputs which one pressed here.
Switch one.
Yeah.
And what we want to do is turn on the red LCD.
So sorry go there.
So I'm simply going to move the red LCD
simply going to say move
I wish you pushed uh put this into our sewer a little red and I'm going to branch into another subroutine
that would I would turn on the LCD which we shall call a lady on a lot of branch and going on here and
then
um we can return to the um to loop once we've done this once we've executed and turn on the LCD we want
to return to the top of the main loop while one loop so see a b loop over here and I'm gonna put loop
here this label here right.
So we we have to implement a lady on we have LCD on over here this reads the um
this reads our data register and then okay.
We've got a delete this and yeah this is our lady on and I changed a spelling I made it into a lady
on like this.
So if so which one is price we're going to put a lady red into our zero.
Right.
So then our jury is gonna come to early on and then we take what is in our sewer and put into a data
register and in effect the red readily do turn on right.
This what we get if switch one is pressed.
Okay now let's do the same for switch to when I say RCMP
are 0 switch to pressed BQ on this call switch to.
So we're going to right switch to here
this should be switch one this is switch to
and we start off by moving the green LCD move our zero LCD green and then Bill and a score early on
and then we print Park to the top of the loop to start again
right.
So now let's check.
Um we've checked the switch one switch to and then um I think I can leave it here.
I'll leave it for your assignment.
I'll leave on exercise for you to implement both pressed and no price.
What should happen if both of them are pressed or if none of them is pressed.
That will be your exercise for this lesson.
So let's see what we have.
Okay.
After switch to I'm gonna branch back to loop so I'm gonna be here
okay.
Let's pull it and see what we have.
Okay.
Click it to build.
I've caught one error it says switch one not defined
here I put two underscores here.
Let's build to peel successfully installed onto the board
it's finished downloading.
As you can see when I press this the green LCD is on when I press this the red LCD on green red green
red green red light.
So like I said for your exercise I would like you to implement what happens when both buttons are pressed
and when none of them is pressed.
None of them is pressed.
I would like for you to turn off the LCD.
Now you can see that the last LCD the last one that I pressed is still on on the board.
So if nothing is being pressed I'd like for you to implement a subroutine though.
Turn it off.
And if both are pressed I'd like for you to implement you know to turn on the blue LCD or turn on both
LCD when they're both pressed at the same time.
And if you face the questions with regards to the exercise just let me know and I'll see you in the
next lesson.
Have a nice day.