1
00:00:02,700 --> 00:00:03,840
All right.

2
00:00:03,980 --> 00:00:05,170
Welcome.

3
00:00:05,180 --> 00:00:08,070
So let's move on to project number two.

4
00:00:08,270 --> 00:00:14,330
The first project all we did was write a piece of assembly code that tense on the red and indeed on

5
00:00:14,330 --> 00:00:16,570
the launchpad it keeps it on.

6
00:00:16,610 --> 00:00:20,410
That was a bit boring I know but it's a good starting point.

7
00:00:20,450 --> 00:00:24,840
At least now you know how cheap apple works in assembly.

8
00:00:24,840 --> 00:00:31,460
And this one here we're going to add an input pot to this first code and we're going to turn on the

9
00:00:31,460 --> 00:00:33,730
light by pressing a button.

10
00:00:33,960 --> 00:00:36,540
So there will be a bit of interaction there.

11
00:00:36,590 --> 00:00:38,860
So let's get started.

12
00:00:38,900 --> 00:00:42,110
So let's create our new project like we always do.

13
00:00:42,110 --> 00:00:43,150
We come over here.

14
00:00:43,190 --> 00:00:44,710
New York Vision project.

15
00:00:44,960 --> 00:00:45,250
Yes.

16
00:00:45,260 --> 00:00:52,580
I want to save this and create it in this folder create a new folder and keep it in there.

17
00:00:52,610 --> 00:00:56,500
I'll call this red.

18
00:00:56,720 --> 00:00:58,260
I just call it red switch.

19
00:00:58,570 --> 00:01:03,820
Something you can call it what you want to call it this way

20
00:01:07,110 --> 00:01:09,140
then I'll double open.

21
00:01:09,530 --> 00:01:14,680
And then create the name red switch.

22
00:01:14,710 --> 00:01:15,900
It's a strange name

23
00:01:21,110 --> 00:01:23,060
call it red on the school switch

24
00:01:25,640 --> 00:01:28,800
and save her like this.

25
00:01:28,940 --> 00:01:33,930
And our microcontrollers T for C 1 2 3 0 h.

26
00:01:34,670 --> 00:01:37,060
And then it took over her we choose.

27
00:01:37,130 --> 00:01:38,230
Then there we have it.

28
00:01:38,670 --> 00:01:46,310
Then all we have to add over here is the CMC score and then for device we got to start up like this.

29
00:01:46,320 --> 00:01:51,750
And okay we have her we have our target.

30
00:01:51,900 --> 00:02:01,890
So we have to create a new file and then say the US main dot s and click here to expand and then double

31
00:02:01,890 --> 00:02:03,140
click here.

32
00:02:03,490 --> 00:02:05,640
We come here to load our file.

33
00:02:05,730 --> 00:02:09,750
Remember Carrie Lee the file only exists on your desk.

34
00:02:09,750 --> 00:02:12,580
You have to make it part of your project and to do that.

35
00:02:12,660 --> 00:02:16,990
You have to come here and then double click to file to your project.

36
00:02:17,070 --> 00:02:23,970
So in order to make our file visible let's just go to all files and I'll file this man s overhead like

37
00:02:23,970 --> 00:02:24,760
this.

38
00:02:25,020 --> 00:02:28,320
And now it is part of our project and we can find the.

39
00:02:29,040 --> 00:02:31,170
So we're all set.

40
00:02:31,170 --> 00:02:33,010
Let's crack on.

41
00:02:33,030 --> 00:02:41,460
So let's recap from of our previous lesson in our previous lesson we dealt with four registers we dealt

42
00:02:41,460 --> 00:02:47,630
with the clock gains and register which is used by mood in day microcontrollers to save power.

43
00:02:47,670 --> 00:02:52,790
They don't turn on all the hardware to keep the hardware off when you need it.

44
00:02:52,800 --> 00:02:54,530
Then you turn on the clock.

45
00:02:54,660 --> 00:02:56,980
That's the clock gating mechanism basically.

46
00:02:57,000 --> 00:03:01,440
So we use that register and then for our a good part.

47
00:03:01,620 --> 00:03:08,980
We used to keep a data register the GPA or direction register the cheap I O digital enabled register

48
00:03:09,040 --> 00:03:13,030
at these four registers are basic registers to turn on GPA.

49
00:03:13,710 --> 00:03:18,640
But to do something more we would need to unlock the entire port Beth.

