Hello.
Welcome back.
So in the last lesson we saw how to develop a what.
You drive up.
We created the GPL you as an output and then were able to turn on the LCD.
Now let's see how to make the LCD print blink.
I should say I am going to create a copy of the last project and rename this and then we just continue
from there.
You can open it
right.
It's opened.
So we are going to create a delay function to help us do this.
And I should mention this delay that we want to create is not precise.
Later on when we get to the section on time is we going to see how to create precise delays.
But for now I'm going to create delays I'm going to create our say pseudo delays.
Actually I shouldn't say it's not precise.
This delay is precise but it is calibrated for my my particular configurations and what I mean by this
is it is calibrated for my MCU running at 60 megahertz and using the call you efficient compiler.
So let's see what I mean.
I'm going to create a symbolic name for one second.
I'll call this one sec.
Q You and I'm going to sign this constant so I'm gonna pass this to my register and we're going to keep
minus in one from this taken one from this.
And by the time it reaches zero one second would have passed and then I'm gonna create another symbolic
name.
This is half a second and I'm gonna use this.
I'm gonna use half of this value here which is this.
Right.
So then we can go ahead to create our daily
come down here to create a new subroutine called delay
come here and then I'll see a delay
in this This subroutine shall take the contents of register are three so we are going to part of what
delay amounts.
Our argument is gonna be placed in r 3.
So I'll come here and see sup is
R three are three and then minus one meaning subtract what is an R 3.
So product 1 from the content of our 3 input I resort back into our 3 and then I place the S over here
because I want to update the PSR flags when I perform this operation to subtract operation and the reason
I want to up date the flags is that I want to be able to check what I knew of the flux I set the PSR
flags for those of you who took day the fundamental course the assembly program from ground up we spoke
about those flags we have this zero flag the carry flag the overflow flag so the Zero flag is set when
the previous instruction or the previous operation return the result of zero.
So that flag is gonna be set right.
So I'm gonna say B and E GONNA SEE A B and E delay
and this basically means branch if the Z flag is not equal to zero
meaning if doesn't like you said if the result here if the result here is is zero.
If we keep subtracting from our three if we keep subtracting one from this number and we end at zero
the Z flag is going to be set.
So we check if there is if like you said if it's not set then let's keep subtracting.
If it s not set we keep subtracting.
That is why we seem branch if the C flag is no set meaning we've not arrived at zero yet
and then I'm going to return from the subroutine by doing B X LR like this.
Right.
So I'm going to write a new subroutine known as Lady blink and then I'm going to test all the delay
function to
so we start off by accessing our data register
I'm going to access the data register like we did before
so we have the data register now we've accessed it read We put in our zero and then we turn reality
on this what we do we did this already.
This is our entity on once the LCD on we're going to load one second I'm going to do load R3 with the
constant one second
and once we floated our three we're going to branch two hour delay subroutine
and then we going to turn reality off or just copy this
I'm going to create a symbolic name for 10 in the early days off.
I'm gonna have red off here.
Red is bits number one so red.
So red off I'm gonna do
red off equals shift zero to position one like this I'm gonna take this red off
and put it here.
So we're gonna turn red off and we're gonna delay again.
So start by loading R3 with one second again and then Bill
then we delay.
We go to a delay on subroutine and then this is it.
We can we can keep a branch into the top so that we create a loop here.
Lady blank over here like this so now we can try this out.
I'm gonna copy this label and come over here and because we already have a lady playing us a loop we
can take out this loop.
Okay we can test out our code and see what we have.
I'm going to click here to build
have an arrow here.
It says one sec not defined
okay there's a typo here
okay.
Let's do it again.
It's built successfully.
I'm gonna click it download it.
Mm mm mm mm mm mm mm mm.
I'm gonna download onto my board by clicking here.
It downloaded.
You can see the LCD is blinking at a rate of one second.
Right.
This all the risk for this lesson.
Like I said distillate is not perfectly precise.
This is sort of calibrated as to um you can just take it as a pseudo delay but this is how we are going
to make our lady blink.
Um when we get to the time of section we going to see how to create delays using assisted time is as
well as general papers time is but for now this all the rest.
If you have any questions just let me know and I'll see you later.