So welcome back.
In order to start sending data we have to type out the data function the function that would set the
proper register requirements in place to allow us to send data.
So we would just write to her.
It's very quick.
Let's declare it for LCD data.
Now this boy down here close to the LCD command.
I'll just put it here.
Void LCD on this court data.
And just like the LCD command.
This one takes one argument and this argument is not the type of assigned character we call it data
and this data we want to write to the LCD.
And we said in order to send data to the LCD we have to set the R S pin of the LCD to 1 in order to
allow the internal shift registers of the LCD to choose the data register.
So that's what we do here.
You start by selecting the data register and all we have to do is write which puts a chip a data
and don't let this confuse you GPA or a data and this data has nothing in common.
The states are registered and we want to write to is in the internal.
You know the internals of the LCD the LCD has two registers inside it has one for command and one for
data and we select them and then we write command or select and write data.
And this one here is the basic way of writing to a GPA or pots pin.
We call it GPA or data.
I hope you get the police whatever you do not understand.
It in the comment box below.
Thank you.
So let's continue.
So GPA or a data we write the value 0 x to 0 2.
And basically what this means let me keep you young.
Buying a reform the binary form is this serious you know 1 0 and 1 2 3 4.
Yeah of course this is a 32 bit value or it's supposed to get 32 bit value all of these proceedings
heroes can be cleaned and we can shorten a hair and it would work perfectly.
That's why we keep on right here.
That's why we don't write all the other numbers.
So yeah.
And what this means is our S which is the register select S equals 1 and naval pin Coursera and then
our Coursera show remember our s Let's just check here.
This is p a zero P A one two three.
Keep it for a five when you check your physical connection your red lights that you connected to R S
pinned to a five.
That is why you've changed this p a five to one get called out to set it high to select the data register
inside the LCD.
So yeah.
So once we select a data register we write our data and we do this by a sign in the IQ meant to this
GPA or GPA or a data
equals data.
Basically it's this local variable data that we assign in her and after we do the Senate pass by enabling
P E for a brief moment and what we do is to create a data today and a data then we thought this.
Don't forget to do this.
This vertical line and equal to it.
If you don't put this vertical line and you write directly to it.
Remember they are the same registered to share the same register.
So when we write directly we change in all the values of the register.
If we are to write without this line and then we just write 0 x.
If we are to write just X sorry 0 x 8 0.
If we had to write just this this one is going to happen like always.
Let me break it down to binary for you.
What is going to happen is we are going to have 1 0 0 1 2 3 4.
And as you know a 0 a 1 8 2 8 3 8 4 8 5 6 7.
So this the new value.
But as you can see this fund to us has disabled this set and that we created earlier and we want to
keep this in order to keep this.
We do this.
We use the all operator and we put a vertical line.
So when we put this vertical line this father here this previous setting of the value is added to this
one conclusion
this previous setting is added like this.
And an operation is performed when we perform.
The answer becomes as you can guess it comes 1 0 1.
Remember this one here and to say and then the rest of us to which serious you I've thought is why we
bought this line.
Also if you don't quite get this there is a course on the basics of embedded sea cortex programming
which you can take a quick look at.
It's explains these things in details and it makes programming really easy and robust.
So that being said let's continue.
We have this we've send the pulse and just like we did we delayed Michael delay 0 here which we can
play wait or manipulate this file to her and finally we set it back to ISSUE super cheap or a data register
because 2 x 0 0 and then then we delay again
if we want.
It's always good to be given bits of delay.
Usually the best way is to give the minimum amount of delay as you go on to see how how well the microcontroller
would catch up or how well the LCD will catch up put a microcontroller and then you start reducing the
amount of delay gradually till it still works in order not to slow down the computer so you test you
reduce the amount of delays gradually.
So when we run it and it works we might need to reduce some of this delay amount and when the program
still works which means it's fine.
So now everything is set.
We have to do now as typos are our data.
So the first thing we do we have to clear the screen set the cursor home and remember we call the command
to do this for us.
Let's use this fiscal month as LC to command 2 x 2 1
class to screen LCD command 0 x 0 8.
This sets the coast home now.
This queen is Claire.
The curse I sent home and delay a bit just to allow these commands to finish executing.
Okay good.
How about we compile and see whether the compiler agrees with what we're 3 2 or one warning.
It's probably because of no new line.
It's probably down here.
It should work.
Or two warnings.
Okay so the compiler agrees with what we've written that is great.
So let's just put some basic data here.
Remember data is transferred one character at a time.
Do not worry I know that sounds a bit cumbersome to type one character at a time in the next lesson.
I'll show you a function would engineer a function doubt allow us to type sentences at once.
Let's play with our data and see.
Basically I'm going to call the LC data
how come we cannot see ahead.
Where are you.
Data show.
The reason why LCD data is this way and we couldn't find it into help was because as you can guess we
did not at to prototype up there.
So just like we did for all the our functions as copies is and how to set function code to type now
the only D stuff.
This one here requires an argument I'm going to put on arguments here see like this and the function
works so as great as I'm just going to try C M cortex.
So as we said you can park your data with very very minimal delays to allow the LCD to catch up with
the microcontroller show.
I put a delay here and then I'll call the LCD data again and then write the second correct.
Which is the end
okay.
This should work
delay my could all that to go back to the top of the loop.
Let's see so let's compile this and download onto a board and see what happens.
Okay.
Super errors two warnings
OK it's downloaded.
I hope you've downloaded all your board so please plug in your board download it and then reset your
MCU the microcontroller to see what happens.
So mine is in work.
And I guess yours isn't working as well as a might be wrong given the speed at which we timed out this
long code.
My top mid said all mistyped something.
Let's start from the top.
There are prototypes looks like that in order.
Let's see here.
Okay let's increase this delay effort to millisecond.
Okay.
And then this come here.
I suspect the arrow here goes nothing at all.
Change is on the board.
It has to be the initialization.
Let's see the first one GPI.
Oh this one here.
This one here opens the clock for court.
This one opens the clock for good.
Aha.
There is a problem here.
Okay.
How about we post the video and let's see what you can figure out what the problem is
it's a simple one.
As you can see we dealt with the same issue here.
Remember when we got here and I was explained and I said if we write to this register directly by using
just the equals sign we change in all the values of the register.
So therefore when we get here and we write this new value we wouldn't have our R as selected.
Therefore we have to use this.
It's the same thing happened here.
The RC GC GP registered the this registrar is the same but there are various bits inside to enable different
GP I will pots.
So what we did here was we anybody put a.
And what we got here.
We disabled poor and disabled put the what we want is to enable them both so we can just use the or
operator to add this line here and then would enable it.
So this problem is solved.
Let's see what else we might have lingering around down there.
Let's see.
Aha.
There is another one.
Look at this line.
This line looks okay but it is very problematic actually over here.
What we did was we selected.
We made our eyes course to one using TPA or a course we connected our LCD control registers to the GP
a sort of controlled registers are useful.
Just selection only and the data registers are useful.
Rights and data and data is in the form of command data and actual data.
So when we write 0 x 0 1 which is 2 to enable this screen or to clear the screen this 0 0 1 is a form
of data which is transmitted to the command register and we do it up by telling the LCD we want the
command register active and then we transmit data to where.
But what we did here was we use the.
I should also point out that we use the arm that paints the data pins d you go through a D7 to transmit
in a form of data without the data is actual data or its command data.
We use these pins but we made the mistake of trying to write data to the control the control parts with
it which is GP 8 or a actually it should be GPA.
This is how data is transmitted.
Course we've connected our 8 bits of data line to put to put B.
So let's recap what we just did.
So we came here.
We selected we selected the the LCD data register and we did this by set an R as 2 1 and then we wrote
data we put data into data bus and basically we make GPA will be our data bus and then we put our data
there so I know what might seem confusing as we're using the named data and command.
Meanwhile command actually is a type of data.
So the same thing is affecting this function that we wrote over here we selected our hero.
The only difference between this and this should be are you actually.
So we selected our zero and we have to write a command to it.
And remember this command also has to be put in the database and sent to the command register inside
our Su and we designated codes B I saw one data bus but we forgot we got excited and kept typing and
typing.
So yeah this line here should be GPA would be data and this line should be data anyway.
Yeah.
If anything this error has taught us to pay more attention.
And one last thing I realized right now was we said we have to senate pass through P E while we did
it.
We enabled and didn't disable it mean meaning we did not actually senate pass through it.
We kept it enabled in order to send a oppose would just enable and disable very briefly and we do this
by setting this data register back to 0 x 0 0 and everything should work perfectly.
Now let's compile and let the compiler judge.
Okay so white is working as you can see it's working
and the potential for me to adjust in the contrast is this little one I have heard by turning it contrast
changes.
Yeah.
All we have to do is play with a bulb used in the arm in the data.
Let's try to extend the amount of data we transmit and try to play around with and delay values a bit.
Yeah so see you in the next lesson.