50
00:03:18,930 --> 00:03:24,770
So we would have to add three more registers with one key.

51
00:03:24,810 --> 00:03:29,080
So let's continue ok.

52
00:03:29,090 --> 00:03:34,930
These are the registers we started with from our first our first example.

53
00:03:35,030 --> 00:03:37,130
Today we'll be adding four more registers.

54
00:03:37,130 --> 00:03:46,830
We'll be adding the switch the switch on the board as it turns on when the current is low.

55
00:03:47,060 --> 00:03:50,200
So it enables on low.

56
00:03:50,300 --> 00:03:55,610
So because of this we have to connect and pull up resistor to the switch.

57
00:03:56,030 --> 00:03:57,320
We can do this physically.

58
00:03:57,320 --> 00:04:05,910
We can add a resistor to the pin physically using a small circuit but we don't need to do this code.

59
00:04:05,930 --> 00:04:10,790
There is a pull up resistor register and in the microcontroller.

60
00:04:10,790 --> 00:04:13,280
So we just need to enable this register.

61
00:04:13,290 --> 00:04:23,030
Also we have to use the the commit register of port f this the thing some pins on the port F are connected

62
00:04:23,030 --> 00:04:29,510
to the deejay tag which is used for debugging hardware and the NMR.

63
00:04:29,660 --> 00:04:34,110
And these are very very serious important part of the microcontroller.

64
00:04:34,250 --> 00:04:42,110
So some pins are connected to these parts and because of the importance of the microcontroller has locked

65
00:04:42,110 --> 00:04:43,820
down these pins by default.

66
00:04:43,850 --> 00:04:47,890
So that we don't ride to these pins mistakenly.

67
00:04:48,020 --> 00:04:55,280
So if we want to use them we have to enable them and by well I don't mean right into their digital enable

68
00:04:55,280 --> 00:04:55,960
register.

69
00:04:56,060 --> 00:04:58,670
We have to make them comfortable.

70
00:04:58,670 --> 00:05:04,520
This is where the comet register comes in to the to register allows you to be able to commit a value

71
00:05:04,850 --> 00:05:06,790
or data to these registers.

72
00:05:06,830 --> 00:05:12,270
And in order to use that commits register you have to unlock the pot.

73
00:05:12,350 --> 00:05:19,280
So there is another register known as tick pot f lock register and we have to use this register to unlock

74
00:05:19,550 --> 00:05:20,760
the commit register.

75
00:05:20,900 --> 00:05:29,300
So let's crack on in fact rather than go in there and get the error to come declare let's just declare

76
00:05:29,360 --> 00:05:31,430
our register now.

77
00:05:31,460 --> 00:05:44,900
So we have cheap or port F P U R which stands for pull up resistor and we give it a symbolic name.

78
00:05:45,770 --> 00:05:51,090
That's the symbolic name at this this the number of the register.

79
00:05:51,120 --> 00:05:55,860
This the address basically 2 5 5 1 0.

80
00:05:55,860 --> 00:05:59,390
Do not worry you can find this in the data sheet if you want to.

81
00:05:59,400 --> 00:06:01,830
I don't want us to keep going back and forth.

82
00:06:01,830 --> 00:06:04,010
It would print long this video.

83
00:06:04,020 --> 00:06:09,460
So I just went into the data sheets and collected this on your behalf.

84
00:06:09,540 --> 00:06:13,110
So we have this one to get a lock Reg stock.

85
00:06:13,170 --> 00:06:14,220
The one I'm talking about

86
00:06:17,130 --> 00:06:28,020
and this is E Q You 0 x 4 your 2 5 5 2 0.

87
00:06:28,510 --> 00:06:33,500
And then we have the commit register one of our new registers.

88
00:06:33,880 --> 00:06:41,320
If she'd gone on this call here or F C are on a school

89
00:06:44,000 --> 00:06:54,720
in queue you then how she would X of course you 2 5 5 2 4.

90
00:06:54,850 --> 00:06:57,950
And then finally we need to lock key.

91
00:06:57,990 --> 00:07:01,200
If you want to unlock something you definitely need a key.

92
00:07:01,740 --> 00:07:03,360
So let's start a key.

93
00:07:03,360 --> 00:07:05,340
Let's give a symbolic name to that key.

94
00:07:06,210 --> 00:07:15,460
Let's just call it creepy eye or lucky GPO lock key.

