1
00:00:03,250 --> 00:00:12,250
So we'll come back to projects Number two we ended the previous one by right now a lot in it and I'm

2
00:00:12,250 --> 00:00:19,630
very sure about we have a deep understanding about initialization and cheeky I O registers by now.

3
00:00:19,630 --> 00:00:21,270
That is very good show.

4
00:00:21,390 --> 00:00:28,540
And this one we're going to complete the rest of the code and we'll stop by writing The Loop remember

5
00:00:28,540 --> 00:00:32,600
what is going to keep the program running on and on is the loop.

6
00:00:32,890 --> 00:00:41,880
So an assembly as we have meant we write a move by given a label and then branch into that label continuously.

7
00:00:41,920 --> 00:00:42,690
Sure.

8
00:00:43,060 --> 00:00:44,770
Let's just call this move a loop.

9
00:00:44,830 --> 00:00:49,780
The first one what cops and for this loop.

10
00:00:49,780 --> 00:00:58,660
When it starts we want to give some delay and then accept input and then output delay input output so

11
00:00:58,660 --> 00:01:07,330
that we have enough time and we let it delay for about let's say three cycles which is which is equivalent

12
00:01:07,330 --> 00:01:09,970
to the SEC divided by five.

13
00:01:10,090 --> 00:01:19,090
We declared up to two what we're going to do in order to create this delay that's going to load or funnel

14
00:01:19,090 --> 00:01:26,860
you into a register and then form a bit of magic with it no actual magic you know what I mean.

15
00:01:28,270 --> 00:01:37,380
So this was declared so we know this here and then grunge to a subroutine that we would create now called

16
00:01:37,400 --> 00:01:46,640
delay and this subroutine is going to use this funding for us this created a whole lot more.

17
00:01:47,550 --> 00:01:49,090
So this subroutine here

18
00:01:53,560 --> 00:01:59,130
this collector and what it's going to do it is going to use this collection.

19
00:01:59,150 --> 00:02:00,870
Remember we spoke about this.

20
00:02:00,930 --> 00:02:09,200
I know I like going to buy things now again can and again I saw our share one.

21
00:02:09,290 --> 00:02:16,750
So as you can tell the fundamentals of our issue currently when you get here just want to go through

22
00:02:16,750 --> 00:02:17,250
this.

23
00:02:17,260 --> 00:02:23,130
I know it might take time to at this point ask you or has this button.

24
00:02:23,570 --> 00:02:28,820
And then branches here and then it branches to delay subroutine.

25
00:02:28,870 --> 00:02:32,170
Well we aim to subroutine Iris here is still a positive value.

26
00:02:32,210 --> 00:02:38,390
So what we want is to continuously subtract this value from Iris here sort of like it counts down.

27
00:02:39,140 --> 00:02:46,760
And what we're going to how we're going to achieve that is by using the subtraction plus updating the

28
00:02:46,760 --> 00:02:51,670
API so register to do this and then we'll tell it.

29
00:02:52,010 --> 00:02:53,980
And the

30
00:02:58,230 --> 00:03:08,250
and then X are basically the entry delay means callback to delay if it's not required to see your X

31
00:03:08,630 --> 00:03:17,280
LR 5 return.

32
00:03:17,300 --> 00:03:25,040
So this is a countdown basically it's lost to value the value an answer and then subtract one from it

33
00:03:25,070 --> 00:03:33,530
comes in it checks whether the value is equal to zero or not if it's not courtesy of the branches but

34
00:03:33,560 --> 00:03:40,570
to delay which is this and then delay continues and then comes and branches onto it reaches zero.

35
00:03:41,060 --> 00:03:43,520
That's a very nice way of writing a calm down.

36
00:03:44,240 --> 00:03:52,670
So then we return to the function after we've delayed then the next and we'll have to do will be to

37
00:03:52,670 --> 00:03:58,820
take our input and then we do the by production to another subroutine.

38
00:03:58,820 --> 00:04:05,900
It's really good to use subroutines easier to manage and then make understanding there is straightforward.

