Hello.
Welcome back.
So in this lesson we going to ride the SS I driver to interface a Texas Instruments and force you one
two three microcontroller with the SD 7 7 3 5 graphic liquid crystal display which is a colored LCD
screen for displaying graphics so I'm going to create a new project by coming over here.
Project your vision project
and I'm going to come over here.
Create a new format for this
I'll say Tim for C 1 2 3 SD 7 7 3 5.
Driver Not quite a project.
S t 7 7 3 5.
Driver
and the microcontroller is for C 1 2 3 0 8 6 p.m..
Select this over here.
Okay and the census isolate the core
on the device select the startup with this device or select startup
click okay here and I'm going to come over here Target's options
using distilleries I CDI setters reset and run.
Okay and then okay.
Right click here.
Target system for C T 4C one two three.
So this group here renamed to up
and in this project we actually are going to make it a bit more interesting by also initialize in an
ADC driver so that we can connect a potential meter to our microcontroller board and plot the resistance
as we turn the potential meters knob.
We will be able to plot how the default age changes on the LCD just for a test.
So I'm going to create a separate file for the LCD driver.
So come over here and.
I call this
g LCD
SD 7 7 3 5
and then I'm going to copy this name because I'm going to create the header file as well.
Right click right click each new item this ahead of file and it's going to be called this and I'm going
to create the main file right click that new item.
This is going to be made at C
OK.
So we start with the driver file.
This one here too we basically going to create a number of functions for initializing the LCD.
And what we're going to use here is going to be information from the the SD 7 7 3 5 data sheet the data
she talks about the various steps that needs to be taken in order to configure the LCD screen as well
as you know right data to it.
Right.
So let's start by including some symbolic names to are what drive here.
First of all list included the head of file of the microcontroller.
This is it.
Once that is done I'm going to if not define defined in this interface file
then.
And if over here
right now I'm going to include some symbolic names.
So these are names representing the setting of certain bits.
So it's in the control register 0 as well as the control register 1.
We're going to give all of these bit symbolic names to that rather than type the hexadecimal numbers
we just call the symbolic name.
And this is going to make the code more readable.
Right.
So this over here sets SS asynchronous serial port.
This represents this hexadecimal code and it's the same for all of them.
So that will reduce you know calculating what X hexadecimal code we need to pass to the register we
just call these symbolic names.
Once this is done there's one more I would have to include the busy bit
and Hubble will include one for the day transmits five or not for this is simply 0 0 2 we can give it
a symbolic name as well.
So we call an SSI status register TANF a simple cluster.
Once that is done we're going to add we're going to add more defined statement
and this this year is for the D.C. line.
As you can see on the MCU there is a line known as the DC line.
And this over here if we want to set a DC line high we pass this and then come mode would pass zero
data mode would pass through x 4 0
this year.
As for the DC line the address of the DC line.
And if we want to set a DC line to command what we pass through to data would pass through x force 0.
That is a.
And just as a reminder I'm going to bring the pin out here to remind us to remind us of what we're dealing
with.
So the DC is connected to p. 86.
That is why to set the data mode we set in this 2 4 0 0 x 4 0.
Because if I explained this to it's binary form you realize that bit bit 7 which is bits Number Six
because we count from 0 but 7 is set to 1.
If you expand this to accept it that if you expand this to its binary form you realize the bits number
six which is the seventh bit is set to 1 because we counter a 1 2 3 4 5 6.
Right.
I'm going to suffer a bit and the reset line is connected to pierce 7 okay.
So that's what we're dealing with.
Once that is done we can define our LCD board over here.
Create a symbolic name for that as well to improve readability.
I'm going to connect the LCD to put a
and then again when I put some other defined statement for the arrest pin which is P seven addresses
reset CSP and which is P A three.
So I'm just using bits shift here and then DC pin which is P6 right.
So of course symbolic names for these as well.
Once that is done I'm going to create a symbolic name for it for setting RSP in to 0 setting RSP into
one set and see esp into 0 setting it to 1 set in DCP into 0 and setting it to 1.
So when you have a symbolic name for that as well and I'm just gonna put these names here.
So if I simply call LCD R S 0 screen to set p a 7 2 0 2 if I call LCD R.S. one is going to set p a 7
to 1 and it's because we've written it this way.
So when we call the symbolic name this code is executed and it's the same for the rest.
Once that is done we're going to put some constant here with regards to the parameters of our LCD the
width of the LCD is one hundred and twenty eight pixels and the height is 160 pixels.
So I'm just going to create defined statement for these as well.
When I put them here like this once that is done we are going to define certain colors.
We can define colors as what colors are simply hexadecimal numbers like any other two.
I've got some colors that are already defined.
I'm just going to bring them as well.
Here are the colors right.
And once that is done some specific registers in the LCD.
When you take a look at the data sheet there is the R is set to register C it sets register and other
other locations in the LCD memory map and we're going to create defined statements to navigate this
locations.
These allocations in indeed OCD so there are other constants with regards to the LCD there is the art
is set which according to the data sheet is 0 x to be there is the C is at whose address is zero x to
a will be integrate define statement for D as well so that we can just call the symbolic names rather
than run it and end up with a code filled with hexadecimal numbers.
We don't want that.
That is why we are doing this.
So since we said we are going to be plotting graphs I've created a symbolic name for certain parameters
of the graph such as the background color of the graph.
The Axis color the background color and other things so I just I've just given them symbolic color names
because we've created a color names here.
So I just bring these deaths including the command for setting the display on and other things.
I just bring this here and we're going to use all of these in the c file.
That's one put in here so that as we type in the CFR we just don't see red marks because these symbolic
needs to know exist.
Once that is done in order to type text we need to have a font.
We need to include a font.
So I've generated this font and fonts are generally generated there are different types of font so it
is just a long array of numbers of new 8 numbers.
And that is how you get the font on the LCD screen so this font and these numbers represent 0 to 9 ABC.
All the characters or the symbols.
Question mark comma harsh.
All of it is represented in this in this array.
So this the format and simply calling it font over here.
The reason we have this error is because we've not included sd d and so I'll come over here and include
it
and it's disappeared.
Right.
So now that we've sorted this out let's go to our implementation file which is they don't see file and
start writing out the functions
so we're going to need a delay function cause during the initialization process where we set certain
bits we've got to wait for some time before we move on.
Cos of that I'm going to bring this time of function here like this.
And the reason I'm bringing this time a function without write in is because we've already learned how
to write such time of functions in the time section so I know you would understand what is going on
here.
The reason we have these marks is because we don't have access to these microcontroller specific structures.
So all I need to do is include the DOT h file because we've already included temp for C dot h here.
So I'm gonna include a dot h file here.
Our problem should be solved right.
Once this is done I'm going to create a function called SS I 0 in it so I'll save for it SS I 0 on the
score in it and this takes no argument open closed.
So I'm going to start off
I'm going to start off by actually bringing in some more I'll create some local create some local global
share some global variables global only 2 the dot c 5 million.
We cannot fetch them outside this far but any function in this file can fetch them and I'll just bring
them here.
This includes setting the width and height of the LCD which we've already defined in a dot.
Each file we defined this we defined this as well we set in start X to 0 starts way to 0 and we have
columns that's real estate and text color to 0.
We've just set these goals we're going to need them right.
So once that is done I'm going to initialize the column start and the row starts as well as create a
new variable called delay like this.
And once that is done I'm going to enable clock access to the SS II module as well as the keep your
module that we've connected the SS to and I'm going to come here and do this like this and this line
here is just to make sure that the initialization is complete before we move on to the to the next line
of code.
So there's just a blocking statement to make sure that we've completed executing these two lines before
we can move on.
So this just a poor.
This can be admitted.
Yeah there's nothing wrong with it.
Once that is done I'm going to go to GPL you a and access the direction register and set the pace that
we need
setting them US UP BRING OUR HEAD a file here.
This should assist the
some of the things that we're using put this yes.
Well as a reminder and then I'll set the alternate function the alternate function is set and then digitally
enabled them
once that's done.
I coached at Port controller register
and then inserted.
Then once that is done or disable analog so let
once that is done I'm going to set the C S line to 0 and then the address line to 1.
Remember we already created symbolic names for C S 0 and R S 1
and according to the data sheet when we set CSU to arrest one we've got to wait for a bit and then we
set our best to 0 and then wait for a bit and then sets out as to 1.
So we've got to follow that initialization sequence.
So I'm going to wait for 500 EMIs once that is done.
I'm going to set R S to 0.
We already have a symbolic name for set in r s to 0 as well.
So once that is done I'm going to wait for another 500 m s
and then set R Us to 1
and then
wait for another 500 m s once we've done this.
We go ahead to initialize the SSI module
right.
So we set up these and then we disable the SSA module by access the contra register one and using the
enable pin that we have here because we've already created this symbolic name for this and then will
select master mode.
We've already created a symbolic name for Master mode as well.
You can find all of these in these that each these defined a statement we have here.
Once that's done we configure for system clock and the bot rate source and all of this is making use
of the defined statement we wrote earlier.
And to learn more about any of these registers you can simply go to the data sheet find the SSI readable
these registers.
The reason in the beginning I spent so much time taking you to the data sheet to help you navigate and
find various registers and how to read the the the bits and decode the meaning of each bit set in so
that I can move faster in the later sections such as this one so that I can simply use a register and
tell you this is the register required and knowing that you can go to the data sheet on your own as
an independent and better developer to be able to locate these registers and read more about them and
understand or should you be confused as to why you know for instance as to why we set and see are one
we set it to less is we set in bits one to one if you don't understand that you simply need to go to
SS a section in the data sheet find a C R1 control register 1 and then check bit 1 and see if between
is 0 What happens if between is 1 what happens by finding that out you simply understand everything
should you be confused right
if you have any questions of course you can send me a message
right.
So this is going to be our SSA in its function but we have to include further code here for some initialization
code months across the data.
She talks about setting common sequence that you need to execute during initialization and write it
an item to this function we go into create a separate function to sort out that that task
right.
So let's just without an order not to forget it.
Let's write it here.
So I'm going to call this new function.
Void standard in its command or you can give it whichever name you want.
And according to the data sheet to initialize we start off by set in the C S line our baseline to 0.
We wait for around 10 milliseconds said the errors line to 1 and then would write command we write a
specific command and then we go on from there.
So we start off by setting C s2 0 arrest 0
we wait for 10 m s and then we set our rest to 1 we wait for another 10 m s and then we write the commands
0 x 1 1 2.
I'm going to bring this here.
So this should tell you that we need to write a function that would help us write commands.
We currently don't have this function.
That is why we have this red mark.
We should write this function after this wonder we are currently dealing with we radical monster x 1
1.
We wait a bit longer this time let's say we wait for 120 milliseconds.
Once that is done we write the command to set the color to sets the bids.
And finally we set a display.
And just like the datasheet of the of the microcontroller if there's a specific hexadecimal command
you do not understand.
You can find this in the data sheet of the LCD the SD 7 7 3 5 LCD.
These commands and the Armenian is written in there right.
And one other thickness.
This course is going to be is going to be mostly about dealing with the LCD at this point.
Really.
We are done with initialize and the SBA or the SSA module.
That's the thing with SSI.
It's initialization is so simple and straightforward.
Majority of the time you spend customizing functions for communicating with a particular SSI slave.
In this case the rest of the course is going to be spent or the rest of this particular lesson is going
to be spent on writing functions to sort of navigate it configure and write data to the LCD screen taken
into account or or using the information provided in the LCD data sheet.
So that's what we are doing though right.
So because of that some of the functions I'm just going to gloss over because this is not a lesson on
this particular graphically liquid crystal display.
It's a lesson on SBI just that it will be interesting to show you how it works with a real world slave.
That is where we have this LCD here.
Okay so once this is done we still have this function to sort out.
We have two functions here one for writing code on one for writing data.
Command is different from data.
Data is where you want to be sort of printed on the screen.
Command is sent to the screen to configure it such as configured the color mode configure the bid size
turn on the LCD sets the cursor etc..
So that is why we would have two functions one for command another one for data.
So less rights the function for writing commands.