95
00:07:16,400 --> 00:07:24,540
And then we give this this the value of that key for C

96
00:07:28,480 --> 00:07:34,830
for F for three for B.

97
00:07:34,860 --> 00:07:43,000
So these are when you registers these will be used in this in our chippy IDE or in it subroutine to

98
00:07:43,000 --> 00:07:48,450
initialize the board and make it ready and we will be it on the red LCD.

99
00:07:48,450 --> 00:07:51,170
So how about we just give it a symbolic name as well.

100
00:07:51,180 --> 00:07:52,190
But I'm going to do this.

101
00:07:52,240 --> 00:07:56,770
I'm going to declare right here symbolic name right.

102
00:07:56,810 --> 00:08:03,900
And you can you add know value to X to remember.

103
00:08:04,150 --> 00:08:07,960
I think I should keep putting this there until you get used to it.

104
00:08:08,750 --> 00:08:14,630
So this work this basically means because red is connected to P. f 1.

105
00:08:14,650 --> 00:08:21,500
So this phase 0 is for PFC row and this P F 1 p.m. 2 p.m. 3 2.

106
00:08:22,240 --> 00:08:29,470
And we would have to delay a bit to make all micro controller responsive and to make it able to read

107
00:08:29,670 --> 00:08:31,690
inputs we press continuously.

108
00:08:32,080 --> 00:08:39,770
We're going to give an approximate value of one fifth of a second based on the frequency of our microcontroller

109
00:08:39,880 --> 00:08:41,260
which is 16 megahertz.

110
00:08:41,530 --> 00:08:45,940
So I'm just going to give this symbolically sick if five.

111
00:08:46,150 --> 00:08:53,780
Which means second divided by 5 and 2 and the value is 1 6.

112
00:08:53,890 --> 00:08:55,720
Once you are sorry.

113
00:08:55,720 --> 00:08:59,340
One two three four five.

114
00:08:59,890 --> 00:09:03,400
And just put a comment here for you.

115
00:09:03,720 --> 00:09:09,850
Second divided by 5 to now.

116
00:09:09,880 --> 00:09:14,450
Yes we've declared all the stuff we need to declare.

117
00:09:14,710 --> 00:09:16,750
Let's get into our assembly.

118
00:09:16,900 --> 00:09:18,170
So let's start.

119
00:09:18,340 --> 00:09:20,390
Start with support directives.

120
00:09:20,770 --> 00:09:22,880
Stop by area.

121
00:09:24,510 --> 00:09:26,000
Space space.

122
00:09:26,100 --> 00:09:34,440
This dot text and this comma and there's the code area number.

123
00:09:35,430 --> 00:09:47,500
And let's make it read only and there's a line line in the codes to in using thumb instruction set and

124
00:09:47,510 --> 00:09:56,610
let's export main again to make it accessible by the dot by the time the dot s file that we saw just

125
00:09:56,610 --> 00:10:08,610
in the previous I don't lesson show we call it man don't come here and declare man.

126
00:10:09,040 --> 00:10:11,370
So just like we do.

127
00:10:11,370 --> 00:10:18,540
Let's break it down let's create a fair subroutine to initialize we call this G P.

128
00:10:18,750 --> 00:10:19,020
OK.

129
00:10:19,040 --> 00:10:20,430
Too much space.

130
00:10:20,580 --> 00:10:22,460
Let's just keep it close.

131
00:10:22,880 --> 00:10:24,620
Cheaply I do.

132
00:10:25,000 --> 00:10:27,960
And then it let's go.

133
00:10:27,960 --> 00:10:34,330
Don't have to initialize of course the contents of to cheap.

134
00:10:34,960 --> 00:10:41,020
I do it.

135
00:10:41,130 --> 00:10:44,930
So first we start really on the clock.

136
00:10:44,970 --> 00:10:57,550
Register healthy the young 1 more then system 1 true.

137
00:10:57,640 --> 00:10:59,310
I'll see you soon.

138
00:11:00,460 --> 00:11:02,550
Keep your eye on the school.

139
00:11:03,550 --> 00:11:17,860
Then slowed our Tier 1 what we want to do we want to turn on the clock for what F which is 0 x to 0.

140
00:11:19,560 --> 00:11:23,970
So we apply to all operator are here.

141
00:11:25,280 --> 00:11:27,590
Don I'm sure you

