1
00:00:00,180 --> 00:00:00,670
Hello.

2
00:00:00,720 --> 00:00:01,170
Welcome back.

3
00:00:01,530 --> 00:00:08,700
So in this lesson like we said we are going to implement a war stick delay subroutines so I'm gonna

4
00:00:08,820 --> 00:00:12,290
create a function here called cystic weight.

5
00:00:12,780 --> 00:00:16,570
I'm given the word function and subroutine here interchangeably.

6
00:00:16,590 --> 00:00:25,680
Yeah it's called the cystic weight and first of all we um we go to the reload value.

7
00:00:28,470 --> 00:00:35,070
Um so what is going to happen is we going to subtract one from the content of the reload register.

8
00:00:35,070 --> 00:00:41,070
So we push we put our rate node value into our cystic reload register this a reload value we put into

9
00:00:41,070 --> 00:00:47,320
the reload register and we would keep subtracting one from this value until it reaches zero.

10
00:00:47,340 --> 00:00:49,350
That is where what time out would okay.

11
00:00:49,590 --> 00:00:52,740
And a unit here is Andy the clock cycles.

12
00:00:52,750 --> 00:00:55,310
And what I mean by this is um.

13
00:00:55,410 --> 00:00:56,430
Because we.

14
00:00:56,610 --> 00:00:56,820
Yeah.

15
00:00:58,820 --> 00:00:59,440
Okay.

16
00:00:59,460 --> 00:01:06,990
What I mean by clock psychosis my microcontroller its default clock frequency is 16 megahertz.

17
00:01:06,990 --> 00:01:12,790
And what this means is 16 million cycles.

18
00:01:13,950 --> 00:01:14,370
Okay.

19
00:01:14,370 --> 00:01:16,200
In one second.

20
00:01:16,200 --> 00:01:20,610
So it's execute 16 million cycles in one second.

21
00:01:20,620 --> 00:01:28,200
Does the meaning of 16 mega hit it simple to remember 80 megahertz means 80 million cycles executed

22
00:01:28,380 --> 00:01:35,450
in a single seconds it's like 80 million hits mega means million.

23
00:01:35,480 --> 00:01:39,110
So 80 mega hit equals 80 million hits.

24
00:01:39,500 --> 00:01:43,320
And this means 80 million cycles in a second.

25
00:01:43,340 --> 00:01:46,790
So my default frequency is 16 megahertz.

26
00:01:46,790 --> 00:01:54,370
In other words 16 million Hertz meaning 16 million psychos executed in a single second.

27
00:01:54,410 --> 00:02:00,470
So if we know 16 million cycles are executed in a single second.

28
00:02:00,470 --> 00:02:04,410
Then how long does it take to execute a single cycle.

29
00:02:04,430 --> 00:02:08,110
And this value is sixty two point five nanoseconds.

30
00:02:08,690 --> 00:02:15,090
So the unit here is sixty two point five nanoseconds which is equal to one cycle for this hour cystic

31
00:02:15,110 --> 00:02:17,750
wait subroutine that we right over here.

32
00:02:17,750 --> 00:02:20,050
So we're going to pass this argument.

33
00:02:20,210 --> 00:02:25,860
How how many cycles we want to delay for we're going to pass this argument to register our issue.

34
00:02:25,940 --> 00:02:33,050
So if I pass five I want to delay for five cycles which essentially equals five multiplied by sixty

35
00:02:33,050 --> 00:02:35,110
two point five nanoseconds.

36
00:02:35,150 --> 00:02:43,130
But yeah we would later only see how to have our delays in you know seconds in units such as seconds

37
00:02:43,220 --> 00:02:44,540
or milliseconds.

38
00:02:44,540 --> 00:02:47,150
So the argument is gonna pass into rage the RS zero.

39
00:02:47,180 --> 00:02:52,910
So by the time we get to the subroutine we are assuming we already have our zero which are what DeLay

40
00:02:52,910 --> 00:02:53,880
amount.

41
00:02:53,930 --> 00:03:01,720
What I'm gonna do now is get into the value that is in the system load or the system reload register

42
00:03:02,180 --> 00:03:08,330
so to invoke s t reload underscore Ah over here

43
00:03:15,190 --> 00:03:26,490
and then I'm simply going to subtract one or two sub one from our zero hour zero.

44
00:03:26,560 --> 00:03:34,270
So what DeLay amount and then I'm going to start a new value after I perform the subtraction what is

45
00:03:34,270 --> 00:03:39,400
left I'm going to store it.

46
00:03:39,400 --> 00:03:45,840
So after I perform this subtraction I'm going to start a resort in the reload register by using the

