1
00:00:01,530 --> 00:00:01,920
Right.

2
00:00:02,250 --> 00:00:08,070
So you can decide to create a new file for the ADC driver.

3
00:00:08,090 --> 00:00:12,780
Oh we can just keep the ADC driver in the main file.

4
00:00:13,020 --> 00:00:15,510
So I'm just going to keep the adc in the main file.

5
00:00:15,540 --> 00:00:19,830
But you can create an ADC to C and ADC dot H.

6
00:00:19,890 --> 00:00:20,270
Hmm.

7
00:00:20,330 --> 00:00:23,580
Actually let me just show you how to much low rise.

8
00:00:23,590 --> 00:00:28,320
This by having a separate driver in a separate file for the ADC.

9
00:00:28,320 --> 00:00:31,390
So I'm going to come by here at new item.

10
00:00:31,440 --> 00:00:32,310
It's a c file.

11
00:00:33,360 --> 00:00:39,870
Ordinarily I would keep this in the main file but since then the lesson that since perhaps it would

12
00:00:39,870 --> 00:00:43,140
be useful and look more and.

13
00:00:44,150 --> 00:00:47,290
Yeah let me just keep it in the in a separate file.

14
00:00:47,290 --> 00:00:53,240
I'll call this A C C and then I'll call this it is that H.

15
00:00:53,250 --> 00:01:01,200
And the reason I'm doing this is to show you we can reuse each of the drivers separately so we can simply

16
00:01:01,200 --> 00:01:08,240
copy LCD C and LCD to each and add it to a different project that we are using in the same way.

17
00:01:08,240 --> 00:01:15,990
The ADC driver that we are both right we can copy ADC that C ADC dot H and add it to a different project.

18
00:01:16,050 --> 00:01:21,730
That is why I've decided to keep the ADC functions in a separate FA right.

19
00:01:21,750 --> 00:01:24,710
So yeah it's just for this purpose.

20
00:01:24,740 --> 00:01:33,560
But ordinarily I would just add it in the in demand or c file since I've got my own written ADC drivers.

21
00:01:33,720 --> 00:01:39,810
Much more complicated than the one we're going to use so I hope you understand in a way I'm going to

22
00:01:39,840 --> 00:01:42,240
do if not define define

23
00:02:03,460 --> 00:02:06,120
it.

24
00:02:06,790 --> 00:02:07,690
OK.

25
00:02:09,340 --> 00:02:10,190
Right.

26
00:02:10,420 --> 00:02:15,850
So I'm going to have an ADC 0 in it.

27
00:02:16,010 --> 00:02:19,310
I'm just gonna put a prototype here cause this has to be clinical.

28
00:02:19,410 --> 00:02:21,840
I'm going to have another function on us ADC.

29
00:02:21,850 --> 00:02:22,630
Get results.

30
00:02:26,650 --> 00:02:27,320
Right.

31
00:02:27,860 --> 00:02:34,760
So all we have to do is go to the go to the doc see file and implement these functions.

32
00:02:34,770 --> 00:02:38,410
The reason we have this error is because we've not included a study end

33
00:02:42,300 --> 00:02:42,800
show.

34
00:02:42,840 --> 00:02:50,270
Come over here and include it if you don't age.

35
00:02:50,790 --> 00:02:54,420
Another thing we need to include is the header file for our microcontroller.

36
00:02:54,480 --> 00:02:58,830
So come over here right click and then include this over here.

37
00:02:58,830 --> 00:03:07,450
Once that is done we can come over here and implement our ADC in its function.

38
00:03:08,160 --> 00:03:09,000
This is 0.

39
00:03:09,000 --> 00:03:14,370
We use an ADC 0 and it's over here.

40
00:03:14,500 --> 00:03:16,060
Void void.

41
00:03:16,830 --> 00:03:22,340
Open Close and we are going to initialize P3 as our ADC input.

42
00:03:22,350 --> 00:03:29,280
You start off by enabling clock access to the port e as well as the ADC module.

43
00:03:29,490 --> 00:03:33,450
And I explained why we enable clock access.

44
00:03:33,510 --> 00:03:37,380
I explained this earlier that 4 for saving power.

45
00:03:37,530 --> 00:03:44,760
There is this mechanism known as the clock gate and mechanism for mode in the microcontrollers meaning