142
00:11:30,740 --> 00:11:35,250
then no to share

143
00:11:47,900 --> 00:11:49,360
show.

144
00:11:49,630 --> 00:11:51,080
We got this settled.

145
00:11:51,180 --> 00:12:02,160
Well we have to do now this stalled and funding must you know restore stalwart source and then destination.

146
00:12:02,160 --> 00:12:10,920
Remember the difference between skull and mode is to forestall the first apparent is the source and

147
00:12:10,920 --> 00:12:13,720
the second operation is the destination followed.

148
00:12:13,770 --> 00:12:15,620
It's the other way round.

149
00:12:17,190 --> 00:12:18,810
So you've got this one down.

150
00:12:19,560 --> 00:12:31,470
Let's go to the direction register idea I want to go on this call.

151
00:12:31,950 --> 00:12:35,690
If I go on.

152
00:12:35,840 --> 00:12:39,370
So one thing I forgot to mention is ducks.

153
00:12:39,380 --> 00:12:50,210
Which one is connected to a four and switch two is connected to PFC or shall I just write it that it's

154
00:12:50,210 --> 00:12:50,780
a comment

155
00:12:56,290 --> 00:13:08,190
for and then yes then a comma has changed to that I would just like to manipulate ships to.

156
00:13:08,240 --> 00:13:09,170
PFC you

157
00:13:16,380 --> 00:13:16,810
OK.

158
00:13:16,830 --> 00:13:27,840
I'm just competition for her and what for actually implies this in order to enable care for the basically

159
00:13:29,120 --> 00:13:30,830
half to keep us here of course.

160
00:13:30,830 --> 00:13:37,400
Remember when we set in that direction register when we set it too low it means we're telling the microcontroller

161
00:13:37,400 --> 00:13:41,730
to make that particular pin an input pin we'll set it too high.

162
00:13:41,730 --> 00:13:43,860
We're telling it to make it an output pin.

163
00:13:44,220 --> 00:13:53,090
So over here in that direction register it stays the same us to the previous program we wrote goes well

164
00:13:53,090 --> 00:13:54,410
we keep it serious.

165
00:13:54,510 --> 00:13:57,450
We basically telling it to keep it as output.

166
00:13:57,780 --> 00:13:59,980
So we're going to do that.

167
00:13:59,990 --> 00:14:02,470
We're going to use the move goes to value.

168
00:14:02,480 --> 00:14:13,010
We're going to write in it's an 8 bit value and we can use to move a creator of this show to X and then

169
00:14:14,940 --> 00:14:22,360
she wrote to us it implies it's been 0 0 0 0.

170
00:14:23,950 --> 00:14:24,920
Juicier.

171
00:14:25,370 --> 00:14:28,400
Once you show this one here is fine.

172
00:14:28,400 --> 00:14:31,750
Here is what a switch course this is you.

173
00:14:31,820 --> 00:14:33,950
One two three four.

174
00:14:34,790 --> 00:14:44,630
And because it's zero it means finished output and then this tool for store is a source destination

175
00:14:44,900 --> 00:14:47,680
like this shell that's been covered.

176
00:14:48,190 --> 00:14:59,960
The next thing we have to do is to connect a pull up resistor to the switch and we'll use the P R ratio

177
00:14:59,960 --> 00:15:13,100
for this because you can dial F P on a longer school.

178
00:15:14,240 --> 00:15:16,070
And this one too.

179
00:15:16,070 --> 00:15:21,290
It's an 8 bit farther we want to move so we can just move the stage but 12

180
00:15:24,140 --> 00:15:28,060
that into our shoe and what we want.

181
00:15:28,980 --> 00:15:42,230
It's this guy her show this rather easy just have 2 1 2 2 x 1 share then I'll just pour alcohol for

182
00:15:42,230 --> 00:15:43,160
you.

183
00:15:43,160 --> 00:15:56,100
What this means is 0 0 1 0 0 0 2 so we know this is part 4 and then was unable to pull up retches pull

184
00:15:56,100 --> 00:16:05,520
up resistor here for remember this it resists that not a register is a normal resistor so restore it

185
00:16:05,820 --> 00:16:11,770
ness and restore by source are zero discrimination.

186
00:16:11,830 --> 00:16:22,190
1 so that's been covered the next step is to call to the pool at which to enable register let's do the

187
00:16:24,880 --> 00:16:39,010
TR 1 because you can go for f a thing always right in the image function takes quite a lot of time for