47
00:03:45,840 --> 00:03:49,720
store instruction and then our zero hour one over here.

48
00:03:52,250 --> 00:03:52,540
Okay.

49
00:03:52,540 --> 00:03:57,220
So once that is done I'm gonna do load R 1

50
00:04:00,030 --> 00:04:07,960
because and fake cystic control register underscore Ah right.

51
00:04:08,210 --> 00:04:11,860
And what I'm gonna do next is load.

52
00:04:11,860 --> 00:04:13,500
I'll use a different register.

53
00:04:13,970 --> 00:04:27,000
Our three are one over here and then I'm going to check whether our count flag is set or 2 and s and

54
00:04:27,580 --> 00:04:36,080
then are 3 0 3 0 3 or 3 and then we created a symbolic name for the count.

55
00:04:36,700 --> 00:04:45,970
This one here to perform on an operation of the content of our three course um off the content of our

56
00:04:45,970 --> 00:04:46,360
three.

57
00:04:47,480 --> 00:04:52,670
There's a mistake here of the contents of our three with the count flag.

58
00:04:52,780 --> 00:04:58,270
Remember our three would have what is located in the register.

59
00:04:58,270 --> 00:05:03,910
This is the control register we've put in our three and we're doing what is in our three and it on end

60
00:05:03,970 --> 00:05:08,800
operation and then we start a resort back into R3 I'm using three options here is the same as using

61
00:05:08,800 --> 00:05:10,240
two appearance it's fine.

62
00:05:10,270 --> 00:05:12,040
It should work the same way.

63
00:05:12,310 --> 00:05:14,110
Right.

64
00:05:14,110 --> 00:05:18,250
Once that is done we want to check if the count flag is set.

65
00:05:18,250 --> 00:05:25,910
If it is not set we'll branch to lessee or create a loop RC LP one here.

66
00:05:26,050 --> 00:05:29,180
We keep checking if they can't flag is no set.

67
00:05:29,440 --> 00:05:31,160
Come over here.

68
00:05:31,450 --> 00:05:31,780
Right.

69
00:05:32,050 --> 00:05:37,080
And the reason we are using b q is when we perform the N operation we append it s over here.

70
00:05:37,120 --> 00:05:48,340
Whenever you see me or whenever you see on instructions such as move s or sub S O at s in fact whenever

71
00:05:48,340 --> 00:05:54,280
you see an instruction which s it means you want to update the AP s r registers when you perform that

72
00:05:54,280 --> 00:06:01,000
particular instruction and the EPA s registered s um the you want to update the AP flags.

73
00:06:01,690 --> 00:06:08,350
Yes some flags in the AP s I registered I get updated based on the results of a particular um execution.

74
00:06:08,560 --> 00:06:09,970
So we have the Zero flag.

75
00:06:10,000 --> 00:06:14,130
We have the overflow flag we have the carry flag we up the negative flag.

76
00:06:14,230 --> 00:06:19,270
This shows you um that the last operation that you performed returned a negative value that last we

77
00:06:19,260 --> 00:06:21,460
appreciate that you performed a return to zero.

78
00:06:22,540 --> 00:06:28,990
So that is why we appended it here so it just checks whether after our subtraction the um the answer

79
00:06:28,990 --> 00:06:29,950
is zero.

80
00:06:29,950 --> 00:06:33,460
If it is not we come back to the top over here.

81
00:06:35,560 --> 00:06:37,330
Um this checks.

82
00:06:37,360 --> 00:06:37,950
Um what uh.

83
00:06:37,980 --> 00:06:44,240
After our N operation I should say course with the form and an and over here.

84
00:06:44,590 --> 00:06:49,810
So we keep returning to the top here until the flag is set right.

85
00:06:49,810 --> 00:06:51,860
The current flag is set.

86
00:06:52,240 --> 00:06:52,910
Okay.

87
00:06:52,960 --> 00:07:00,940
So once that is done we can return from the subroutine bookseller like this.

88
00:07:01,510 --> 00:07:01,810
Okay.

89
00:07:01,840 --> 00:07:04,000
So this is our a cystic wait subroutine.

90
00:07:04,000 --> 00:07:11,130
No we gonna create another the subroutine to um to um to allow us to be able to delay in this a milliseconds.

91
00:07:11,140 --> 00:07:19,210
We going to create 10 milliseconds delay such that we gonna make such that when you call the subroutine

92
00:07:19,270 --> 00:07:24,320
it's gonna delay for 10 millisecond if you pass on documents of one and if you pass on arguments of

93
00:07:24,340 --> 00:07:30,880
hundred it's going to delay hundred multiply by ten EMIs which is equal to one second something of that

