Right.
So you can decide to create a new file for the ADC driver.
Oh we can just keep the ADC driver in the main file.
So I'm just going to keep the adc in the main file.
But you can create an ADC to C and ADC dot H.
Hmm.
Actually let me just show you how to much low rise.
This by having a separate driver in a separate file for the ADC.
So I'm going to come by here at new item.
It's a c file.
Ordinarily I would keep this in the main file but since then the lesson that since perhaps it would
be useful and look more and.
Yeah let me just keep it in the in a separate file.
I'll call this A C C and then I'll call this it is that H.
And the reason I'm doing this is to show you we can reuse each of the drivers separately so we can simply
copy LCD C and LCD to each and add it to a different project that we are using in the same way.
The ADC driver that we are both right we can copy ADC that C ADC dot H and add it to a different project.
That is why I've decided to keep the ADC functions in a separate FA right.
So yeah it's just for this purpose.
But ordinarily I would just add it in the in demand or c file since I've got my own written ADC drivers.
Much more complicated than the one we're going to use so I hope you understand in a way I'm going to
do if not define define
it.
OK.
Right.
So I'm going to have an ADC 0 in it.
I'm just gonna put a prototype here cause this has to be clinical.
I'm going to have another function on us ADC.
Get results.
Right.
So all we have to do is go to the go to the doc see file and implement these functions.
The reason we have this error is because we've not included a study end
show.
Come over here and include it if you don't age.
Another thing we need to include is the header file for our microcontroller.
So come over here right click and then include this over here.
Once that is done we can come over here and implement our ADC in its function.
This is 0.
We use an ADC 0 and it's over here.
Void void.
Open Close and we are going to initialize P3 as our ADC input.
You start off by enabling clock access to the port e as well as the ADC module.
And I explained why we enable clock access.
I explained this earlier that 4 for saving power.
There is this mechanism known as the clock gate and mechanism for mode in the microcontrollers meaning
by default the peripheral or the module has no clock enabled to it in DC.
And this saves power.
If you want to use a particular module or power for you need to enable that clock.
That is why we access the GPO.
I receive GC
points to enable our AC DC GPA to enable the clock for GPA you E and then RC GC ADC and the GC is the
clock gate and register so this stands for clock gate.
This probably stands for clock gate in C clock and then gate and then control.
Right.
They can verify this from the datasheet we spoke about this earlier.
If we did not talk about this maybe then I spoke about it in the SDM 32 course but in any case that
is why we always have to enable clock in the past in very good microcontrollers.
Clock the clock was enabled for all the parts or the peripherals so there was no need in enabling clock
access to particular peripherals but later on it was realized that this waste power.
Why do you have to have clock access to each and every module of the of the microcontroller.
If you're not using it because of that we have to enable clock only to the modules we use in right.
So let's move on.
We are going to enable P3 like I said and this over here and there was it was said the alternate function
select D to enable and then we set analog select analog mode select and once that is done we configure
ATC itself.
And the reason I'm going quickly with this is because we already studied if I write in ADC drivers in
the ADC section to reconfigure the ADC here we use in the sample sequence are three because we have
just one one channel here and it's sufficient for what we are about to do.
Once that is done we move on to the next function the function 4 gets in the resort.
This is going to return you into that 32 data type and it's quality.
This is 0 underscore gets results.
It's going to take no variable.
It's going to take no arguments open and close.
We start off start a conversion
and then wait for conversion complete
that we'd read the results
declared a completion flag and we returned to results.
And the reason we have this is because we've not defined results.
Okay.
Right.
Sorry about the
tattoo on this quality.
So it's okay.
We should be fine.
Okay.
Let's see.
What happened here.
Yeah.
Know what happened here okay.
We simply returned the resort and this will be the ADC Value.
Okay.
So we've got our drivers set.
We can put it all together in the main file.
So let's go to the main file now.
I am going to come over here and I'm going to include include
ADC to h as well as include
this is called g LCD G key LCD and I score SD 7 7 3 5 and age right.
We've got both the LCD and ADC drivers included here.
Once that is done I'm going to open
each made
and within main I'm going to initialize the ADC cause we've already written the function for performing
the ADC in it and I'm going to initialize the graphic display as well because we have the already written
the reason we have in this is because it's not included in no gun each far
we've got to include that in it and in on each file.
This should make this disappear right.
Once this is done
we can get no infinite loop here.
And I'm going to create functions for plotting the data as well as trying the axes.
I'm gonna have a function here and you're not strong.
Actually is this going to be a local function.
And this basically is going to set the axes color background color and then I'm going to call the axis
time for x axis ADC for y axis and you can read the content of draw axes.
Further if you do not understand and we've got to define the maximum why if I do as well as the minimum
wage value so I'm gonna bring the here
we can define y much
OK.
Two to fit this maximum ADC.
And why me can this hero
and we can put a prototype of this function up here.
Right.
We are going to have another function for growing less if we want to have an informal bar just like
you have a task or in full bar at the top of the top of your phone showing your battery level that date
and time we can have a similar thing.
So over here we could say we are showing the CPSU how much work to use perform in the temperature and
other things.
So I've just written the string here.
C.P. you of course 85 percent utilization temperature equals 30 degrees.
So this is going to be printed at the top.
I'm calling this in full.
Right.
Once this is done we can put a prototype
over here.
You can see the reason it's going to be at the top is because we are using these these positions these
coordinates to put out the top and you can read more about these from the respective functions.
Once we've got the info bar and the draw axes we can call them here
and this should be a full bar
right.
Once that is done we can either last the last function or be to plot the data.
So basically to plug the data we need to plot the point and increment to the next position in order
to be able to plot the point in the next position.
So we're going to have a function and another local function here and then as plot data.
And this simply plot point sense of value is going to be the value we read from the ADC.
Once we've plotted the point we increment the next position.
I'm going to this defined sense of value over here at the top.
And once that is done I'm simply going to read a sense of value from EDC using the ADC get to resort
to function.
We wrote in The ADC module once that is done.
I'm going to plot data about all of these functions that we've written.
You can write them in how you want.
Right.
Forrester's plot data here could be could be made to take an argument and the arguments should be what
is plotted.
So for instance this can be you interface to underscore t sense of value and then that will be passed.
You can rewrite this function.
These functions aren't perfect they're just good for the test.
We're going to write we're going to run of hard coded sense of value into this function.
But ordinarily you would want to allow the function to take an argument.
Right.
So our code looks complete thus far.
Or C it looks fine or we have to do now is build get it onto our board connect our LCD and potential
meter to the board and see how we works where to click over here to build
and it's built successfully.
Let's get it onto the board and see how it works.
Certain business setup.
Excuse the mess but if the attention of the method of what a new report get cause on powering the LCD
display using if you're bored.
Remember the two most important US firewalls to provides just three point report.
So I'm using the nuclear provided fiber.
That's the only reason the nuclear is here and there's the LCD and this is exactly it could be rude
to plug the ABC value.
No need to move money my ABC and CBS the main ABC.
Right.
So this is it.
Well like I say the potential I mean I'm going to move the potential need to modern ABC.
This is my potential into I'm going to move it and I can see it's being plotted accordingly.
Right.
And I said the potential router can be replaced with your own sense of it it doesn't often get attention.
And yes this is it.
And you know it is untouched as in the abstract to go it's the following.
You can take a look at it.
I'm going to upload quality code to the diplomacy.
That's all there is.
You have any questions just let me know and I'll see you later.