Hello.
Welcome back.
In this lesson we should take a look at another digital input output example.
This lesson also teach us how to unlock sets in locked panes.
So some of the pins on a wire microcontroller because they are used for other functions by default they
are locked in order to use them.
We need to unlock them.
This lesson is going to show us how to perform such on lock in so I'm going to create a new project
over here.
Create this new vision project or save Main.
We have projects.
Come over here.
Great new photo for it.
I call this GPI you unlock it
and then we didn't fold our creative forward GPO a unlock in and then team 4C.
One two three.
U h 6 p.m..
Select the board.
Okay.
Over here.
She says isolate the core device isolate the startup over here like this.
Okay.
And Target over here.
I'm going to see a Tim 4C One two three and I'm going to expand their source group or select Oh.
Change the name to AP and GONNA COME TO TARGET OPTIONS set the X all to 16 over here and debug outcrop
down in select SD link select still areas I CDI yeah And over here I'll take this.
And then.
Okay.
And then.
Okay come over here right click each new item.
See and then I'll give it a name.
Main here like this.
Right.
And I'm going to bring our pin out.
Going copy and paste our pin up here so that we know which pins we are dealing with right to proceed
by including my microcontroller header followed by right clicking include this over here like this.
So in this example we're going to use the switch too which is connected to PFC row and we'll use this
switch too because p of zero is locked.
By default it's connected to something known as the enemy.
And because of this by default it is locked.
If we want to configure it we've got to tell the microcontroller we've got to sort of take extra steps
in order to use PFO 0 right and unjust and enabling the pin to because of that would practice with P.F.
0 in this course.
In this lesson.
So come over here.
Create the main enemy over here
and open and close and we're going to initialize clock access to port F so RC GC GPA will register pass
you X
to zero over here like this.
Once that is done so to unlock the pin we've got to access the Dethklok register as a block register
we've got to access the clock register and write a particular proc code to it to there's a particular
32 bit value we need to write this register in order for you to unlock and the value we need to write
this time is this one here we need to write 0 x for C for F for 3 and 4 b in order to unlock PSU.
So I'm going to come over here and I'm going to access GPI or port F and then the lock register and
then I'm going to write this file due to the lock register
core this
unlock value like this
right.
I'm going to write this so once we've written this value to the unlock once we've written this to the
lock register we have to take another step we have to access to see our register and enable the um the
bids for PSU before we can configure it so to do that I'm going to come over here and see GPI.
F
and then see R and then I'm going to set the pin 0 the bits corresponding to 0 high and I'm going to
do that by simply writing your ex 0 1 and you know if I expand this this corresponds to bit zero off
the of this nimble being set high.
Once that is done I'll put some committee actually
and over here we've seen
on lock commits register so this the commits register we first need to unlock the comet's register before
we're able to tell the comet's registered to make PFC real configurable.
Once that is done we can proceed with a normal sequence by accessing the direction register.
I'll say keep you f over here.
Ah.
And then I'll say 0 x says you X over here and your x 0 8.
We still work in your X A2 actually because we're dealing with the green entity which is this one here
P F three the green and the DP F 3 0 8 like this.
Right.
And we can expand this to C we set in 0 8 as outputs so as your aids gives us binary one two three four
and one one two three.
Right.
So this corresponds to P.F. 3 we set an output once that is done.
We accessed the enable registered GPI or f the end and we set both our switch and both our switch and
our P F three which is the elder pin as these two pins.
So they switch is connected to peer four over here.
Four bit four so bit voice zero one two three four.
So by here to get here for we simply do 0 x 1 0 and this one here corresponds to 4.
So we change this to 8 over here.
So we're dealing with PFC you over here right.
So we want to set SPF 0 1 to enable PSU.
So we simply need to change this bit here to 1 2 what we have to do in hexadecimal is we've got to do
0 0 0 4 zeros and then 1 0 0 1.
Right.
So we've got to have this in hexadecimal form so we can simply pass the number nine here.
This corresponds to 0 x 0 9 so x 0 9 here would set both our sets.
Both our PSU and P F three US digital teams.
That's what we're doing here.
I'll put a comment here.
Right.
We've got to enable the pull up register come over here and see GPA you f and then P U R pull up is
connected to our bits 0 of port F so I say is your x.
Sure wonder why here to enable it.
And once that is done we can come over here and do what we did before we can say while 1 and we have
to read the State of the GPL FDA to register and perform a bit twice and with which pin 0 and c to come
over here and see if GPL u f data register and 0 x 0 1.
If this is false because this is also an active Lupin.
If this is false it means that the button has been pressed right.
If this forced then what we want to do is
turn on our ability and we do that by seeing GP I o f the LSD is connected to P F 3 which is your x
8 a data register true 2 x 8.
Want to set this high.
If this not if this is not a case we can point out before getting it brackets here actually
if this is not a case we can put an LS condition here.
Else we open close and in here we see a GP.
F
data and then we use the amber sunshine and to add a sign here to just disable this bit like this.
So once this is done we can build and see what it looks like.
Click over here to build.
Now let's download onto our board.
Quint Click here to download onto the board and it's downloaded.
Now let's see what we have.
Click over here and I say press the switch.
No one would say press I say.
And I say and I say press switch to here which is connected to PFC row.
We can see the LCD on.
You can see the LCD tan on how about we comment out a code.
These new lines we added the unlock lines.
Let's see what happens if we fail to unlock the PFC row.
So I reveal this and I don't go down to the board.
So these green LCD is on because P FS you over here PFC over here and it's locked.
St..
Reed zero when we read PFC row.
It's locked.
We get a values you.
Once we unlock it then it is associated to the switch the S.W. W2 here and DSW too is an octave low
as W2.
So once we unlock it it states becomes high with without we pressing it.
When we press it it goes slow but when it's locked it is zero.
Once it's unlocked it becomes an active low switch and by active low it means its default state is high.
When we press.
And then of course load to going to comments this.
So now we unlock the pin click over here to build click here to download onto the board and I can see
it's unlocked now and the ladies off because it's octave low because this condition is was met.
Now.
Right.
I'm going to press it and I can see it comes on I say.
Press So this order is for this lesson.
If you have any questions at all just let me know and I shall see you in the next lesson.
Have a good day.