94
00:07:30,880 --> 00:07:32,660
nature.

95
00:07:32,980 --> 00:07:45,530
So I'm gonna come over here to create a new subroutine call this I call this mistake wait 10 EMIs and

96
00:07:45,530 --> 00:07:47,560
then I'm gonna take the argument.

97
00:07:47,600 --> 00:07:50,090
So we're going to pass our dollar amount into register.

98
00:07:50,130 --> 00:07:53,900
Iris 0 so I'm gonna move it from our 4 0.

99
00:07:53,910 --> 00:07:57,020
I'm gonna move it into our four or do move s..

100
00:07:57,500 --> 00:08:03,200
And as you can see I've added as to this operation because I need the EPA as our flux to update on this

101
00:08:03,990 --> 00:08:04,710
move.

102
00:08:04,760 --> 00:08:07,290
What is in our zero into our four.

103
00:08:07,550 --> 00:08:18,590
And I'm going to say BQ if if after this operation if if the um if the argument is zero then branch

104
00:08:18,590 --> 00:08:20,640
to a place that I'm going to name.

105
00:08:20,740 --> 00:08:21,490
Done.

106
00:08:21,520 --> 00:08:23,690
Meaning if you pass zero for the dollar amount.

107
00:08:23,720 --> 00:08:28,430
There is no need to execute anything the subroutine should simply return.

108
00:08:28,430 --> 00:08:30,870
So I'm gonna put a label here underscore underscore.

109
00:08:30,890 --> 00:08:31,830
Done.

110
00:08:32,300 --> 00:08:43,240
And this simply going to return from the subroutine be set low so low over here right.

111
00:08:43,260 --> 00:08:44,410
Okay.

112
00:08:44,710 --> 00:08:50,080
So if this is not a case then I'm going to um I'm gonna perform the actual delay

113
00:08:53,020 --> 00:08:56,920
so I'm gonna create uh constants somewhere.

114
00:08:59,080 --> 00:09:05,400
Um I'll put it up here or create delay.

115
00:09:07,000 --> 00:09:09,900
Let's see 10.

116
00:09:11,050 --> 00:09:12,550
Call this 10 image delay.

117
00:09:12,550 --> 00:09:13,200
How about this.

118
00:09:14,740 --> 00:09:19,060
And then I'm gonna assign the number this is based on my clock frequency.

119
00:09:19,170 --> 00:09:19,690
You call you.

120
00:09:19,690 --> 00:09:21,820
I'm gonna give 160 thousand

121
00:09:25,190 --> 00:09:28,610
I'm gonna give 160 thousand.

122
00:09:28,610 --> 00:09:28,990
Right.

123
00:09:29,150 --> 00:09:33,240
So that's the explanation for the one sixty thousand we have here.

124
00:09:33,500 --> 00:09:34,150
Right.

125
00:09:34,160 --> 00:09:43,010
Like I mentioned earlier 16 million equals one hurts my microcontroller is running at sixteen megahertz

126
00:09:43,070 --> 00:09:50,810
meaning sixteen million cycles in a second and in another way of expressing this as 16 million equals

127
00:09:50,810 --> 00:09:57,420
one hertz and we know a thousand milliseconds equals one hertz as well.

128
00:09:58,100 --> 00:10:00,740
Then we want to create 10 seconds we want to find.

129
00:10:00,740 --> 00:10:05,110
How many how many cycles do we get with 10 milliseconds then.

130
00:10:05,120 --> 00:10:07,850
Cause we say we create in 10 milliseconds.

131
00:10:08,030 --> 00:10:16,400
Well for 10 we do want 10 divided by 1000 10 milliseconds divided by 1000 milliseconds times 1 hertz

132
00:10:16,700 --> 00:10:26,910
which equals one over 100 to see how many psychos we get for one over 100 heads.

133
00:10:27,020 --> 00:10:30,010
We simply more to play one over one hundred times.

134
00:10:30,020 --> 00:10:36,760
I was 16 million or sixty million cycles which is equal to one hertz and then we get one sixty thousand

135
00:10:36,980 --> 00:10:44,300
to this um this perhaps I don't know if any of you could explain this in a simpler way but yeah I'm

136
00:10:44,300 --> 00:10:49,730
sure there are simple explanations out there and then you can share it in the comment area if you can

137
00:10:49,730 --> 00:10:52,140
explain this to your fellow students in a simpler way.

138
00:10:52,160 --> 00:11:01,050
So basically um 16 million cycles of course one hertz and this equals one hundred m is it.

139
00:11:01,170 --> 00:11:08,690
Uh this was a thousand M S so then the question is we want a hundred m s equivalent in psychos.