39
00:04:05,930 --> 00:04:09,040
So we recall under that branch here.

40
00:04:09,430 --> 00:04:19,050
So here we would call the subroutine influence an office name.

41
00:04:19,160 --> 00:04:27,690
And what we're going to do here for the subroutine input is we're going to use the data register.

42
00:04:27,700 --> 00:04:30,150
We're going to compare it to a particular value.

43
00:04:30,190 --> 00:04:34,640
That's how we decide whether an input has been triggered or not.

44
00:04:34,660 --> 00:04:44,110
Remember our switch is a logic mode switch meaning when it's in the low state it's activates and when

45
00:04:44,110 --> 00:04:46,180
it's high it's to activate.

46
00:04:46,690 --> 00:04:51,950
So what is actually going to turn on the end is when the switch goes to zero.

47
00:04:52,180 --> 00:04:55,720
And that is why we connect to the pull up resistor to it.

48
00:04:56,470 --> 00:04:59,830
So what are we going to do is compare this.

49
00:04:59,840 --> 00:05:06,520
We're going to compare the state of the switch to a particular states in order to detect whether it's

50
00:05:06,570 --> 00:05:07,750
compressed or not.

51
00:05:08,260 --> 00:05:19,390
So let's continue let's create a new subroutine called in good and then a pointer to the register LDA

52
00:05:23,060 --> 00:05:38,070
point to GPO Gates a registered GP called data on the school are and then OCR Of course we're going

53
00:05:38,070 --> 00:05:46,680
to perform a bit of manipulation using the logical operations we have to load it into our shoe in order

54
00:05:46,680 --> 00:05:47,390
to get to.

55
00:05:47,490 --> 00:05:50,260
Remember this first line is only pointing to it.

56
00:05:50,370 --> 00:05:54,660
The second line is what built it into the register.

57
00:05:54,660 --> 00:06:02,700
For those of you who were here for the introduction you might remember this show.

58
00:06:02,750 --> 00:06:04,090
So now it's an Irish theater.

59
00:06:04,100 --> 00:06:10,070
And what we want is to use the end operation to check whether it's been pressed or not.

60
00:06:10,810 --> 00:06:15,110
So what I'm going to do here is in one hour show our CEO.

61
00:06:15,680 --> 00:06:24,890
Then I'm going to compare it to this filing what I'm going to do would be to compare it to both switches

62
00:06:25,220 --> 00:06:30,370
and see whether there's a difference in the state currently.

63
00:06:30,650 --> 00:06:36,920
When when did microcontroller it's not activated or when the switch is not pressed.

64
00:06:36,920 --> 00:06:41,000
This is the state meaning this.

65
00:06:41,300 --> 00:06:44,050
Let's break it down to the undefined reform.

66
00:06:44,660 --> 00:06:45,590
What do we have here.

67
00:06:45,590 --> 00:06:55,860
We have we have to assume one and then to assume that one show the switch here is false and it's both.

68
00:06:55,910 --> 00:06:56,820
That's the lowest state.

69
00:06:56,840 --> 00:06:59,740
If we tend this to sue the switch switches high.

70
00:07:00,350 --> 00:07:02,830
That's what switch one if we tend to zero.

71
00:07:02,870 --> 00:07:06,380
This will switch to it's high and it's dormant state.

72
00:07:06,500 --> 00:07:07,520
This is what it is.

73
00:07:07,820 --> 00:07:14,710
So we have to compare this we have this file and see you have to compare this file and see whether there

74
00:07:14,710 --> 00:07:21,170
is a difference and you'll see how that works when the call back up to our main subroutine and we're

75
00:07:21,170 --> 00:07:23,570
going to show how that works.

76
00:07:23,570 --> 00:07:35,200
So once we get our share and then we perform this we can return from the subroutine along with this.

77
00:07:35,330 --> 00:07:46,500
So basically unlike other registers just register here keep the yet changes without Curt rhino aside.

78
00:07:46,540 --> 00:07:53,440
Chris as I progress my switch on the code on the physical board I mean the value of this this register

79
00:07:53,470 --> 00:07:54,220
is changing.

