So let's declare let's avoid function call and delay my call.
And it takes one argument which is a tight end.
And in this function what we're going to do is we're going to use a nested full loop to create a forced
DeLay and nested for loop.
This feels like this end with two local variables and I and J.
And what we're going to do is four by four equals zero and I by less than and remember and is the name
of the document that the function accepts plus plus and then inside I inside I would call that a for
loop inside this first for loop we have k equals zero J less than three
J plus plus and then this does nothing.
This is just to waste time basically.
So do not worry about where the stumble came from.
There is a calculation for it based on the frequency of our microcontroller which is 16 megahertz.
I wouldn't go into the details of how we derive this number of course.
This is not the right way of performing delays.
We would use the right when later.
So do not worry about this number.
So we'll need to delay functions as we said while we are here.
How will we create the other delay function.
This one is going to give us delay in millisecond units.
So I'm going to declare us forward delay merely and it also takes one procurement and the same way we
use and nested for loop.
And then J.
And without for I call 0 then I less than an then R plus plus
Brandis and call on her plus plus.
And then we have that in the loop which is J.
Because 0 overhead J is done.
You want a zero.
Do not worry about this number as well.
J.
Plus plus.
And it does nothing.
So this is what these are not delay functions.
They are forced to place.
Yes sir.
Let's go back here now we have a delay.
So in order to enable it we delay here.
The reason why we have this is because we have not added to function prototype of the Hubble we add
a prototype.
I really do not like this.
Red lines say to stop it.
All you have to do is under function prototype like this with a semicolon.
And we can do the same for this one to stop the red lines.
V What s in the column.
You see the line disappeared a K is one more function.
F with this so that you don't get a red line when we use it.
So with paste that semicolon disappeared.
Okay so now we have now own this all of all functions.
That's just one more function left or right.
When we need it.
So we have delay micro zero here.
This values you.
You should leave that dependent on your microcontroller.
You might need to tweak this value to 1 0 0.
If the code is not running appropriately but Karen the mess leaves 0 4.
If you check the key to shoot for far LCD or the data datasheet of your LCD which I presume the market
has the same type of LCD drivers you'd realize that the commands have different amount of delays as
specifically commands 0 1 2 and 3 have different delay amounts compared to the rest of the command.
So what we're going to do is create a condition here to give two delays based on the command that we
are given to the LCD.
We're just going to use an if statement here.
I'm going to say that command is less than 4 which means if it's commanded one two three DeLay give
us a delay of two milliseconds delay merely to
dispel this well ls one hell to delay my crew.
This is based on the data sheets which I do not want to bore you with.
You can open it and check out our data sheets to the additional files with this particular video.
Some data sheets come weights 14 and two milliseconds so based on your microcontroller you might need
to know not based on your microcontroller based on your LCD and you might need to tweak this for two
to delay for to 40 microseconds but it should be well.
So basically this is our LCD do command function.
So now that we have the function we can come back here to use the LCD the command function to initialize
our LCD show.
What we want to do the first thing we want to do as we spoke about is to tell the microcontroller or
to tell the internal registers of the LCD.
What type of LCD we are using and the mode we want to operate it in.
And this entire nation is and capitulated into called 0 x 3 8 and basically what this means is that
we want to operate in a debate.
Remember we can send information in full bits as well as 8 bids.
So we tell in it we want to operate in it and now our particular LCD has to outline.
It has to line display
and it has fallen off and it has fallen off 5 by 7.
So this what this information means for more commands you can check the data sheets they have so many
commands out there you can check later.
We still have this her.
Sure we still have this here because we did not at the prototype of this function up there so cocky
bring it up here.
Paste control V and then semicolon it should disappear.
It's disappeared now.
So with added the first command with telnet you know what we want to Fed data and 8 bids and our LCD
displays to lives in and has a 5 by 7 font size.
So this good the next command is to tell the LCD internal on register to increment the curse up for
rest not too much too early and the code or the command for this is 0 x 0 6.
So all we have to do is LC the upfront new function put it to use policy zero 0 0 6 and medical equipment
for you swore increment automatically.
Finally the last two commands will be to 10 on the display and included display to 10 on the display
LCD command is 0 x 0 F like this and to clear the display issue x 2 a 1 or C to command 2 x 0 1.
So let's put this command here.
Let's put this comment here.
Just call it 10 on display then we'll put another comment here.
Clear display.
So yeah we've covered quite a lot.
We have to write one more function which is the LCD data the data function.
This is the one that would allow us to send data.
Then after that we just start typing our data out.
So we'll take a look at that in the next lesson.