140
00:11:08,810 --> 00:11:16,220
And one could say you are you can't so two zeros here you can't so two zeros here you are left with

141
00:11:16,270 --> 00:11:22,470
160 thousand cycles has the this constant is 160 thousand right.

142
00:11:22,620 --> 00:11:22,980
You know what.

143
00:11:22,980 --> 00:11:23,950
Continuing.

144
00:11:24,170 --> 00:11:24,470
Right.

145
00:11:24,470 --> 00:11:25,930
So we've created a constant.

146
00:11:26,060 --> 00:11:29,110
Let's continue to create a 10 m s delay.

147
00:11:29,970 --> 00:11:38,390
Um so we said f 0 is past this argument the D subroutine is going to return if that's not the case then

148
00:11:38,390 --> 00:11:44,510
we're going to subtract we're gonna subtract something from a while constant or delay amounts when a

149
00:11:44,510 --> 00:11:46,970
load or what delay amounts here.

150
00:11:50,110 --> 00:11:51,920
I'm going to load.

151
00:11:52,090 --> 00:12:03,730
I'm going to use RC reload r 0 with our delay amount which is this our 10 m s and then I'm gonna call

152
00:12:03,730 --> 00:12:04,720
our cystic wait

153
00:12:09,470 --> 00:12:14,250
be a cystic reach over here.

154
00:12:15,270 --> 00:12:15,710
Right.

155
00:12:15,720 --> 00:12:22,440
And then once cystic weight has done it s thin once you know it's returned I'm going to subtract one

156
00:12:22,440 --> 00:12:32,670
from our daily amount by doing the sub as sub subs as UBS and then remember our phone still has a copy

157
00:12:32,670 --> 00:12:33,500
of the argument.

158
00:12:33,510 --> 00:12:39,060
What the uh the argument we passed cause the argument is are it's a no show but we copied it into our

159
00:12:39,060 --> 00:12:39,570
four.

160
00:12:39,610 --> 00:12:41,220
So we still have the original argument.

161
00:12:41,210 --> 00:12:42,050
Yeah we reused.

162
00:12:42,060 --> 00:12:49,080
We used our sue later on for our 10 m s constant so our 4 has the argument we passed initially.

163
00:12:49,100 --> 00:12:49,820
No.

164
00:12:49,890 --> 00:12:55,890
So we say our four our four minus one.

165
00:12:55,890 --> 00:13:03,080
And then we are going to subtract one and if we subtract and it s not equal to zero.

166
00:13:03,090 --> 00:13:06,250
If the result is not zero we are going to branch.

167
00:13:06,290 --> 00:13:09,900
If it's higher we're going to branch.

168
00:13:09,930 --> 00:13:15,600
If the resorts in our fall is higher than zero I'm gonna use P H I instruction here and then I'm gonna

169
00:13:15,720 --> 00:13:20,610
branch to the spot LP 2 and I'm going to put LP 2 here.

170
00:13:20,610 --> 00:13:22,410
Right.

171
00:13:22,620 --> 00:13:24,440
So this is it.

172
00:13:25,290 --> 00:13:26,510
I think yeah it looks good.

173
00:13:26,520 --> 00:13:26,880
No.

174
00:13:29,370 --> 00:13:30,000
Okay.

175
00:13:30,060 --> 00:13:36,000
So we can a line and and there s the loss of 15

176
00:13:40,430 --> 00:13:40,930
right.

177
00:13:42,870 --> 00:13:43,420
Okay.

178
00:13:43,840 --> 00:13:44,120
Okay.

179
00:13:44,140 --> 00:13:47,490
So now let's test our program.

180
00:13:47,500 --> 00:13:56,070
I'm gonna create two new subroutines here for LGB on an LCD of when I have a lady own.

181
00:13:56,560 --> 00:13:59,310
And this is simply going to turn on the red LCD.

182
00:13:59,860 --> 00:14:08,260
I'm gonna do load R one and then GPL you f data register

183
00:14:11,600 --> 00:14:13,570
and then move into our 0

184
00:14:16,840 --> 00:14:29,830
the lady read and then store our as you are 1 and then be SLR return from subroutine.

185
00:14:29,840 --> 00:14:33,820
Now we're gonna have a lady of

186
00:14:37,900 --> 00:14:41,710
and then this is implemented the same way.

187
00:14:41,710 --> 00:14:55,750
Load our 1 GPL you f data register move into our 0 this time read off

188
00:14:59,740 --> 00:15:06,360
and then store our 0 are 1 and then be slr.

189
00:15:10,070 --> 00:15:10,430
Okay.