80
00:07:55,150 --> 00:08:02,140
So what we want is at any given time check what is the value of this and perform on end operation with

81
00:08:02,140 --> 00:08:02,890
this.

82
00:08:02,890 --> 00:08:13,870
So let's say I press which one if I press each one button becomes the value of this becomes 2 x 3 0

83
00:08:13,960 --> 00:08:19,240
x 0 1 costs which one this one here becomes you.

84
00:08:19,300 --> 00:08:22,190
And if I press a switch to the five.

85
00:08:23,110 --> 00:08:25,800
Sorry if I press switch to

86
00:08:29,180 --> 00:08:37,050
and if I press 1 2 the value becomes x 1 2 and this has nothing to do with this one.

87
00:08:37,110 --> 00:08:40,860
They change based on code but this one here just changes.

88
00:08:40,930 --> 00:08:43,150
That's why we can perform on end with it.

89
00:08:43,330 --> 00:08:44,770
So we check in.

90
00:08:44,800 --> 00:08:52,660
As the user presses the funding here changes and then it is compared to this an an operation is performed

91
00:08:52,660 --> 00:08:59,370
with this and then it's stored back into our shoe and then we're returned from the subroutine.

92
00:08:59,530 --> 00:09:05,470
So whether it is such one dice price for this value we'll switch to Vice President this finally it is

93
00:09:05,470 --> 00:09:11,860
stored in virus you return to we're going to use this button until the end the microcontroller if it

94
00:09:11,860 --> 00:09:16,090
is this fun turn on this ability or if it's this one you turn on this motor.

95
00:09:16,750 --> 00:09:23,210
So basically that's how this on this input detection works too.

96
00:09:23,450 --> 00:09:24,790
Let's go back up.

97
00:09:25,160 --> 00:09:30,300
And as I said this is where we used to value what we're going to do this.

98
00:09:30,310 --> 00:09:42,610
We're going to use the C and I'm going to use the simple instructions into our singer compared with

99
00:09:45,580 --> 00:09:47,740
2 x 0 1

100
00:09:53,230 --> 00:09:57,990
so we compare the value what about value comes we compare it with this file.

101
00:09:58,000 --> 00:10:03,990
Of course we know this is the value that would be there if switch one is price cost which one becomes

102
00:10:03,990 --> 00:10:05,240
zero.

103
00:10:05,290 --> 00:10:09,800
So we'll compare it and we'll tell it if it's less than 10 and the red and as simple as that.

104
00:10:10,430 --> 00:10:15,240
So CNPC the operation for comparing.

105
00:10:15,550 --> 00:10:27,440
So basically it's saying it's our or equal to zero x 1 and then we use Q the Q S If so branch.

106
00:10:27,580 --> 00:10:37,960
Basically if true branch to a particular subroutine assemblies find a key then we have to create another

107
00:10:37,960 --> 00:10:41,120
subroutine that would deal with it.

108
00:10:41,440 --> 00:10:43,950
If so branch to switch on.

109
00:10:44,610 --> 00:10:48,610
So we compare the value of minus you to X or Y.

110
00:10:48,730 --> 00:10:54,940
If it is the same then branch to this and this is where we're going to trigger our lights to turn on

111
00:10:55,530 --> 00:11:00,740
very nice with drip with broken everything down nice pieces.

112
00:11:00,930 --> 00:11:07,270
So let's just ride this one here and basically what this one is going to do is to keep this code very

113
00:11:07,270 --> 00:11:09,810
firm going to break it down further.

114
00:11:09,860 --> 00:11:11,290
Let's move faster.

115
00:11:11,290 --> 00:11:13,480
Let's move red to our two

116
00:11:17,220 --> 00:11:18,160
you know Red.

117
00:11:18,190 --> 00:11:20,570
Yeah we've already declared red.

118
00:11:20,590 --> 00:11:26,840
We'll get her to exit two and this is for the Red LCD.

119
00:11:27,010 --> 00:11:35,830
This is for P F F one to remove move ahead and then or we have to do is we can create another subroutine