46
00:03:45,240 --> 00:03:51,940
by default the peripheral or the module has no clock enabled to it in DC.

47
00:03:51,990 --> 00:03:53,490
And this saves power.

48
00:03:53,490 --> 00:03:59,490
If you want to use a particular module or power for you need to enable that clock.

49
00:03:59,550 --> 00:04:02,710
That is why we access the GPO.

50
00:04:02,730 --> 00:04:04,140
I receive GC

51
00:04:10,560 --> 00:04:23,220
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

52
00:04:23,220 --> 00:04:28,960
clock gate and register so this stands for clock gate.

53
00:04:29,100 --> 00:04:35,470
This probably stands for clock gate in C clock and then gate and then control.

54
00:04:35,640 --> 00:04:36,200
Right.

55
00:04:36,250 --> 00:04:39,990
They can verify this from the datasheet we spoke about this earlier.

56
00:04:39,990 --> 00:04:45,870
If we did not talk about this maybe then I spoke about it in the SDM 32 course but in any case that

57
00:04:45,870 --> 00:04:51,570
is why we always have to enable clock in the past in very good microcontrollers.

58
00:04:51,570 --> 00:04:59,130
Clock the clock was enabled for all the parts or the peripherals so there was no need in enabling clock

59
00:04:59,190 --> 00:05:04,490
access to particular peripherals but later on it was realized that this waste power.

60
00:05:04,530 --> 00:05:11,240
Why do you have to have clock access to each and every module of the of the microcontroller.

61
00:05:11,250 --> 00:05:19,250
If you're not using it because of that we have to enable clock only to the modules we use in right.

62
00:05:19,350 --> 00:05:20,280
So let's move on.

63
00:05:20,310 --> 00:05:29,290
We are going to enable P3 like I said and this over here and there was it was said the alternate function

64
00:05:29,310 --> 00:05:37,490
select D to enable and then we set analog select analog mode select and once that is done we configure

65
00:05:37,750 --> 00:05:38,690
ATC itself.

66
00:05:38,700 --> 00:05:45,720
And the reason I'm going quickly with this is because we already studied if I write in ADC drivers in

67
00:05:45,720 --> 00:05:52,350
the ADC section to reconfigure the ADC here we use in the sample sequence are three because we have

68
00:05:52,350 --> 00:05:57,590
just one one channel here and it's sufficient for what we are about to do.

69
00:05:57,600 --> 00:06:02,950
Once that is done we move on to the next function the function 4 gets in the resort.

70
00:06:02,970 --> 00:06:07,380
This is going to return you into that 32 data type and it's quality.

71
00:06:07,380 --> 00:06:12,600
This is 0 underscore gets results.

72
00:06:13,140 --> 00:06:14,520
It's going to take no variable.

73
00:06:14,700 --> 00:06:20,150
It's going to take no arguments open and close.

74
00:06:20,250 --> 00:06:24,540
We start off start a conversion

75
00:06:29,050 --> 00:06:31,240
and then wait for conversion complete

76
00:06:34,820 --> 00:06:37,080
that we'd read the results

77
00:06:40,950 --> 00:06:47,210
declared a completion flag and we returned to results.

78
00:06:47,400 --> 00:06:52,260
And the reason we have this is because we've not defined results.

79
00:06:52,370 --> 00:06:54,750
Okay.

80
00:06:54,770 --> 00:06:56,300
Right.

81
00:06:56,530 --> 00:06:57,220
Sorry about the

82
00:07:28,330 --> 00:07:31,020
tattoo on this quality.

83
00:07:31,210 --> 00:07:32,110
So it's okay.

84
00:07:32,110 --> 00:07:32,920
We should be fine.

85
00:07:33,670 --> 00:07:33,990
Okay.

86
00:07:34,450 --> 00:07:35,160
Let's see.

87
00:07:37,130 --> 00:07:38,080
What happened here.

88
00:07:40,400 --> 00:07:41,750
Yeah.

89
00:07:41,940 --> 00:07:44,840
Know what happened here okay.

90
00:07:45,130 --> 00:07:48,430
We simply returned the resort and this will be the ADC Value.

91
00:07:48,510 --> 00:07:48,950
Okay.

92
00:07:49,010 --> 00:07:51,190
So we've got our drivers set.