190
00:15:10,730 --> 00:15:13,010
So now in our main loop over here

191
00:15:16,520 --> 00:15:22,770
um we can um we can test out our code.

192
00:15:23,120 --> 00:15:25,610
I'm gonna come over here and load our 0

193
00:15:28,480 --> 00:15:33,650
A C or load our show across our storage the register.

194
00:15:33,670 --> 00:15:36,240
Doc likes the arguments of our subroutine.

195
00:15:36,240 --> 00:15:37,880
I'm going to load it with the number.

196
00:15:38,630 --> 00:15:47,250
But this one hundred and then I'm gonna do a two hour wait 10 m s

197
00:15:51,880 --> 00:16:04,480
and then I'm gonna call the lady on bill on a score a lady on and then I'm gonna load our issue again

198
00:16:06,360 --> 00:16:12,820
with one hundred so one hundred multiply by ten m s of course a thousand m s of course one second and

199
00:16:12,820 --> 00:16:13,780
I'm going to be able

200
00:16:17,320 --> 00:16:29,830
to wait to m s and then be L and a score early d off right and I'm going to keep this in a loop and

201
00:16:29,830 --> 00:16:31,960
I'll put a loop here.

202
00:16:32,530 --> 00:16:33,200
Right.

203
00:16:33,250 --> 00:16:35,920
We're looking good.

204
00:16:35,920 --> 00:16:42,230
Okay so we can try out all code see what we have.

205
00:16:42,330 --> 00:16:44,620
Gonna click here to build

206
00:16:47,780 --> 00:16:50,590
this picture that Roy says but register symbol

207
00:17:09,410 --> 00:17:11,240
probably have a partridge somewhere.

208
00:17:15,240 --> 00:17:18,690
Okay this first type will we get to build

209
00:17:23,790 --> 00:17:24,990
look at that.

210
00:17:25,160 --> 00:17:29,910
I was supposed to write a line that I ended up typing and

211
00:17:35,090 --> 00:17:39,880
Turbo the Okay we've got two more.

212
00:17:41,040 --> 00:17:41,470
So.

213
00:17:41,480 --> 00:17:41,820
Whoa.

214
00:17:43,710 --> 00:17:44,370
Yeah.

215
00:17:44,410 --> 00:17:45,950
They shall use using the load.

216
00:17:45,960 --> 00:17:47,650
You don't use this.

217
00:17:47,760 --> 00:17:49,860
This is how to load.

218
00:17:49,860 --> 00:17:50,850
We could have done move.

219
00:17:53,280 --> 00:17:56,980
Okay so there's a typo with regards to this.

220
00:17:57,300 --> 00:18:01,210
And Vic is the current register are over here.

221
00:18:04,750 --> 00:18:15,070
Okay let's set our target options debugger I'm using these the libraries I CDI come over here reset

222
00:18:15,070 --> 00:18:15,550
and run.

223
00:18:15,790 --> 00:18:16,380
Okay.

224
00:18:16,380 --> 00:18:16,680
And then.

225
00:18:16,750 --> 00:18:17,200
Okay.

226
00:18:20,380 --> 00:18:28,480
So I'm gonna quicker to download onto my board to download in my early days.

227
00:18:28,480 --> 00:18:29,140
Not Blinken.

228
00:18:29,350 --> 00:18:32,290
Let's see.

229
00:18:32,440 --> 00:18:33,910
Right.

230
00:18:34,240 --> 00:18:34,630
Right.

231
00:18:34,630 --> 00:18:39,460
The reason we have in this issue is we need to push.

232
00:18:39,610 --> 00:18:43,150
Register our 4 and L 4 We need to save them.

233
00:18:44,360 --> 00:18:46,870
Um yeah.

234
00:18:48,030 --> 00:18:49,210
I'm gonna push

235
00:18:58,090 --> 00:19:00,530
our file and a link register

236
00:19:05,150 --> 00:19:09,600
and then before I return from the subroutine I'm gonna pop them pop

237
00:19:12,500 --> 00:19:15,590
R for and then the link register.

238
00:19:16,500 --> 00:19:22,640
Okay let's build and see if this solves so what is you gonna click here to build.

239
00:19:28,170 --> 00:19:31,020
I'm going to click here to download onto the board.

240
00:19:31,510 --> 00:19:34,160
S can see my LCD is blinking.

241
00:19:34,290 --> 00:19:36,260
So this brings us to the end of this lesson.

242
00:19:36,260 --> 00:19:39,780
If you have any questions at all just let me know and I'll see you later.

243
00:19:39,780 --> 00:19:40,570
Have a nice day.