120
00:11:35,830 --> 00:11:42,370
to perform the output so that when we have multiple outputs we can manage it.

121
00:11:42,550 --> 00:11:53,940
And then from this subroutine we can branch to the output for it get this branch to output.

122
00:11:54,040 --> 00:12:00,730
And after that the branch bunch loop you might be wondering first articulate article which is basically

123
00:12:02,010 --> 00:12:05,370
is basically the same as the the switch on.

124
00:12:05,680 --> 00:12:12,770
Yeah the switch on subroutine revealed in the previous projects says that over here.

125
00:12:13,150 --> 00:12:16,140
It's not called the constant value of 1 to 10.

126
00:12:16,180 --> 00:12:23,410
We always have to go through to go it would the files to turn on which means we can create another comparison

127
00:12:23,530 --> 00:12:35,060
and then move loop here to send to outputs anyway this war output looks like the output subroutine.

128
00:12:35,060 --> 00:12:41,840
This what looks like output then or we have to do is load again.

129
00:12:42,290 --> 00:12:46,310
Point to this game to register

130
00:12:50,200 --> 00:12:52,590
story data.

131
00:12:52,980 --> 00:12:53,670
Register

132
00:12:56,820 --> 00:13:02,170
and then distort and funny or shear.

133
00:13:02,360 --> 00:13:10,180
Remember we did not put anything in our 0 0 coins are similar to anything course this filing read our

134
00:13:10,190 --> 00:13:12,940
here as punch to the subroutine.

135
00:13:13,190 --> 00:13:15,320
So it's already contains red.

136
00:13:15,350 --> 00:13:25,250
So the source read story to destination which is this and then the X are returned from this subroutine

137
00:13:26,920 --> 00:13:30,910
and does a good job.

138
00:13:30,910 --> 00:13:39,910
So yes this is our code and always remember we have to make sure it is aligned and we have to end this

139
00:13:39,980 --> 00:13:41,550
in the code.

140
00:13:41,720 --> 00:13:42,310
The time

141
00:13:45,050 --> 00:13:46,100
yes.

142
00:13:46,220 --> 00:13:51,280
So like we did previously the fact.

143
00:13:51,540 --> 00:13:56,130
Yeah well we have to do this great to compile this.

144
00:13:56,130 --> 00:14:06,370
You have two errors or more why you have to come here and go to the reset handler and tell the reset

145
00:14:06,390 --> 00:14:07,120
handler.

146
00:14:07,250 --> 00:14:16,410
What crew bump starts and I'm going to go with her.

147
00:14:16,460 --> 00:14:17,000
There we go.

148
00:14:17,060 --> 00:14:27,330
Michelle handler said yes or worse is called Made in order in order not to always come back here.

149
00:14:27,340 --> 00:14:29,050
You can just name your program.

150
00:14:29,050 --> 00:14:34,180
We can always put this underscore on this call made of this place.

151
00:14:35,490 --> 00:14:40,460
This place as well as this place you can just replace this and use to finally reset.

152
00:14:40,540 --> 00:14:48,920
Handler uses if you don't want to always come and change the name of the starting point you could see

153
00:14:49,230 --> 00:14:50,560
probably have one last.

154
00:14:50,760 --> 00:14:51,660
You have two errors

155
00:14:54,740 --> 00:14:58,590
Okay so it says our RC GC GP bio.

156
00:14:59,230 --> 00:14:59,950
Oh yeah.

157
00:14:59,960 --> 00:15:01,350
Did not talk to them.

158
00:15:01,350 --> 00:15:02,030
Correct.

159
00:15:02,740 --> 00:15:03,340
Yes he

160
00:15:07,320 --> 00:15:12,840
seemed to know what the cause that's what we have now.

161
00:15:14,280 --> 00:15:20,150
Got one more error switch on what defined shit on the front.

162
00:15:20,500 --> 00:15:20,990
Okay.

163
00:15:23,870 --> 00:15:28,350
This user should have more modems.

164
00:15:28,600 --> 00:15:30,540
Okay good work.