93
00:07:51,190 --> 00:07:53,820
We can put it all together in the main file.

94
00:07:53,980 --> 00:07:55,680
So let's go to the main file now.

95
00:07:56,230 --> 00:08:02,590
I am going to come over here and I'm going to include include

96
00:08:06,460 --> 00:08:10,900
ADC to h as well as include

97
00:08:18,970 --> 00:08:31,270
this is called g LCD G key LCD and I score SD 7 7 3 5 and age right.

98
00:08:31,330 --> 00:08:35,570
We've got both the LCD and ADC drivers included here.

99
00:08:35,590 --> 00:08:37,750
Once that is done I'm going to open

100
00:08:42,490 --> 00:08:43,200
each made

101
00:08:50,690 --> 00:08:57,650
and within main I'm going to initialize the ADC cause we've already written the function for performing

102
00:08:57,650 --> 00:09:07,060
the ADC in it and I'm going to initialize the graphic display as well because we have the already written

103
00:09:15,150 --> 00:09:20,040
the reason we have in this is because it's not included in no gun each far

104
00:09:39,120 --> 00:09:43,670
we've got to include that in it and in on each file.

105
00:09:43,840 --> 00:09:45,990
This should make this disappear right.

106
00:09:49,400 --> 00:09:50,450
Once this is done

107
00:09:59,590 --> 00:10:01,410
we can get no infinite loop here.

108
00:10:08,380 --> 00:10:14,590
And I'm going to create functions for plotting the data as well as trying the axes.

109
00:10:14,650 --> 00:10:16,610
I'm gonna have a function here and you're not strong.

110
00:10:16,600 --> 00:10:18,630
Actually is this going to be a local function.

111
00:10:20,520 --> 00:10:30,260
And this basically is going to set the axes color background color and then I'm going to call the axis

112
00:10:30,890 --> 00:10:38,780
time for x axis ADC for y axis and you can read the content of draw axes.

113
00:10:38,990 --> 00:10:44,720
Further if you do not understand and we've got to define the maximum why if I do as well as the minimum

114
00:10:44,720 --> 00:10:47,150
wage value so I'm gonna bring the here

115
00:10:59,860 --> 00:11:01,900
we can define y much

116
00:11:07,050 --> 00:11:07,700
OK.

117
00:11:07,780 --> 00:11:11,940
Two to fit this maximum ADC.

118
00:11:13,990 --> 00:11:15,550
And why me can this hero

119
00:11:24,290 --> 00:11:29,800
and we can put a prototype of this function up here.

120
00:11:32,740 --> 00:11:33,180
Right.

121
00:11:33,210 --> 00:11:38,110
We are going to have another function for growing less if we want to have an informal bar just like

122
00:11:38,110 --> 00:11:45,700
you have a task or in full bar at the top of the top of your phone showing your battery level that date

123
00:11:45,700 --> 00:11:47,440
and time we can have a similar thing.

124
00:11:48,160 --> 00:11:55,270
So over here we could say we are showing the CPSU how much work to use perform in the temperature and

125
00:11:55,270 --> 00:11:55,690
other things.

126
00:11:55,690 --> 00:11:59,150
So I've just written the string here.

127
00:11:59,190 --> 00:12:05,590
C.P. you of course 85 percent utilization temperature equals 30 degrees.

128
00:12:05,620 --> 00:12:07,600
So this is going to be printed at the top.

129
00:12:07,610 --> 00:12:09,040
I'm calling this in full.

130
00:12:09,460 --> 00:12:12,220
Right.

131
00:12:12,310 --> 00:12:14,920
Once this is done we can put a prototype

132
00:12:17,560 --> 00:12:19,210
over here.

133
00:12:19,660 --> 00:12:26,140
You can see the reason it's going to be at the top is because we are using these these positions these

134
00:12:26,140 --> 00:12:32,220
coordinates to put out the top and you can read more about these from the respective functions.

135
00:12:32,710 --> 00:12:36,040
Once we've got the info bar and the draw axes we can call them here

136
00:12:41,820 --> 00:12:43,330
and this should be a full bar

137
00:12:55,570 --> 00:12:56,590
right.

138
00:12:56,620 --> 00:13:02,590
Once that is done we can either last the last function or be to plot the data.

