All right.
Welcome.
So let's move on to project number two.
The first project all we did was write a piece of assembly code that tense on the red and indeed on
the launchpad it keeps it on.
That was a bit boring I know but it's a good starting point.
At least now you know how cheap apple works in assembly.
And this one here we're going to add an input pot to this first code and we're going to turn on the
light by pressing a button.
So there will be a bit of interaction there.
So let's get started.
So let's create our new project like we always do.
We come over here.
New York Vision project.
Yes.
I want to save this and create it in this folder create a new folder and keep it in there.
I'll call this red.
I just call it red switch.
Something you can call it what you want to call it this way
then I'll double open.
And then create the name red switch.
It's a strange name
call it red on the school switch
and save her like this.
And our microcontrollers T for C 1 2 3 0 h.
And then it took over her we choose.
Then there we have it.
Then all we have to add over here is the CMC score and then for device we got to start up like this.
And okay we have her we have our target.
So we have to create a new file and then say the US main dot s and click here to expand and then double
click here.
We come here to load our file.
Remember Carrie Lee the file only exists on your desk.
You have to make it part of your project and to do that.
You have to come here and then double click to file to your project.
So in order to make our file visible let's just go to all files and I'll file this man s overhead like
this.
And now it is part of our project and we can find the.
So we're all set.
Let's crack on.
So let's recap from of our previous lesson in our previous lesson we dealt with four registers we dealt
with the clock gains and register which is used by mood in day microcontrollers to save power.
They don't turn on all the hardware to keep the hardware off when you need it.
Then you turn on the clock.
That's the clock gating mechanism basically.
So we use that register and then for our a good part.
We used to keep a data register the GPA or direction register the cheap I O digital enabled register
at these four registers are basic registers to turn on GPA.
But to do something more we would need to unlock the entire port Beth.
So we would have to add three more registers with one key.
So let's continue ok.
These are the registers we started with from our first our first example.
Today we'll be adding four more registers.
We'll be adding the switch the switch on the board as it turns on when the current is low.
So it enables on low.
So because of this we have to connect and pull up resistor to the switch.
We can do this physically.
We can add a resistor to the pin physically using a small circuit but we don't need to do this code.
There is a pull up resistor register and in the microcontroller.
So we just need to enable this register.
Also we have to use the the commit register of port f this the thing some pins on the port F are connected
to the deejay tag which is used for debugging hardware and the NMR.
And these are very very serious important part of the microcontroller.
So some pins are connected to these parts and because of the importance of the microcontroller has locked
down these pins by default.
So that we don't ride to these pins mistakenly.
So if we want to use them we have to enable them and by well I don't mean right into their digital enable
register.
We have to make them comfortable.
This is where the comet register comes in to the to register allows you to be able to commit a value
or data to these registers.
And in order to use that commits register you have to unlock the pot.
So there is another register known as tick pot f lock register and we have to use this register to unlock
the commit register.
So let's crack on in fact rather than go in there and get the error to come declare let's just declare
our register now.
So we have cheap or port F P U R which stands for pull up resistor and we give it a symbolic name.
That's the symbolic name at this this the number of the register.
This the address basically 2 5 5 1 0.
Do not worry you can find this in the data sheet if you want to.
I don't want us to keep going back and forth.
It would print long this video.
So I just went into the data sheets and collected this on your behalf.
So we have this one to get a lock Reg stock.
The one I'm talking about
and this is E Q You 0 x 4 your 2 5 5 2 0.
And then we have the commit register one of our new registers.
If she'd gone on this call here or F C are on a school
in queue you then how she would X of course you 2 5 5 2 4.
And then finally we need to lock key.
If you want to unlock something you definitely need a key.
So let's start a key.
Let's give a symbolic name to that key.
Let's just call it creepy eye or lucky GPO lock key.
And then we give this this the value of that key for C
for F for three for B.
So these are when you registers these will be used in this in our chippy IDE or in it subroutine to
initialize the board and make it ready and we will be it on the red LCD.
So how about we just give it a symbolic name as well.
But I'm going to do this.
I'm going to declare right here symbolic name right.
And you can you add know value to X to remember.
I think I should keep putting this there until you get used to it.
So this work this basically means because red is connected to P. f 1.
So this phase 0 is for PFC row and this P F 1 p.m. 2 p.m. 3 2.
And we would have to delay a bit to make all micro controller responsive and to make it able to read
inputs we press continuously.
We're going to give an approximate value of one fifth of a second based on the frequency of our microcontroller
which is 16 megahertz.
So I'm just going to give this symbolically sick if five.
Which means second divided by 5 and 2 and the value is 1 6.
Once you are sorry.
One two three four five.
And just put a comment here for you.
Second divided by 5 to now.
Yes we've declared all the stuff we need to declare.
Let's get into our assembly.
So let's start.
Start with support directives.
Stop by area.
Space space.
This dot text and this comma and there's the code area number.
And let's make it read only and there's a line line in the codes to in using thumb instruction set and
let's export main again to make it accessible by the dot by the time the dot s file that we saw just
in the previous I don't lesson show we call it man don't come here and declare man.
So just like we do.
Let's break it down let's create a fair subroutine to initialize we call this G P.
OK.
Too much space.
Let's just keep it close.
Cheaply I do.
And then it let's go.
Don't have to initialize of course the contents of to cheap.
I do it.
So first we start really on the clock.
Register healthy the young 1 more then system 1 true.
I'll see you soon.
Keep your eye on the school.
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.
So we apply to all operator are here.
Don I'm sure you
then no to share
show.
We got this settled.
Well we have to do now this stalled and funding must you know restore stalwart source and then destination.
Remember the difference between skull and mode is to forestall the first apparent is the source and
the second operation is the destination followed.
It's the other way round.
So you've got this one down.
Let's go to the direction register idea I want to go on this call.
If I go on.
So one thing I forgot to mention is ducks.
Which one is connected to a four and switch two is connected to PFC or shall I just write it that it's
a comment
for and then yes then a comma has changed to that I would just like to manipulate ships to.
PFC you
OK.
I'm just competition for her and what for actually implies this in order to enable care for the basically
half to keep us here of course.
Remember when we set in that direction register when we set it too low it means we're telling the microcontroller
to make that particular pin an input pin we'll set it too high.
We're telling it to make it an output pin.
So over here in that direction register it stays the same us to the previous program we wrote goes well
we keep it serious.
We basically telling it to keep it as output.
So we're going to do that.
We're going to use the move goes to value.
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
she wrote to us it implies it's been 0 0 0 0.
Juicier.
Once you show this one here is fine.
Here is what a switch course this is you.
One two three four.
And because it's zero it means finished output and then this tool for store is a source destination
like this shell that's been covered.
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
for this because you can dial F P on a longer school.
And this one too.
It's an 8 bit farther we want to move so we can just move the stage but 12
that into our shoe and what we want.
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
you.
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
up resistor here for remember this it resists that not a register is a normal resistor so restore it
ness and restore by source are zero discrimination.
1 so that's been covered the next step is to call to the pool at which to enable register let's do the
TR 1 because you can go for f a thing always right in the image function takes quite a lot of time for
the video.
So in the next project that we'll be doing they're going to be relatively long project show what we
will be doing is we're wedding type out the the inmates function together I'll just take it out once.
Now you go through and then we continue from there.
That would save us quite a lot of time for these two projects.
It's very good that we do it together.
So they serve and what we need is another age but.
We want to move to our share and what we want to enable.
We want to enable P F we want to enable people for the switch.
We want to enable.
If one who be for the end to do so.
As you can guess except we accept hexadecimal 8 but you the one to look at this and could put the help
I have for you.
What would this be.
This is ISSUE 1 seriously
2 2 1 0.
So that's what this implies and then restore it skull.
Source register answer.
Destination major stop 1.
So now we have to use all we have to access to more Redish this we have to unlock it and then allow
comment.
She could do LTI.
I want cheaply I F
block on the school.
Then and then since we don't need to perform any form of computation or manipulation we just want to
take something from one register and put it into another one.
You can just note this one into another register like this.
And what do we call it.
Recorded it cheaply.
I'll lock both you or something.
Let's see what name you gave it to right here to call you.
Lock key so.
This is a 32 bit value.
That's where we use the LTE.
We cannot use move for this move wouldn't work so we just load below the register in R1 and then load
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
for it and it is still that cheaply.
I will commit register and then do that by this GP I'll put on a school C and then.
And what we want to do is to unlock say some 8 bit value into that value we will use in her father year
school X
and B.
Basically what this means is
it can say.
Then finally restore the source and destination then a initialization is complete.
What we want is to return from the subroutine using the x x and then return.
So this particular video is getting quite too long.
So we're going to end here and continuing the next video with the rest of the on the assembly code.
Good work.
See you.