165
00:15:31,380 --> 00:15:38,850
Don't forget to add these two lines to the main subroutine the L output and and be loop without these

166
00:15:38,850 --> 00:15:45,360
two lines the loop wouldn't work what you would see would be just a red light on without any interaction

167
00:15:45,360 --> 00:15:46,070
with a button.

168
00:15:47,030 --> 00:15:48,030
Okay.

169
00:15:48,150 --> 00:15:50,910
It looks okay and it looks complete.

170
00:15:51,660 --> 00:15:52,530
Let's see.

171
00:15:52,680 --> 00:15:59,190
Fingers crossed a let's load onto our board for control of okay.

172
00:15:59,580 --> 00:16:00,960
We have to set our board.

173
00:16:01,020 --> 00:16:06,840
Remember our frequency 16 megahertz Bulker.

174
00:16:06,870 --> 00:16:08,860
Is this the lives I see.

175
00:16:08,910 --> 00:16:17,700
I click here to find errors I see.

176
00:16:17,730 --> 00:16:18,800
Okay.

177
00:16:18,850 --> 00:16:23,840
Guess crossed moments and then reset to board.

178
00:16:23,910 --> 00:16:30,010
Then we'll see what do you see okay.

179
00:16:30,050 --> 00:16:31,440
The light stays on.

180
00:16:31,590 --> 00:16:35,620
Yeah okay let's solve that problem now.

181
00:16:35,650 --> 00:16:45,130
There are two things that we need to take into consideration first before the comet and the lock registers

182
00:16:45,250 --> 00:16:52,570
have to occur before the other registers in order to allow the data to be committed.

183
00:16:52,600 --> 00:16:57,130
So let's cut this here and put it right on the clock.

184
00:16:57,130 --> 00:16:59,060
Register activation.

185
00:16:59,140 --> 00:17:08,010
Good one thing you might have found on your own is that over here we are comparing these two values.

186
00:17:08,020 --> 00:17:13,460
This PFC and P F for how ever.

187
00:17:13,540 --> 00:17:20,450
When we come here to our initialization you realize though we did not enable s here.

188
00:17:20,590 --> 00:17:23,560
So how can you use something you've not enabled.

189
00:17:23,560 --> 00:17:31,420
We actually use it in our comparison but it's an invalid value therefore it wouldn't work currently.

190
00:17:31,450 --> 00:17:42,640
What this value here means is it's just 0 0 1 0 0 1 2 but we want this.

191
00:17:42,770 --> 00:17:45,790
So we have to enable this this way.

192
00:17:45,800 --> 00:17:52,850
So now this is enabled and we can perform our comparison properly in order to give us the proper resource

193
00:17:53,630 --> 00:17:59,670
and we don't need to change anything because zero here implies it's already on inputs.

194
00:18:00,020 --> 00:18:09,320
So what we're going to do now for these changes we've done yeah we're going to compile and then download

195
00:18:09,410 --> 00:18:11,150
onto our microcontroller.

196
00:18:11,150 --> 00:18:14,280
And this time it's going to work.

197
00:18:14,300 --> 00:18:21,080
I guarantee you but always keep in mind when you use the incorrect commit to register it should come

198
00:18:21,080 --> 00:18:29,840
before the young the activation or initialization of the other registers and this is trickier to should

199
00:18:29,840 --> 00:18:31,280
be aware.

200
00:18:31,340 --> 00:18:37,660
It's easy to forget and just perform a comparison without enabling this this other pin.

201
00:18:37,730 --> 00:18:39,690
So always be aware.

202
00:18:39,740 --> 00:18:41,290
Let's go forward.

203
00:18:42,970 --> 00:18:53,140
So severe errors as download and then we've done all of or restarts and there we go.

204
00:18:53,160 --> 00:18:54,190
Mine works.

205
00:18:54,330 --> 00:18:55,700
I hope yours works.

206
00:18:55,920 --> 00:18:58,020
And congratulations.

207
00:18:58,020 --> 00:18:59,810
See you in the next project.

208
00:18:59,820 --> 00:19:00,370
Yeah.