188
00:16:39,010 --> 00:16:39,770
the video.

189
00:16:39,970 --> 00:16:46,090
So in the next project that we'll be doing they're going to be relatively long project show what we

190
00:16:46,090 --> 00:16:52,240
will be doing is we're wedding type out the the inmates function together I'll just take it out once.

191
00:16:52,250 --> 00:16:54,700
Now you go through and then we continue from there.

192
00:16:54,700 --> 00:16:58,470
That would save us quite a lot of time for these two projects.

193
00:16:58,480 --> 00:17:01,330
It's very good that we do it together.

194
00:17:02,320 --> 00:17:06,540
So they serve and what we need is another age but.

195
00:17:06,700 --> 00:17:11,560
We want to move to our share and what we want to enable.

196
00:17:11,560 --> 00:17:17,130
We want to enable P F we want to enable people for the switch.

197
00:17:17,140 --> 00:17:18,050
We want to enable.

198
00:17:18,120 --> 00:17:22,460
If one who be for the end to do so.

199
00:17:23,030 --> 00:17:34,950
As you can guess except we accept hexadecimal 8 but you the one to look at this and could put the help

200
00:17:34,950 --> 00:17:37,470
I have for you.

201
00:17:37,840 --> 00:17:38,770
What would this be.

202
00:17:38,770 --> 00:17:44,010
This is ISSUE 1 seriously

203
00:17:46,970 --> 00:17:49,200
2 2 1 0.

204
00:17:49,330 --> 00:17:55,220
So that's what this implies and then restore it skull.

205
00:17:55,930 --> 00:17:57,530
Source register answer.

206
00:17:57,610 --> 00:17:59,440
Destination major stop 1.

207
00:17:59,690 --> 00:18:06,810
So now we have to use all we have to access to more Redish this we have to unlock it and then allow

208
00:18:06,820 --> 00:18:07,790
comment.

209
00:18:08,020 --> 00:18:10,030
She could do LTI.

210
00:18:10,210 --> 00:18:14,380
I want cheaply I F

211
00:18:17,720 --> 00:18:19,670
block on the school.

212
00:18:21,540 --> 00:18:28,110
Then and then since we don't need to perform any form of computation or manipulation we just want to

213
00:18:28,560 --> 00:18:31,830
take something from one register and put it into another one.

214
00:18:32,130 --> 00:18:35,930
You can just note this one into another register like this.

215
00:18:36,060 --> 00:18:38,370
And what do we call it.

216
00:18:38,370 --> 00:18:39,510
Recorded it cheaply.

217
00:18:39,520 --> 00:18:42,360
I'll lock both you or something.

218
00:18:44,060 --> 00:18:48,090
Let's see what name you gave it to right here to call you.

219
00:18:48,090 --> 00:18:51,120
Lock key so.

220
00:18:51,330 --> 00:18:53,640
This is a 32 bit value.

221
00:18:53,670 --> 00:18:55,850
That's where we use the LTE.

222
00:18:56,550 --> 00:19:05,940
We cannot use move for this move wouldn't work so we just load below the register in R1 and then load

223
00:19:05,940 --> 00:19:19,920
a key in our here and score and as we know you are one now with one locked in the last in the last register

224
00:19:19,920 --> 00:19:22,730
for it and it is still that cheaply.

225
00:19:22,730 --> 00:19:38,500
I will commit register and then do that by this GP I'll put on a school C and then.

226
00:19:39,270 --> 00:19:50,450
And what we want to do is to unlock say some 8 bit value into that value we will use in her father year

227
00:19:50,590 --> 00:19:51,600
school X

228
00:19:55,320 --> 00:19:58,090
and B.

229
00:19:58,260 --> 00:19:59,670
Basically what this means is

230
00:20:03,190 --> 00:20:05,220
it can say.

231
00:20:05,310 --> 00:20:17,020
Then finally restore the source and destination then a initialization is complete.

232
00:20:17,020 --> 00:20:26,220
What we want is to return from the subroutine using the x x and then return.

233
00:20:26,240 --> 00:20:29,660
So this particular video is getting quite too long.

234
00:20:29,800 --> 00:20:36,610
So we're going to end here and continuing the next video with the rest of the on the assembly code.

235
00:20:36,670 --> 00:20:37,500
Good work.

236
00:20:37,510 --> 00:20:38,070
See you.