139
00:13:02,740 --> 00:13:08,680
So basically to plug the data we need to plot the point and increment to the next position in order

140
00:13:08,680 --> 00:13:11,600
to be able to plot the point in the next position.

141
00:13:11,650 --> 00:13:15,460
So we're going to have a function and another local function here and then as plot data.

142
00:13:15,460 --> 00:13:20,710
And this simply plot point sense of value is going to be the value we read from the ADC.

143
00:13:20,920 --> 00:13:24,520
Once we've plotted the point we increment the next position.

144
00:13:24,520 --> 00:13:29,160
I'm going to this defined sense of value over here at the top.

145
00:13:29,170 --> 00:13:35,830
And once that is done I'm simply going to read a sense of value from EDC using the ADC get to resort

146
00:13:35,830 --> 00:13:36,490
to function.

147
00:13:36,520 --> 00:13:40,690
We wrote in The ADC module once that is done.

148
00:13:40,990 --> 00:13:45,840
I'm going to plot data about all of these functions that we've written.

149
00:13:45,850 --> 00:13:47,730
You can write them in how you want.

150
00:13:47,770 --> 00:13:48,900
Right.

151
00:13:49,240 --> 00:13:55,870
Forrester's plot data here could be could be made to take an argument and the arguments should be what

152
00:13:55,870 --> 00:13:56,960
is plotted.

153
00:13:56,980 --> 00:14:03,760
So for instance this can be you interface to underscore t sense of value and then that will be passed.

154
00:14:03,820 --> 00:14:05,440
You can rewrite this function.

155
00:14:05,440 --> 00:14:08,440
These functions aren't perfect they're just good for the test.

156
00:14:08,440 --> 00:14:13,750
We're going to write we're going to run of hard coded sense of value into this function.

157
00:14:13,750 --> 00:14:18,350
But ordinarily you would want to allow the function to take an argument.

158
00:14:18,630 --> 00:14:19,150
Right.

159
00:14:19,570 --> 00:14:22,190
So our code looks complete thus far.

160
00:14:22,210 --> 00:14:30,760
Or C it looks fine or we have to do now is build get it onto our board connect our LCD and potential

161
00:14:30,880 --> 00:14:35,170
meter to the board and see how we works where to click over here to build

162
00:14:39,860 --> 00:14:41,110
and it's built successfully.

163
00:14:41,240 --> 00:14:43,670
Let's get it onto the board and see how it works.

164
00:14:43,730 --> 00:14:45,400
Certain business setup.

165
00:14:46,280 --> 00:14:56,060
Excuse the mess but if the attention of the method of what a new report get cause on powering the LCD

166
00:14:56,120 --> 00:14:58,290
display using if you're bored.

167
00:14:58,430 --> 00:15:03,740
Remember the two most important US firewalls to provides just three point report.

168
00:15:03,770 --> 00:15:06,610
So I'm using the nuclear provided fiber.

169
00:15:06,710 --> 00:15:13,250
That's the only reason the nuclear is here and there's the LCD and this is exactly it could be rude

170
00:15:13,460 --> 00:15:15,510
to plug the ABC value.

171
00:15:15,550 --> 00:15:21,730
No need to move money my ABC and CBS the main ABC.

172
00:15:22,090 --> 00:15:22,520
Right.

173
00:15:23,000 --> 00:15:23,850
So this is it.

174
00:15:24,490 --> 00:15:30,590
Well like I say the potential I mean I'm going to move the potential need to modern ABC.

175
00:15:30,650 --> 00:15:37,430
This is my potential into I'm going to move it and I can see it's being plotted accordingly.

176
00:15:37,430 --> 00:15:37,760
Right.

177
00:15:37,760 --> 00:15:43,540
And I said the potential router can be replaced with your own sense of it it doesn't often get attention.

178
00:15:44,300 --> 00:15:45,530
And yes this is it.

179
00:15:46,050 --> 00:15:50,840
And you know it is untouched as in the abstract to go it's the following.

180
00:15:50,850 --> 00:15:51,780
You can take a look at it.

181
00:15:51,800 --> 00:15:55,680
I'm going to upload quality code to the diplomacy.

182
00:15:55,770 --> 00:15:56,570
That's all there is.

183
00:15:56,580 --> 00:15:59,560
You have any questions just let me know and I'll see you later.
