Hello.
Welcome back.
In this lesson we are going to see how to configure our GPI view as an output pin.
I'm gonna make a copy of the last project and then we continue from the core call this GPL you output
input.
Sorry we're going to see how to configure our key player you pin as an input.
Right.
We've already done output
okay.
They were quick to open
to right arm to configure us on input.
It's really simple.
All we have to do is go to the direction register and set it as an input and then we'll have it as an
input but for our experiment we are going to use their switches provided on the port we have switch
one on switch to a P F for and P FS 0 respectively.
We need to enable the um the pull up stuff for these switches so we need to enable the internal pull
up resist the we need to enable the internal pull up resistor that are connected to these two switches
and to enable them we can use the pin up register to enable the internal pull up resistor.
So we have to get uh we have to create the um the address for that.
So I'm going to come over here and create a new address.
I've already gone ahead to get the M to get the offset of the pull up pull up read uh pull up register.
So I'm gonna create it s also GPO F P R for pool upper register offset the offset is 0 x 5 1 0 and you
can go and such.
You are in your data sheet you find this offsets there so to create the um the resistor you simply build
GPL you f p you are on the score are over here and we know we compute this by QPR you f base plus GPL
you p you are offset that is point number 1 1 r right that's another thing we have to deal with.
So our switch PFC row here which is switch number two it is locked by default and this means that we
have to unlock we have to unlock this pin.
The reason this plan is locked is because it is a B PFC row is connected to what is known as the N in
my then non masked ball.
Interrupt and because the the designers of the Texas Instrument microcontroller don't want us to alter
the state of the the the pin by mistake they've locked it such that if we want to use it we've got to
unlock it with a particular unlock key and then we can use it.
So we've got to unlock this and to do it we need to access what is known as the lock register and then
we write a particular unlock to this ones with unlock this we've got a comet what new set in through
the comet right.
Uh comets register.
And mind you we are only doing this because we are using PSU if we connect a own switch to the M to
the microcontroller board.
We don't we don't need to lock in a pin if it's not locked.
Just p f 0 has this issue or for now in our experiment it just has to do a PSU if I'm to connect a pin
to p EF 5 I wouldn't need to unlock it I'll be good to go but because we're using PSU and internally
is connected to the enemy we need to knock it so I'll create the register for lock in on unlocking over
here do you play your f the registers keep a f or call it LC k 4 Look offset the offset here is 0 x
5 2 0
and then we can create the register self keep your f LC K on this call R E Q You would take down the
GPL you f base and then we add this the offset
right.
So this one at I register once we unlock the key we've got to commit the changes and we commit to using
the committee register.
No no C are for short and we can create that as well.
Oh c GPL you f c r offset it can you.
This is or x 5 to 4 and then GPL you f c r underscore R E Q You Cooper you f space address
plus the C are offset.
Right.
So this is it.
So the key the lock key the key to to unlock code port f I'm gonna create a symbolic name to hold this
hexadecimal value and that this can be found in the data sheet as well call this lock key.
This is this value here.
Right.
So I think the set
let's create some symbolic names to correspond to the um the bits of our switch one is switch switch
two.
I'm gonna come over here come down here and say stop you one for switch one
switch one we know is that ping for and then switch two we know this is hard to pin zero
right
um we can create more symbolic names um remember oh uh oh a switch is an octave low switch in and by
default the switch is high when we press the switch it goes slow meaning if we detect that if we wrote
the switch and it state shows that it is low it means someone is pressing it has it is caught on octaves
octave low switch right.
So um I'm going to put a block of comment here
with this output
um let's stop you one pressed
wait let's see how do I write this.
Okay so the output is gonna come out in the um in register.
Iris 0 0 x 0 1.
This will mean
a switch 1
so each one is pressed
sorry bother.
Okay.
If our sorrow which has the output is 0 x
1 0.
This will mean switch to
pressed
if our shoe which is going to be our output register has
0 x 0 0.
This will mean both switches
are pressed if our 0 0 0 x 1 1.
This will mean
no switch is pressed.
Remember we said it's active low
right.
So this is a comment so I'm going to highlight this and comments for your explanation.
Okay I'm gonna create symbolic names to hold these state.
So come over here I'll s top you one on the score prized and there's a Q You 0 x 0 1 and then I stop
you too on a score pressed this AQ you score x 1 0.
This both pressed AQ you sure x.
Sure sure this no press
AQ you sure x 1 1 right.
So now we have all the registers and symbolic names we need.
Yeah.
So how about we continue in the next lesson this implement our code in the next lesson.
I'll see you there.